mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Extract more information from legacy tracking data
This commit is contained in:
parent
1126e2e110
commit
725a64c29d
@ -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
|
||||
|
||||
|
@ -349,8 +349,6 @@ class StockTrackingSerializer(InvenTreeModelSerializer):
|
||||
if user_detail is not True:
|
||||
self.fields.pop('user_detail')
|
||||
|
||||
url = serializers.CharField(source='get_absolute_url', read_only=True)
|
||||
|
||||
label = serializers.CharField(read_only=True)
|
||||
|
||||
item_detail = StockItemSerializerBrief(source='item', many=False, read_only=True)
|
||||
@ -363,7 +361,6 @@ class StockTrackingSerializer(InvenTreeModelSerializer):
|
||||
model = StockItemTracking
|
||||
fields = [
|
||||
'pk',
|
||||
'url',
|
||||
'item',
|
||||
'item_detail',
|
||||
'date',
|
||||
@ -376,7 +373,6 @@ class StockTrackingSerializer(InvenTreeModelSerializer):
|
||||
'tracking_type',
|
||||
'user',
|
||||
'user_detail',
|
||||
'system',
|
||||
]
|
||||
|
||||
read_only_fields = [
|
||||
@ -384,4 +380,6 @@ class StockTrackingSerializer(InvenTreeModelSerializer):
|
||||
'user',
|
||||
'system',
|
||||
'quantity',
|
||||
'label',
|
||||
'tracking_type',
|
||||
]
|
||||
|
Loading…
Reference in New Issue
Block a user