mirror of
https://github.com/inventree/InvenTree.git
synced 2025-07-03 04:00:57 +00:00
Create "SalesOrderAllocation" object
- Links multiple StockItem objects to a single SalesOrderLineItem
This commit is contained in:
@ -29,7 +29,7 @@ from InvenTree.models import InvenTreeTree
|
||||
from InvenTree.fields import InvenTreeURLField
|
||||
|
||||
from part.models import Part
|
||||
from order.models import PurchaseOrder, SalesOrderLineItem
|
||||
from order.models import PurchaseOrder, SalesOrder
|
||||
|
||||
|
||||
class StockLocation(InvenTreeTree):
|
||||
@ -127,7 +127,7 @@ class StockItem(MPTTModel):
|
||||
build: Link to a Build (if this stock item was created from a build)
|
||||
purchase_order: Link to a PurchaseOrder (if this stock item was created from a PurchaseOrder)
|
||||
infinite: If True this StockItem can never be exhausted
|
||||
sales_order: Link to a SalesOrderLineItem (if this stockitem has been allocated to a sales order)
|
||||
sales_order: Link to a SalesOrder object (if the StockItem has been assigned to a SalesOrder)
|
||||
"""
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
@ -263,20 +263,6 @@ class StockItem(MPTTModel):
|
||||
# TODO - Find a test than can be perfomed...
|
||||
pass
|
||||
|
||||
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_line is not None:
|
||||
|
||||
if self.sales_order_line.part is 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_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
|
||||
|
||||
if self.belongs_to and self.belongs_to.pk == self.pk:
|
||||
raise ValidationError({
|
||||
'belongs_to': _('Item cannot belong to itself')
|
||||
@ -369,8 +355,8 @@ class StockItem(MPTTModel):
|
||||
help_text=_('Purchase order for this stock item')
|
||||
)
|
||||
|
||||
sales_order_line = models.ForeignKey(
|
||||
SalesOrderLineItem,
|
||||
sales_order = models.ForeignKey(
|
||||
SalesOrder,
|
||||
on_delete=models.SET_NULL,
|
||||
related_name='stock_items',
|
||||
null=True, blank=True)
|
||||
|
Reference in New Issue
Block a user