From 43c4e936a7726e2212af749254650823eab7df4c Mon Sep 17 00:00:00 2001 From: Oliver Date: Thu, 2 Sep 2021 10:41:23 +1000 Subject: [PATCH 1/2] Fix on_delete for PurchaseOrderLineItem.destination - Currently set to DO_NOTHING - However when deleting a StockLocation which has a PurchaseOrderLineItem.destionation point to it, this will cause an IntegrityError --- InvenTree/order/models.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/InvenTree/order/models.py b/InvenTree/order/models.py index e55f5203ba..ad2105bb44 100644 --- a/InvenTree/order/models.py +++ b/InvenTree/order/models.py @@ -778,7 +778,7 @@ class PurchaseOrderLineItem(OrderLineItem): ) destination = TreeForeignKey( - 'stock.StockLocation', on_delete=models.DO_NOTHING, + 'stock.StockLocation', on_delete=models.SET_NULL, verbose_name=_('Destination'), related_name='po_lines', blank=True, null=True, From 5d703af932772ea430274389c4eaa0be38069167 Mon Sep 17 00:00:00 2001 From: Oliver Date: Thu, 2 Sep 2021 11:11:25 +1000 Subject: [PATCH 2/2] Add migration file --- ...alter_purchaseorderlineitem_destination.py | 21 +++++++++++++++++++ InvenTree/order/models.py | 8 ++++++- 2 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 InvenTree/order/migrations/0050_alter_purchaseorderlineitem_destination.py diff --git a/InvenTree/order/migrations/0050_alter_purchaseorderlineitem_destination.py b/InvenTree/order/migrations/0050_alter_purchaseorderlineitem_destination.py new file mode 100644 index 0000000000..7c0620d053 --- /dev/null +++ b/InvenTree/order/migrations/0050_alter_purchaseorderlineitem_destination.py @@ -0,0 +1,21 @@ +# Generated by Django 3.2.4 on 2021-09-02 00:42 + +from django.db import migrations +import django.db.models.deletion +import mptt.fields + + +class Migration(migrations.Migration): + + dependencies = [ + ('stock', '0065_auto_20210701_0509'), + ('order', '0049_alter_purchaseorderlineitem_unique_together'), + ] + + operations = [ + migrations.AlterField( + model_name='purchaseorderlineitem', + name='destination', + field=mptt.fields.TreeForeignKey(blank=True, help_text='Where does the Purchaser want this item to be stored?', null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='po_lines', to='stock.stocklocation', verbose_name='Destination'), + ), + ] diff --git a/InvenTree/order/models.py b/InvenTree/order/models.py index ad2105bb44..2c2fd7c232 100644 --- a/InvenTree/order/models.py +++ b/InvenTree/order/models.py @@ -767,7 +767,13 @@ class PurchaseOrderLineItem(OrderLineItem): help_text=_("Supplier part"), ) - received = models.DecimalField(decimal_places=5, max_digits=15, default=0, verbose_name=_('Received'), help_text=_('Number of items received')) + received = models.DecimalField( + decimal_places=5, + max_digits=15, + default=0, + verbose_name=_('Received'), + help_text=_('Number of items received') + ) purchase_price = InvenTreeModelMoneyField( max_digits=19,