mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Add unit test
This commit is contained in:
parent
6d448d8475
commit
8c78d3b8ea
@ -418,9 +418,9 @@ class PurchaseOrder(Order):
|
|||||||
barcode = ''
|
barcode = ''
|
||||||
|
|
||||||
if not self.status == PurchaseOrderStatus.PLACED:
|
if not self.status == PurchaseOrderStatus.PLACED:
|
||||||
raise ValidationError({
|
raise ValidationError(
|
||||||
"status": _("Lines can only be received against an order marked as 'Placed'")
|
"Lines can only be received against an order marked as 'PLACED'"
|
||||||
})
|
)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if not (quantity % 1 == 0):
|
if not (quantity % 1 == 0):
|
||||||
|
@ -401,25 +401,45 @@ class PurchaseOrderReceiveTest(OrderTest):
|
|||||||
self.assertEqual(line_1.received, 0)
|
self.assertEqual(line_1.received, 0)
|
||||||
self.assertEqual(line_2.received, 50)
|
self.assertEqual(line_2.received, 50)
|
||||||
|
|
||||||
|
valid_data = {
|
||||||
|
'items': [
|
||||||
|
{
|
||||||
|
'line_item': 1,
|
||||||
|
'quantity': 50,
|
||||||
|
'barcode': 'MY-UNIQUE-BARCODE-123',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'line_item': 2,
|
||||||
|
'quantity': 200,
|
||||||
|
'location': 2, # Explicit location
|
||||||
|
'barcode': 'MY-UNIQUE-BARCODE-456',
|
||||||
|
}
|
||||||
|
],
|
||||||
|
'location': 1, # Default location
|
||||||
|
}
|
||||||
|
|
||||||
|
# Before posting "valid" data, we will mark the purchase order as "pending"
|
||||||
|
# In this case we do expect an error!
|
||||||
|
order = PurchaseOrder.objects.get(pk=1)
|
||||||
|
order.status = PurchaseOrderStatus.PENDING
|
||||||
|
order.save()
|
||||||
|
|
||||||
|
response = self.post(
|
||||||
|
self.url,
|
||||||
|
valid_data,
|
||||||
|
expected_code=400
|
||||||
|
)
|
||||||
|
|
||||||
|
self.assertIn('can only be received against', str(response.data))
|
||||||
|
|
||||||
|
# Now, set the PO back to "PLACED" so the items can be received
|
||||||
|
order.status = PurchaseOrderStatus.PLACED
|
||||||
|
order.save()
|
||||||
|
|
||||||
# Receive two separate line items against this order
|
# Receive two separate line items against this order
|
||||||
self.post(
|
self.post(
|
||||||
self.url,
|
self.url,
|
||||||
{
|
valid_data,
|
||||||
'items': [
|
|
||||||
{
|
|
||||||
'line_item': 1,
|
|
||||||
'quantity': 50,
|
|
||||||
'barcode': 'MY-UNIQUE-BARCODE-123',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
'line_item': 2,
|
|
||||||
'quantity': 200,
|
|
||||||
'location': 2, # Explicit location
|
|
||||||
'barcode': 'MY-UNIQUE-BARCODE-456',
|
|
||||||
}
|
|
||||||
],
|
|
||||||
'location': 1, # Default location
|
|
||||||
},
|
|
||||||
expected_code=201,
|
expected_code=201,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user