Improve introspection in migration file

This commit is contained in:
Oliver Walters 2021-05-11 18:23:29 +10:00
parent 725a64c29d
commit ed4da4d338
2 changed files with 17 additions and 11 deletions

View File

@ -54,10 +54,14 @@ def update_history(apps, schema_editor):
tracking_type = StockHistoryCode.BUILD_OUTPUT_COMPLETED tracking_type = StockHistoryCode.BUILD_OUTPUT_COMPLETED
elif 'removed' in title and 'item' in title: 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 # Extract the number of removed items
result = re.search("^removed ([\d\.]+) items$", title) result = re.search("^removed ([\d\.]+) items", title)
if result: if result:
@ -70,9 +74,13 @@ def update_history(apps, schema_editor):
deltas['quantity'] = float(q) deltas['quantity'] = float(q)
except: except:
print(f"WARNING: Error converting removed quantity '{removed}'") print(f"WARNING: Error converting removed quantity '{removed}'")
else:
print(f"Could not decode '{title}'")
elif 'split from existing' in title: elif 'split from existing' in title:
tracking_type = StockHistoryCode.SPLIT_FROM_PARENT tracking_type = StockHistoryCode.SPLIT_FROM_PARENT
deltas['quantity'] = float(q)
elif 'moved to' in title: elif 'moved to' in title:
tracking_type = StockHistoryCode.STOCK_MOVE tracking_type = StockHistoryCode.STOCK_MOVE
@ -93,7 +101,7 @@ def update_history(apps, schema_editor):
tracking_type = StockHistoryCode.STOCK_ADD tracking_type = StockHistoryCode.STOCK_ADD
# Extract the number of added items # Extract the number of added items
result = re.search("^added ([\d\.]+) items$", title) result = re.search("^added ([\d\.]+) items", title)
if result: if result:
@ -107,6 +115,9 @@ def update_history(apps, schema_editor):
except: except:
print(f"WARNING: Error converting added quantity '{added}'") print(f"WARNING: Error converting added quantity '{added}'")
else:
print(f"Could not decode '{title}'")
elif 'assigned to customer' in title: elif 'assigned to customer' in title:
tracking_type = StockHistoryCode.SENT_TO_CUSTOMER tracking_type = StockHistoryCode.SENT_TO_CUSTOMER

View File

@ -641,8 +641,8 @@ class StockItem(MPTTModel):
tracking_info['location_name'] = location.name tracking_info['location_name'] = location.name
if self.customer: if self.customer:
tracking_info['customer'] = customer.id tracking_info['customer'] = self.customer.id
tracking_info['customer_name'] = customer.name tracking_info['customer_name'] = self.customer.name
self.add_tracking_entry( self.add_tracking_entry(
StockHistoryCode.RETURNED_FROM_CUSTOMER, StockHistoryCode.RETURNED_FROM_CUSTOMER,
@ -849,7 +849,7 @@ class StockItem(MPTTModel):
StockHistoryCode.REMOVED_CHILD_ITEM, StockHistoryCode.REMOVED_CHILD_ITEM,
user, user,
deltas={ deltas={
'stockitem': self.pk, 'stockitem': self.pk,
}, },
notes=notes, notes=notes,
url=self.get_absolute_url(), url=self.get_absolute_url(),
@ -1183,11 +1183,6 @@ class StockItem(MPTTModel):
return True 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 self.location = location
tracking_info = {} tracking_info = {}