diff --git a/src/backend/InvenTree/order/models.py b/src/backend/InvenTree/order/models.py index 54e9aa422a86..456e70404cba 100644 --- a/src/backend/InvenTree/order/models.py +++ b/src/backend/InvenTree/order/models.py @@ -1098,6 +1098,8 @@ def _action_complete(self, *args, **kwargs): self.status = SalesOrderStatus.COMPLETE.value else: self.status = SalesOrderStatus.SHIPPED.value + + if self.shipment_date is None: self.shipped_by = user self.shipment_date = InvenTree.helpers.current_date() diff --git a/src/backend/InvenTree/order/test_api.py b/src/backend/InvenTree/order/test_api.py index 4d8a78de8a80..7c77e9076a87 100644 --- a/src/backend/InvenTree/order/test_api.py +++ b/src/backend/InvenTree/order/test_api.py @@ -1576,6 +1576,8 @@ def test_sales_order_complete(self): so.refresh_from_db() self.assertEqual(so.status, SalesOrderStatus.SHIPPED.value) + self.assertIsNotNone(so.shipment_date) + self.assertIsNotNone(so.shipped_by) # Now, let's try to "complete" the shipment again # This time it should get marked as "COMPLETE" @@ -1591,9 +1593,14 @@ def test_sales_order_complete(self): # Next, we'll change the setting so that the order status jumps straight to "complete" so.status = SalesOrderStatus.PENDING.value + so.shipment_date = None + so.shipped_by = None so.save() so.refresh_from_db() + self.assertEqual(so.status, SalesOrderStatus.PENDING.value) + self.assertIsNone(so.shipped_by) + self.assertIsNone(so.shipment_date) InvenTreeSetting.set_setting('SALESORDER_SHIP_COMPLETE', True) @@ -1603,6 +1610,9 @@ def test_sales_order_complete(self): so.refresh_from_db() self.assertEqual(so.status, SalesOrderStatus.COMPLETE.value) + self.assertIsNotNone(so.shipment_date) + self.assertIsNotNone(so.shipped_by) + class SalesOrderLineItemTest(OrderTest): """Tests for the SalesOrderLineItem API."""