From fcb2bb2a46f0478b1eaec7533f7b64e8eb8b1698 Mon Sep 17 00:00:00 2001 From: Oliver Date: Tue, 21 Dec 2021 01:03:37 +1100 Subject: [PATCH] Fix behaviour on deleting parent stock item --- .../migrations/0073_alter_stockitem_parent.py | 20 +++++++++++++++++++ InvenTree/stock/models.py | 3 ++- InvenTree/templates/js/translated/stock.js | 2 +- 3 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 InvenTree/stock/migrations/0073_alter_stockitem_parent.py diff --git a/InvenTree/stock/migrations/0073_alter_stockitem_parent.py b/InvenTree/stock/migrations/0073_alter_stockitem_parent.py new file mode 100644 index 0000000000..dca8788964 --- /dev/null +++ b/InvenTree/stock/migrations/0073_alter_stockitem_parent.py @@ -0,0 +1,20 @@ +# Generated by Django 3.2.10 on 2021-12-20 13:54 + +from django.db import migrations +import django.db.models.deletion +import mptt.fields + + +class Migration(migrations.Migration): + + dependencies = [ + ('stock', '0072_remove_stockitem_scheduled_for_deletion'), + ] + + operations = [ + migrations.AlterField( + model_name='stockitem', + name='parent', + field=mptt.fields.TreeForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='children', to='stock.stockitem', verbose_name='Parent Stock Item'), + ), + ] diff --git a/InvenTree/stock/models.py b/InvenTree/stock/models.py index 1d287cd307..6a9f12bd77 100644 --- a/InvenTree/stock/models.py +++ b/InvenTree/stock/models.py @@ -458,7 +458,7 @@ class StockItem(MPTTModel): parent = TreeForeignKey( 'self', verbose_name=_('Parent Stock Item'), - on_delete=models.DO_NOTHING, + on_delete=models.SET_NULL, blank=True, null=True, related_name='children' ) @@ -1252,6 +1252,7 @@ class StockItem(MPTTModel): self.add_tracking_entry( StockHistoryCode.MERGED_STOCK_ITEMS, user, + quantity=self.quantity, notes=notes, deltas={ 'location': location.pk, diff --git a/InvenTree/templates/js/translated/stock.js b/InvenTree/templates/js/translated/stock.js index 23db95ccba..77aed29c11 100644 --- a/InvenTree/templates/js/translated/stock.js +++ b/InvenTree/templates/js/translated/stock.js @@ -867,7 +867,7 @@ function mergeStockItems(items, options={}) { } } } - ) + ); } }); }