mirror of
https://github.com/inventree/InvenTree.git
synced 2025-09-18 08:31:33 +00:00
Adds option for duplicating an existing purchase order (#3567)
* Adds option for duplicating an existing purchase order - Copy line items across * Update API version * JS linting * Adds option for duplication of extra lines * Decimal point rounding fix * Unit tests for PO duplication via the API
This commit is contained in:
@@ -225,6 +225,64 @@ class PurchaseOrderTest(OrderTest):
|
||||
expected_code=201
|
||||
)
|
||||
|
||||
def test_po_duplicate(self):
|
||||
"""Test that we can duplicate a PurchaseOrder via the API"""
|
||||
|
||||
self.assignRole('purchase_order.add')
|
||||
|
||||
po = models.PurchaseOrder.objects.get(pk=1)
|
||||
|
||||
self.assertTrue(po.lines.count() > 0)
|
||||
|
||||
# Add some extra line items to this order
|
||||
for idx in range(5):
|
||||
models.PurchaseOrderExtraLine.objects.create(
|
||||
order=po,
|
||||
quantity=idx + 10,
|
||||
reference='some reference',
|
||||
)
|
||||
|
||||
data = self.get(reverse('api-po-detail', kwargs={'pk': 1})).data
|
||||
|
||||
del data['pk']
|
||||
del data['reference']
|
||||
|
||||
data['duplicate_order'] = 1
|
||||
data['duplicate_line_items'] = True
|
||||
data['duplicate_extra_lines'] = False
|
||||
|
||||
data['reference'] = 'PO-9999'
|
||||
|
||||
# Duplicate via the API
|
||||
response = self.post(
|
||||
reverse('api-po-list'),
|
||||
data,
|
||||
expected_code=201
|
||||
)
|
||||
|
||||
# Order is for the same supplier
|
||||
self.assertEqual(response.data['supplier'], po.supplier.pk)
|
||||
|
||||
po_dup = models.PurchaseOrder.objects.get(pk=response.data['pk'])
|
||||
|
||||
self.assertEqual(po_dup.extra_lines.count(), 0)
|
||||
self.assertEqual(po_dup.lines.count(), po.lines.count())
|
||||
|
||||
data['reference'] = 'PO-9998'
|
||||
data['duplicate_line_items'] = False
|
||||
data['duplicate_extra_lines'] = True
|
||||
|
||||
response = self.post(
|
||||
reverse('api-po-list'),
|
||||
data,
|
||||
expected_code=201,
|
||||
)
|
||||
|
||||
po_dup = models.PurchaseOrder.objects.get(pk=response.data['pk'])
|
||||
|
||||
self.assertEqual(po_dup.extra_lines.count(), po.extra_lines.count())
|
||||
self.assertEqual(po_dup.lines.count(), 0)
|
||||
|
||||
def test_po_cancel(self):
|
||||
"""Test the PurchaseOrderCancel API endpoint."""
|
||||
po = models.PurchaseOrder.objects.get(pk=1)
|
||||
|
Reference in New Issue
Block a user