From 7cb858546e8aee9ee580033b21a014c8dd5768b4 Mon Sep 17 00:00:00 2001 From: Matthias Date: Thu, 22 Apr 2021 22:16:56 +0200 Subject: [PATCH] tests for new methods in #1509 --- InvenTree/order/fixtures/order.yaml | 9 ++++++++ InvenTree/order/tests.py | 36 ++++++++++++++++++++++++++++- 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/InvenTree/order/fixtures/order.yaml b/InvenTree/order/fixtures/order.yaml index 8943b36061..6b65c20786 100644 --- a/InvenTree/order/fixtures/order.yaml +++ b/InvenTree/order/fixtures/order.yaml @@ -50,6 +50,15 @@ supplier: 3 status: 40 # Cancelled + # for pricebreaks +- model: order.purchaseorder + pk: 7 + fields: + reference: '0007' + description: 'Another PO' + supplier: 2 + status: 10 # Pending + # Add some line items against PO 0001 # 100 x ACME0001 (M2x4 LPHS) diff --git a/InvenTree/order/tests.py b/InvenTree/order/tests.py index ed6a4ebb6a..1779a7f18c 100644 --- a/InvenTree/order/tests.py +++ b/InvenTree/order/tests.py @@ -21,6 +21,7 @@ class OrderTest(TestCase): fixtures = [ 'company', 'supplier_part', + 'price_breaks', 'category', 'part', 'location', @@ -63,7 +64,7 @@ class OrderTest(TestCase): next_ref = PurchaseOrder.getNextOrderNumber() - self.assertEqual(next_ref, '0007') + self.assertEqual(next_ref, '0008') def test_on_order(self): """ There should be 3 separate items on order for the M2x4 LPHS part """ @@ -117,6 +118,39 @@ class OrderTest(TestCase): with self.assertRaises(django_exceptions.ValidationError): order.add_line_item(sku, 99) + def test_pricing(self): + """ Test functions for adding line items to an order including price-breaks """ + + order = PurchaseOrder.objects.get(pk=7) + + self.assertEqual(order.status, PurchaseOrderStatus.PENDING) + self.assertEqual(order.lines.count(), 0) + + sku = SupplierPart.objects.get(SKU='ZERGM312') + part = sku.part + + # Order the part + self.assertEqual(part.on_order, 0) + + # Order 25 with manually set high value + pp = sku.get_price(25) + order.add_line_item(sku, 25, purchase_price=pp) + self.assertEqual(part.on_order, 25) + self.assertEqual(order.lines.count(), 1) + self.assertEqual(order.lines.first().purchase_price.amount, 200) + + # Add a few, now the pricebreak should adjust although wrong price given + order.add_line_item(sku, 10, purchase_price=sku.get_price(25)) + self.assertEqual(part.on_order, 35) + self.assertEqual(order.lines.count(), 1) + self.assertEqual(order.lines.first().purchase_price.amount, 8) + + # Order the same part again (it should be merged) + order.add_line_item(sku, 100, purchase_price=sku.get_price(100)) + self.assertEqual(order.lines.count(), 1) + self.assertEqual(part.on_order, 135) + self.assertEqual(order.lines.first().purchase_price.amount, 1.25) + def test_receive(self): """ Test order receiving functions """