mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Check that supplier and manufacturer parts are created
This commit is contained in:
parent
6fa4e33062
commit
2b13512145
@ -704,31 +704,28 @@ class PartList(generics.ListCreateAPIView):
|
||||
'initial_stock_quantity': [_('Must be a valid quantity')],
|
||||
})
|
||||
|
||||
# If an initial stock quantity is specified...
|
||||
if initial_stock_quantity > 0:
|
||||
initial_stock_location = request.data.get('initial_stock_location', None)
|
||||
|
||||
initial_stock_location = request.data.get('initial_stock_location', None)
|
||||
try:
|
||||
initial_stock_location = StockLocation.objects.get(pk=initial_stock_location)
|
||||
except (ValueError, StockLocation.DoesNotExist):
|
||||
initial_stock_location = None
|
||||
|
||||
try:
|
||||
initial_stock_location = StockLocation.objects.get(pk=initial_stock_location)
|
||||
except (ValueError, StockLocation.DoesNotExist):
|
||||
initial_stock_location = None
|
||||
if initial_stock_location is None:
|
||||
if part.default_location is not None:
|
||||
initial_stock_location = part.default_location
|
||||
else:
|
||||
raise ValidationError({
|
||||
'initial_stock_location': [_('Specify location for initial part stock')],
|
||||
})
|
||||
|
||||
if initial_stock_location is None:
|
||||
if part.default_location is not None:
|
||||
initial_stock_location = part.default_location
|
||||
else:
|
||||
raise ValidationError({
|
||||
'initial_stock_location': [_('Specify location for initial part stock')],
|
||||
})
|
||||
stock_item = StockItem(
|
||||
part=part,
|
||||
quantity=initial_stock_quantity,
|
||||
location=initial_stock_location,
|
||||
)
|
||||
|
||||
stock_item = StockItem(
|
||||
part=part,
|
||||
quantity=initial_stock_quantity,
|
||||
location=initial_stock_location,
|
||||
)
|
||||
|
||||
stock_item.save(user=request.user)
|
||||
stock_item.save(user=request.user)
|
||||
|
||||
# Optionally add manufacturer / supplier data to the part
|
||||
if part.purchaseable and str2bool(request.data.get('add_supplier_info', False)):
|
||||
|
@ -580,6 +580,15 @@ class PartAPITest(InvenTreeAPITestCase):
|
||||
|
||||
self.assertEqual(Part.objects.count(), n + 1)
|
||||
|
||||
pk = response.data['pk']
|
||||
|
||||
new_part = Part.objects.get(pk=pk)
|
||||
|
||||
# Check that there is a new manufacturer part *and* a new supplier part
|
||||
self.assertEqual(new_part.supplier_parts.count(), 1)
|
||||
self.assertEqual(new_part.manufacturer_parts.count(), 1)
|
||||
|
||||
|
||||
class PartDetailTests(InvenTreeAPITestCase):
|
||||
"""
|
||||
Test that we can create / edit / delete Part objects via the API
|
||||
|
Loading…
Reference in New Issue
Block a user