2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-07-03 04:00:57 +00:00

Ability to filter StockItemList API by sales_order or sales_order_line

This commit is contained in:
Oliver Walters
2020-04-21 17:33:02 +10:00
parent 0d1919f10b
commit 2c6e8da90e
3 changed files with 41 additions and 9 deletions

View File

@ -266,13 +266,13 @@ class StockItem(MPTTModel):
try:
# If this StockItem is assigned to a SalesOrderLineItem,
# the "Part" that the line item references is the same as the part that THIS references
if self.sales_order is not None:
if self.sales_order_line is not None:
if self.sales_order.part == None:
raise ValidationError({'sales_order': _('Stock item cannot be assigned to a LineItem which does not reference a part')})
if self.sales_order_line.part == None:
raise ValidationError({'sales_order_line': _('Stock item cannot be assigned to a LineItem which does not reference a part')})
if not self.sales_order.part == self.part:
raise ValidationError({'sales_order': _('Stock item does not reference the same part object as the LineItem')})
if not self.sales_order_line.part == self.part:
raise ValidationError({'sales_order_line': _('Stock item does not reference the same part object as the LineItem')})
except SalesOrderLineItem.DoesNotExist:
pass
@ -369,7 +369,7 @@ class StockItem(MPTTModel):
help_text=_('Purchase order for this stock item')
)
sales_order = models.ForeignKey(
sales_order_line = models.ForeignKey(
SalesOrderLineItem,
on_delete=models.SET_NULL,
related_name='stock_items',