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')],
|
'initial_stock_quantity': [_('Must be a valid quantity')],
|
||||||
})
|
})
|
||||||
|
|
||||||
# If an initial stock quantity is specified...
|
initial_stock_location = request.data.get('initial_stock_location', None)
|
||||||
if initial_stock_quantity > 0:
|
|
||||||
|
|
||||||
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:
|
if initial_stock_location is None:
|
||||||
initial_stock_location = StockLocation.objects.get(pk=initial_stock_location)
|
if part.default_location is not None:
|
||||||
except (ValueError, StockLocation.DoesNotExist):
|
initial_stock_location = part.default_location
|
||||||
initial_stock_location = None
|
else:
|
||||||
|
raise ValidationError({
|
||||||
|
'initial_stock_location': [_('Specify location for initial part stock')],
|
||||||
|
})
|
||||||
|
|
||||||
if initial_stock_location is None:
|
stock_item = StockItem(
|
||||||
if part.default_location is not None:
|
part=part,
|
||||||
initial_stock_location = part.default_location
|
quantity=initial_stock_quantity,
|
||||||
else:
|
location=initial_stock_location,
|
||||||
raise ValidationError({
|
)
|
||||||
'initial_stock_location': [_('Specify location for initial part stock')],
|
|
||||||
})
|
|
||||||
|
|
||||||
stock_item = StockItem(
|
stock_item.save(user=request.user)
|
||||||
part=part,
|
|
||||||
quantity=initial_stock_quantity,
|
|
||||||
location=initial_stock_location,
|
|
||||||
)
|
|
||||||
|
|
||||||
stock_item.save(user=request.user)
|
|
||||||
|
|
||||||
# Optionally add manufacturer / supplier data to the part
|
# Optionally add manufacturer / supplier data to the part
|
||||||
if part.purchaseable and str2bool(request.data.get('add_supplier_info', False)):
|
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)
|
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):
|
class PartDetailTests(InvenTreeAPITestCase):
|
||||||
"""
|
"""
|
||||||
Test that we can create / edit / delete Part objects via the API
|
Test that we can create / edit / delete Part objects via the API
|
||||||
|
Loading…
Reference in New Issue
Block a user