mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Add function to get the default location for a part
- If field not specified, look at the part category
This commit is contained in:
parent
f270375847
commit
71972f4454
@ -148,6 +148,21 @@ class Part(models.Model):
|
|||||||
help_text='Where is this item normally stored?',
|
help_text='Where is this item normally stored?',
|
||||||
related_name='default_parts')
|
related_name='default_parts')
|
||||||
|
|
||||||
|
def get_default_location(self):
|
||||||
|
""" Get the default location for a Part (may be None).
|
||||||
|
|
||||||
|
If the Part does not specify a default location,
|
||||||
|
look at the Category this part is in.
|
||||||
|
The PartCategory object may also specify a default stock location
|
||||||
|
"""
|
||||||
|
|
||||||
|
if self.default_location:
|
||||||
|
return self.default_location
|
||||||
|
elif self.category:
|
||||||
|
return self.category.default_location
|
||||||
|
|
||||||
|
return None
|
||||||
|
|
||||||
# Default supplier part
|
# Default supplier part
|
||||||
default_supplier = models.ForeignKey('part.SupplierPart',
|
default_supplier = models.ForeignKey('part.SupplierPart',
|
||||||
on_delete=models.SET_NULL,
|
on_delete=models.SET_NULL,
|
||||||
|
@ -211,7 +211,7 @@ class StockItemCreate(AjaxCreateView):
|
|||||||
try:
|
try:
|
||||||
part = Part.objects.get(pk=part_id)
|
part = Part.objects.get(pk=part_id)
|
||||||
initials['part'] = part
|
initials['part'] = part
|
||||||
initials['location'] = part.default_location
|
initials['location'] = part.get_default_location()
|
||||||
initials['supplier_part'] = part.default_supplier
|
initials['supplier_part'] = part.default_supplier
|
||||||
except Part.DoesNotExist:
|
except Part.DoesNotExist:
|
||||||
pass
|
pass
|
||||||
|
Loading…
Reference in New Issue
Block a user