From 4dc997c4aecbfd6fd7ab5db8944bbbb50c30c2f7 Mon Sep 17 00:00:00 2001 From: Maksim Stojkovic <18454392+maksimstojkovic@users.noreply.github.com> Date: Thu, 19 May 2022 02:06:43 +1000 Subject: [PATCH] Added unit test --- InvenTree/order/test_sales_order.py | 37 +++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/InvenTree/order/test_sales_order.py b/InvenTree/order/test_sales_order.py index d43c94996c..954fecf2fe 100644 --- a/InvenTree/order/test_sales_order.py +++ b/InvenTree/order/test_sales_order.py @@ -10,6 +10,8 @@ from company.models import Company from InvenTree import status_codes as status +from common.models import InvenTreeSetting + from order.models import SalesOrder, SalesOrderLineItem, SalesOrderAllocation, SalesOrderShipment from part.models import Part @@ -200,3 +202,38 @@ class SalesOrderTest(TestCase): self.assertTrue(self.line.is_fully_allocated()) self.assertEqual(self.line.fulfilled_quantity(), 50) self.assertEqual(self.line.allocated_quantity(), 50) + + def test_default_shipment(self): + # Test sales order default shipment creation + + # Default setting value should be False + self.assertEqual(False, InvenTreeSetting.get_setting('SALESORDER_DEFAULT_SHIPMENT')) + + # Create an order + order_1 = SalesOrder.objects.create( + customer=self.customer, + reference='1235', + customer_reference='ABC 55556' + ) + + # Order should have no shipments when setting is False + self.assertEqual(0, order_1.shipment_count) + + # Update setting to True + InvenTreeSetting.set_setting('SALESORDER_DEFAULT_SHIPMENT', True, None) + self.assertEqual(True, InvenTreeSetting.get_setting('SALESORDER_DEFAULT_SHIPMENT')) + + # Create a second order + order_2 = SalesOrder.objects.create( + customer=self.customer, + reference='1236', + customer_reference='ABC 55557' + ) + + # Order should have one shipment + self.assertEqual(1, order_2.shipment_count) + self.assertEqual(1, order_2.pending_shipments().count()) + + # Shipment should have default reference of '1' + self.assertEqual('1', order_2.pending_shipments()[0].reference) + \ No newline at end of file