diff --git a/InvenTree/order/migrations/0054_salesorderallocation_shipment.py b/InvenTree/order/migrations/0054_salesorderallocation_shipment.py new file mode 100644 index 0000000000..cfb74dd859 --- /dev/null +++ b/InvenTree/order/migrations/0054_salesorderallocation_shipment.py @@ -0,0 +1,19 @@ +# Generated by Django 3.2.5 on 2021-10-25 06:42 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('order', '0053_salesordershipment'), + ] + + operations = [ + migrations.AddField( + model_name='salesorderallocation', + name='shipment', + field=models.ForeignKey(blank=True, help_text='Sales order shipment reference', null=True, on_delete=django.db.models.deletion.CASCADE, to='order.salesordershipment', verbose_name='Shipment'), + ), + ] diff --git a/InvenTree/order/models.py b/InvenTree/order/models.py index be75cf9821..0566ec9312 100644 --- a/InvenTree/order/models.py +++ b/InvenTree/order/models.py @@ -973,6 +973,7 @@ class SalesOrderAllocation(models.Model): Attributes: line: SalesOrderLineItem reference + shipment: SalesOrderShipment reference item: StockItem reference quantity: Quantity to take from the StockItem @@ -1028,6 +1029,11 @@ class SalesOrderAllocation(models.Model): if self.item.serial and not self.quantity == 1: errors['quantity'] = _('Quantity must be 1 for serialized stock item') + + + # TODO: Ensure that the "shipment" points to the same "order"! + + if len(errors) > 0: raise ValidationError(errors) @@ -1037,6 +1043,14 @@ class SalesOrderAllocation(models.Model): verbose_name=_('Line'), related_name='allocations') + shipment = models.ForeignKey( + SalesOrderShipment, + on_delete=models.CASCADE, + null=True, blank=True, + verbose_name=_('Shipment'), + help_text=_('Sales order shipment reference'), + ) + item = models.ForeignKey( 'stock.StockItem', on_delete=models.CASCADE, diff --git a/InvenTree/users/models.py b/InvenTree/users/models.py index d31f2a9905..88052fd40d 100644 --- a/InvenTree/users/models.py +++ b/InvenTree/users/models.py @@ -132,9 +132,10 @@ class RuleSet(models.Model): 'sales_order': [ 'company_company', 'order_salesorder', + 'order_salesorderallocation', 'order_salesorderattachment', 'order_salesorderlineitem', - 'order_salesorderallocation', + 'order_salesordershipment', ] }