From e103bd8880c56464ea94bcd270f9796b28e8ca3a Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Mon, 6 Jan 2020 20:50:16 +1100 Subject: [PATCH 1/2] Write unit test for PurchaseOrder receive views --- InvenTree/order/test_views.py | 72 ++++++++++++++++++++++++++++++++++- InvenTree/order/views.py | 4 ++ 2 files changed, 74 insertions(+), 2 deletions(-) diff --git a/InvenTree/order/test_views.py b/InvenTree/order/test_views.py index 0bed1f8449..a14e48eae1 100644 --- a/InvenTree/order/test_views.py +++ b/InvenTree/order/test_views.py @@ -181,9 +181,77 @@ class TestPOReceive(OrderViewTestCase): super().setUp() self.po = PurchaseOrder.objects.get(pk=1) + self.po.status = OrderStatus.PLACED + self.po.save() self.url = reverse('purchase-order-receive', args=(1,)) + def post(self, data, validate=None): + + response = self.client.post(self.url, data, HTTP_X_REQUESTED_WITH='XMLHttpRequest') + + if validate is not None: + + data = json.loads(response.content) + + if validate: + self.assertTrue(data['form_valid']) + else: + self.assertFalse(data['form_valid']) + + return response + + def test_get_dialog(self): + + data = { + } + + self.client.get(self.url, data, HTTP_X_REQUESTED_WITH='XMLHttpRequest') + def test_receive_lines(self): - # TODO - pass + post_data = { + } + + response = self.post(post_data, validate=False) + + # Try with an invalid location + post_data['location'] = 12345 + + self.post(post_data, validate=False) + + # Try with a valid location + post_data['location'] = 1 + + # Should fail due to invalid quantity + self.post(post_data, validate=False) + + # Try to receive against an invalid line + post_data['line-800'] = 100 + + # Remove an invalid quantity of items + post_data['line-1'] = '7x5q' + + self.post(post_data, validate=False) + + # Receive negative number + post_data['line-1'] = -100 + + self.post(post_data, validate=False) + + # Receive 75 items + post_data['line-1'] = 75 + + response = self.post(post_data, validate=True) + + line = PurchaseOrderLineItem.objects.get(pk=1) + + self.assertEqual(line.received, 75) + + # Receive 30 more items + post_data['line-1'] = 30 + + self.post(post_data, validate=True) + + line = PurchaseOrderLineItem.objects.get(pk=1) + + self.assertEqual(line.received, 105) diff --git a/InvenTree/order/views.py b/InvenTree/order/views.py index b4cde63e18..7b445fbea3 100644 --- a/InvenTree/order/views.py +++ b/InvenTree/order/views.py @@ -381,6 +381,10 @@ class PurchaseOrderReceive(AjaxUpdateView): line.receive_quantity = receive self.lines.append(line) + if len(self.lines) == 0: + msg = _("No lines specified") + errors = True + # No errors? Receive the submitted parts! if errors is False: self.receive_parts() From a064ce13fc8ec7c264343c5c9fdfabc79515fe03 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Mon, 6 Jan 2020 20:51:12 +1100 Subject: [PATCH 2/2] PEP fixes --- InvenTree/order/test_views.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/InvenTree/order/test_views.py b/InvenTree/order/test_views.py index a14e48eae1..de478cc665 100644 --- a/InvenTree/order/test_views.py +++ b/InvenTree/order/test_views.py @@ -212,7 +212,7 @@ class TestPOReceive(OrderViewTestCase): post_data = { } - response = self.post(post_data, validate=False) + self.post(post_data, validate=False) # Try with an invalid location post_data['location'] = 12345 @@ -241,7 +241,7 @@ class TestPOReceive(OrderViewTestCase): # Receive 75 items post_data['line-1'] = 75 - response = self.post(post_data, validate=True) + self.post(post_data, validate=True) line = PurchaseOrderLineItem.objects.get(pk=1)