This commit is contained in:
Oliver Walters 2019-09-13 20:52:25 +10:00
parent 59f102af3c
commit 36ec5e41b0
5 changed files with 40 additions and 4 deletions

View File

@ -15,6 +15,13 @@
supplier: 1
SKU: 'ACME0002'
- model: company.supplierpart
pk: 3
fields:
part: 1
supplier: 1
SKU: 'ACME0003'
# Widget purchaseable from ACME
- model: company.supplierpart
pk: 100
@ -33,7 +40,7 @@
# M2x4 LPHS from Zerg Corp
- model: company.supplierpart
pk: 3
pk: 7
fields:
part: 1
supplier: 3

View File

@ -35,8 +35,16 @@
quantity: 250
received: 50
# 1000 x ACME0003
- model: order.purchaseorderlineitem
fields:
order: 1
part: 3
quantity: 1000
# 100 x ZERGLPHS (M2x4 LPHS)
- model: order.purchaseorderlineitem
pk: 22
fields:
order: 2
part: 3

View File

@ -137,7 +137,7 @@ class POTests(OrderViewTestCase):
# POST with a part that does not match the purchase order
post_data['order'] = 1
post_data['part'] = 3
post_data['part'] = 7
response = self.client.post(url, post_data, HTTP_X_REQUESTED_WITH='XMLHttpRequest')
data = json.loads(response.content)
self.assertFalse(data['form_valid'])
@ -169,3 +169,18 @@ class POTests(OrderViewTestCase):
response = self.client.get(url, HTTP_X_REQUESTED_WITH='XMLHttpRequest')
self.assertEqual(response.status_code, 200)
class TestPOReceive(OrderViewTestCase):
""" Tests for receiving a purchase order """
def setUp(self):
super().setUp()
self.po = PurchaseOrder.objects.get(pk=1)
self.url = reverse('purchase-order-receive', args=(1,))
def test_receive_lines(self):
# TODO
pass

View File

@ -101,7 +101,7 @@ class OrderTest(TestCase):
loc = StockLocation.objects.get(id=1)
# There should be two lines against this order
self.assertEqual(len(order.pending_line_items()), 2)
self.assertEqual(len(order.pending_line_items()), 3)
# Should fail, as order is 'PENDING' not 'PLACED"
self.assertEqual(order.status, OrderStatus.PENDING)
@ -117,7 +117,7 @@ class OrderTest(TestCase):
self.assertEqual(line.remaining(), 50)
self.assertEqual(part.on_order, 350)
self.assertEqual(part.on_order, 1350)
# Try to order some invalid things
with self.assertRaises(django_exceptions.ValidationError):

View File

@ -243,6 +243,11 @@ class PurchaseOrderReceive(AjaxView):
except (PurchaseOrderLineItem.DoesNotExist, ValueError):
continue
# Check that line matches the order
if not line.order == self.order:
# TODO - Display a non-field error?
continue
# Ignore a part that doesn't map to a SupplierPart
try:
if line.part is None:
@ -277,6 +282,7 @@ class PurchaseOrderReceive(AjaxView):
return self.renderJsonResponse(request, data=data)
@transaction.atomic
def receive_parts(self):
""" Called once the form has been validated.
Create new stockitems against received parts.