From ed4da4d3380f5fea7de037a51ef8d778f2de15d4 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Tue, 11 May 2021 18:23:29 +1000 Subject: [PATCH] Improve introspection in migration file --- .../stock/migrations/0061_auto_20210511_0911.py | 17 ++++++++++++++--- InvenTree/stock/models.py | 11 +++-------- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/InvenTree/stock/migrations/0061_auto_20210511_0911.py b/InvenTree/stock/migrations/0061_auto_20210511_0911.py index b3bcb5b88e..2c264aac1d 100644 --- a/InvenTree/stock/migrations/0061_auto_20210511_0911.py +++ b/InvenTree/stock/migrations/0061_auto_20210511_0911.py @@ -54,10 +54,14 @@ def update_history(apps, schema_editor): tracking_type = StockHistoryCode.BUILD_OUTPUT_COMPLETED elif 'removed' in title and 'item' in title: - tracking_type = StockHistoryCode.STOCK_REMOVE + + if entry.notes.lower().startswith('split '): + tracking_type = StockHistoryCode.SPLIT_CHILD_ITEM + else: + tracking_type = StockHistoryCode.STOCK_REMOVE # Extract the number of removed items - result = re.search("^removed ([\d\.]+) items$", title) + result = re.search("^removed ([\d\.]+) items", title) if result: @@ -70,9 +74,13 @@ def update_history(apps, schema_editor): deltas['quantity'] = float(q) except: print(f"WARNING: Error converting removed quantity '{removed}'") + else: + print(f"Could not decode '{title}'") elif 'split from existing' in title: tracking_type = StockHistoryCode.SPLIT_FROM_PARENT + + deltas['quantity'] = float(q) elif 'moved to' in title: tracking_type = StockHistoryCode.STOCK_MOVE @@ -93,7 +101,7 @@ def update_history(apps, schema_editor): tracking_type = StockHistoryCode.STOCK_ADD # Extract the number of added items - result = re.search("^added ([\d\.]+) items$", title) + result = re.search("^added ([\d\.]+) items", title) if result: @@ -107,6 +115,9 @@ def update_history(apps, schema_editor): except: print(f"WARNING: Error converting added quantity '{added}'") + else: + print(f"Could not decode '{title}'") + elif 'assigned to customer' in title: tracking_type = StockHistoryCode.SENT_TO_CUSTOMER diff --git a/InvenTree/stock/models.py b/InvenTree/stock/models.py index 7d55d26f4d..613882ba1a 100644 --- a/InvenTree/stock/models.py +++ b/InvenTree/stock/models.py @@ -641,8 +641,8 @@ class StockItem(MPTTModel): tracking_info['location_name'] = location.name if self.customer: - tracking_info['customer'] = customer.id - tracking_info['customer_name'] = customer.name + tracking_info['customer'] = self.customer.id + tracking_info['customer_name'] = self.customer.name self.add_tracking_entry( StockHistoryCode.RETURNED_FROM_CUSTOMER, @@ -849,7 +849,7 @@ class StockItem(MPTTModel): StockHistoryCode.REMOVED_CHILD_ITEM, user, deltas={ - 'stockitem': self.pk, + 'stockitem': self.pk, }, notes=notes, url=self.get_absolute_url(), @@ -1183,11 +1183,6 @@ class StockItem(MPTTModel): return True - if self.location: - msg = _("Moved to {loc_new} (from {loc_old})").format(loc_new=str(location), loc_old=str(self.location)) - else: - msg = _('Moved to {loc_new}').format(loc_new=str(location)) - self.location = location tracking_info = {}