mirror of
https://github.com/inventree/InvenTree.git
synced 2025-05-02 21:38:48 +00:00
Fix for add_tracking_entry in build.create_output (#8310)
- Also add new end-to-end unit tests
This commit is contained in:
parent
d58d34af25
commit
c9a4e6bf7d
@ -940,7 +940,7 @@ class Build(
|
|||||||
StockHistoryCode.BUILD_OUTPUT_CREATED,
|
StockHistoryCode.BUILD_OUTPUT_CREATED,
|
||||||
user,
|
user,
|
||||||
deltas={
|
deltas={
|
||||||
'quantity': quantity,
|
'quantity': float(quantity),
|
||||||
'buildorder': self.pk,
|
'buildorder': self.pk,
|
||||||
'batch': batch,
|
'batch': batch,
|
||||||
'location': location.pk if location else None
|
'location': location.pk if location else None
|
||||||
|
@ -1269,6 +1269,86 @@ class BuildListTest(BuildAPITest):
|
|||||||
self.assertEqual(len(builds), 20)
|
self.assertEqual(len(builds), 20)
|
||||||
|
|
||||||
|
|
||||||
|
class BuildOutputCreateTest(BuildAPITest):
|
||||||
|
"""Unit test for creating build output via API."""
|
||||||
|
|
||||||
|
def test_create_serialized_output(self):
|
||||||
|
"""Create a serialized build output via the API."""
|
||||||
|
|
||||||
|
build_id = 1
|
||||||
|
|
||||||
|
url = reverse('api-build-output-create', kwargs={'pk': build_id})
|
||||||
|
|
||||||
|
build = Build.objects.get(pk=build_id)
|
||||||
|
part = build.part
|
||||||
|
|
||||||
|
n_outputs = build.output_count
|
||||||
|
n_items = part.stock_items.count()
|
||||||
|
|
||||||
|
# Post with invalid data
|
||||||
|
response = self.post(
|
||||||
|
url,
|
||||||
|
data={
|
||||||
|
'quantity': 10,
|
||||||
|
'serial_numbers': '1-100',
|
||||||
|
},
|
||||||
|
expected_code=400
|
||||||
|
)
|
||||||
|
|
||||||
|
self.assertIn('Group range 1-100 exceeds allowed quantity (10)', str(response.data['serial_numbers']))
|
||||||
|
|
||||||
|
# Build outputs have not increased
|
||||||
|
self.assertEqual(n_outputs, build.output_count)
|
||||||
|
|
||||||
|
# Stock items have not increased
|
||||||
|
self.assertEqual(n_items, part.stock_items.count())
|
||||||
|
|
||||||
|
response = self.post(
|
||||||
|
url,
|
||||||
|
data={
|
||||||
|
'quantity': 5,
|
||||||
|
'serial_numbers': '1,2,3-5',
|
||||||
|
},
|
||||||
|
expected_code=201
|
||||||
|
)
|
||||||
|
|
||||||
|
# Build outputs have incdeased
|
||||||
|
self.assertEqual(n_outputs + 5, build.output_count)
|
||||||
|
|
||||||
|
# Stock items have increased
|
||||||
|
self.assertEqual(n_items + 5, part.stock_items.count())
|
||||||
|
|
||||||
|
# Serial numbers have been created
|
||||||
|
for sn in range(1, 6):
|
||||||
|
self.assertTrue(part.stock_items.filter(serial=sn).exists())
|
||||||
|
|
||||||
|
def test_create_unserialized_output(self):
|
||||||
|
"""Create an unserialized build output via the API."""
|
||||||
|
|
||||||
|
build_id = 1
|
||||||
|
url = reverse('api-build-output-create', kwargs={'pk': build_id})
|
||||||
|
|
||||||
|
build = Build.objects.get(pk=build_id)
|
||||||
|
part = build.part
|
||||||
|
|
||||||
|
n_outputs = build.output_count
|
||||||
|
n_items = part.stock_items.count()
|
||||||
|
|
||||||
|
# Create a single new output
|
||||||
|
self.post(
|
||||||
|
url,
|
||||||
|
data={
|
||||||
|
'quantity': 10,
|
||||||
|
},
|
||||||
|
expected_code=201
|
||||||
|
)
|
||||||
|
|
||||||
|
# Build outputs have increased
|
||||||
|
self.assertEqual(n_outputs + 1, build.output_count)
|
||||||
|
|
||||||
|
# Stock items have increased
|
||||||
|
self.assertEqual(n_items + 1, part.stock_items.count())
|
||||||
|
|
||||||
class BuildOutputScrapTest(BuildAPITest):
|
class BuildOutputScrapTest(BuildAPITest):
|
||||||
"""Unit tests for scrapping build outputs"""
|
"""Unit tests for scrapping build outputs"""
|
||||||
|
|
||||||
|
@ -873,7 +873,7 @@ class PurchaseOrder(TotalPriceMixin, Order):
|
|||||||
deltas=tracking_info,
|
deltas=tracking_info,
|
||||||
location=location,
|
location=location,
|
||||||
purchaseorder=self,
|
purchaseorder=self,
|
||||||
quantity=quantity,
|
quantity=float(quantity),
|
||||||
)
|
)
|
||||||
|
|
||||||
# Update the number of parts received against the particular line item
|
# Update the number of parts received against the particular line item
|
||||||
|
Loading…
x
Reference in New Issue
Block a user