2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-07-02 03:30:54 +00:00

Unit test fixes

This commit is contained in:
Oliver
2021-12-03 18:42:36 +11:00
parent d7c87300c6
commit 88fce1e813
5 changed files with 63 additions and 17 deletions

View File

@ -10,7 +10,7 @@ from company.models import Company
from InvenTree import status_codes as status
from order.models import SalesOrder, SalesOrderLineItem, SalesOrderAllocation
from order.models import SalesOrder, SalesOrderLineItem, SalesOrderAllocation, SalesOrderShipment
from part.models import Part
@ -42,6 +42,12 @@ class SalesOrderTest(TestCase):
customer_reference='ABC 55555'
)
# Create a Shipment against this SalesOrder
self.shipment = SalesOrderShipment.objects.create(
order=self.order,
reference='001',
)
# Create a line item
self.line = SalesOrderLineItem.objects.create(quantity=50, order=self.order, part=self.part)
@ -86,11 +92,13 @@ class SalesOrderTest(TestCase):
# Allocate stock to the order
SalesOrderAllocation.objects.create(
line=self.line,
shipment=self.shipment,
item=StockItem.objects.get(pk=self.Sa.pk),
quantity=25)
SalesOrderAllocation.objects.create(
line=self.line,
shipment=self.shipment,
item=StockItem.objects.get(pk=self.Sb.pk),
quantity=25 if full else 20
)
@ -126,9 +134,9 @@ class SalesOrderTest(TestCase):
# Now try to ship it - should fail
with self.assertRaises(ValidationError):
self.order.ship_order(None)
self.order.complete_order(None)
def test_ship_order(self):
def test_complete_order(self):
# Allocate line items, then ship the order
# Assert some stuff before we run the test
@ -140,7 +148,22 @@ class SalesOrderTest(TestCase):
self.assertEqual(SalesOrderAllocation.objects.count(), 2)
self.order.ship_order(None)
# Attempt to complete the order (but shipments are not completed!)
with self.assertRaises(ValidationError):
self.order.complete_order(None)
self.assertIsNone(self.shipment.shipment_date)
self.assertFalse(self.shipment.is_complete())
# Mark the shipments as complete
self.shipment.complete_shipment(None)
self.assertTrue(self.shipment.is_complete())
# Now, should be OK to ship
self.order.complete_order(None)
self.assertEqual(self.order.status, status.SalesOrderStatus.SHIPPED)
self.assertIsNotNone(self.order.shipment_date)
# There should now be 4 stock items
self.assertEqual(StockItem.objects.count(), 4)
@ -162,12 +185,12 @@ class SalesOrderTest(TestCase):
self.assertEqual(sa.sales_order, None)
self.assertEqual(sb.sales_order, None)
# And no allocations
self.assertEqual(SalesOrderAllocation.objects.count(), 0)
# And the allocations still exist
self.assertEqual(SalesOrderAllocation.objects.count(), 2)
self.assertEqual(self.order.status, status.SalesOrderStatus.SHIPPED)
self.assertTrue(self.order.is_fully_allocated())
self.assertTrue(self.line.is_fully_allocated())
self.assertEqual(self.line.fulfilled_quantity(), 50)
self.assertEqual(self.line.allocated_quantity(), 0)
self.assertEqual(self.line.allocated_quantity(), 50)