From fab738cd752ebe7bbe509a9c6b071dc69b6a2d79 Mon Sep 17 00:00:00 2001 From: Oliver Date: Fri, 23 Jun 2023 23:55:52 +1000 Subject: [PATCH] Scheduling api fix (#5093) * Fix query for part scheduling API * Add unit test for scheduling endpoint * Remove length check --- InvenTree/part/api.py | 4 ++-- InvenTree/part/test_api.py | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/InvenTree/part/api.py b/InvenTree/part/api.py index a66308f161..b225fb3c8e 100644 --- a/InvenTree/part/api.py +++ b/InvenTree/part/api.py @@ -597,8 +597,8 @@ class PartScheduling(RetrieveAPI): # Grab all allocations against the specified BomItem allocations = BuildItem.objects.filter( - bom_item=bom_item, - build=build, + build_line__bom_item=bom_item, + build_line__build=build, ) # Total allocated for *this* part diff --git a/InvenTree/part/test_api.py b/InvenTree/part/test_api.py index 5837493f2a..e39b86365d 100644 --- a/InvenTree/part/test_api.py +++ b/InvenTree/part/test_api.py @@ -536,6 +536,7 @@ class PartAPITestBase(InvenTreeAPITestCase): 'part', 'location', 'bom', + 'build', 'company', 'test_templates', 'manufacturer_part', @@ -3056,3 +3057,22 @@ class PartMetadataAPITest(InvenTreeAPITestCase): 'api-bom-item-metadata': BomItem, }.items(): self.metatester(apikey, model) + + +class PartSchedulingTest(PartAPITestBase): + """Unit tests for the 'part scheduling' API endpoint""" + + def test_get_schedule(self): + """Test that the scheduling endpoint returns OK""" + + part_ids = [ + 1, 3, 100, 101, + ] + + for pk in part_ids: + url = reverse('api-part-scheduling', kwargs={'pk': pk}) + data = self.get(url, expected_code=200).data + + for entry in data: + for k in ['date', 'quantity', 'label']: + self.assertIn(k, entry)