tests for new methods in #1509

This commit is contained in:
Matthias 2021-04-22 22:16:56 +02:00
parent c14478ed1f
commit 7cb858546e
2 changed files with 44 additions and 1 deletions

View File

@ -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)

View File

@ -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 """