mirror of
https://github.com/inventree/InvenTree.git
synced 2025-07-02 11:40:58 +00:00
Extract more information from legacy tracking data
This commit is contained in:
@ -1,5 +1,7 @@
|
||||
# Generated by Django 3.2 on 2021-05-10 23:11
|
||||
|
||||
import re
|
||||
|
||||
from django.db import migrations
|
||||
|
||||
from InvenTree.status_codes import StockHistoryCode
|
||||
@ -27,17 +29,19 @@ def update_history(apps, schema_editor):
|
||||
|
||||
for entry in history:
|
||||
|
||||
deltas = {}
|
||||
updated = False
|
||||
|
||||
q = entry.quantity
|
||||
|
||||
if not q == quantity:
|
||||
|
||||
entry.deltas = {
|
||||
'quantity': float(q),
|
||||
}
|
||||
try:
|
||||
deltas['quantity']: float(q)
|
||||
updated = True
|
||||
except:
|
||||
print(f"WARNING: Error converting quantity '{q}'")
|
||||
|
||||
updated = True
|
||||
|
||||
quantity = q
|
||||
|
||||
@ -51,6 +55,21 @@ def update_history(apps, schema_editor):
|
||||
|
||||
elif 'removed' in title and 'item' in title:
|
||||
tracking_type = StockHistoryCode.STOCK_REMOVE
|
||||
|
||||
# Extract the number of removed items
|
||||
result = re.search("^removed ([\d\.]+) items$", title)
|
||||
|
||||
if result:
|
||||
|
||||
removed = result.groups()[0]
|
||||
|
||||
try:
|
||||
deltas['removed'] = float(removed)
|
||||
|
||||
# Ensure that 'quantity' is stored too in this case
|
||||
deltas['quantity'] = float(q)
|
||||
except:
|
||||
print(f"WARNING: Error converting removed quantity '{removed}'")
|
||||
|
||||
elif 'split from existing' in title:
|
||||
tracking_type = StockHistoryCode.SPLIT_FROM_PARENT
|
||||
@ -73,6 +92,21 @@ def update_history(apps, schema_editor):
|
||||
elif 'added' in title:
|
||||
tracking_type = StockHistoryCode.STOCK_ADD
|
||||
|
||||
# Extract the number of added items
|
||||
result = re.search("^added ([\d\.]+) items$", title)
|
||||
|
||||
if result:
|
||||
|
||||
added = result.groups()[0]
|
||||
|
||||
try:
|
||||
deltas['added'] = float(added)
|
||||
|
||||
# Ensure that 'quantity' is stored too in this case
|
||||
deltas['quantity'] = float(q)
|
||||
except:
|
||||
print(f"WARNING: Error converting added quantity '{added}'")
|
||||
|
||||
elif 'assigned to customer' in title:
|
||||
tracking_type = StockHistoryCode.SENT_TO_CUSTOMER
|
||||
|
||||
@ -93,6 +127,7 @@ def update_history(apps, schema_editor):
|
||||
updated = True
|
||||
|
||||
if updated:
|
||||
entry.deltas = deltas
|
||||
entry.save()
|
||||
update_count += 1
|
||||
|
||||
|
Reference in New Issue
Block a user