mirror of
https://github.com/inventree/InvenTree.git
synced 2025-04-29 20:16:44 +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
|
# Generated by Django 3.2 on 2021-05-10 23:11
|
||||||
|
|
||||||
|
import re
|
||||||
|
|
||||||
from django.db import migrations
|
from django.db import migrations
|
||||||
|
|
||||||
from InvenTree.status_codes import StockHistoryCode
|
from InvenTree.status_codes import StockHistoryCode
|
||||||
@ -27,17 +29,19 @@ def update_history(apps, schema_editor):
|
|||||||
|
|
||||||
for entry in history:
|
for entry in history:
|
||||||
|
|
||||||
|
deltas = {}
|
||||||
updated = False
|
updated = False
|
||||||
|
|
||||||
q = entry.quantity
|
q = entry.quantity
|
||||||
|
|
||||||
if not q == quantity:
|
if not q == quantity:
|
||||||
|
|
||||||
entry.deltas = {
|
try:
|
||||||
'quantity': float(q),
|
deltas['quantity']: float(q)
|
||||||
}
|
updated = True
|
||||||
|
except:
|
||||||
|
print(f"WARNING: Error converting quantity '{q}'")
|
||||||
|
|
||||||
updated = True
|
|
||||||
|
|
||||||
quantity = q
|
quantity = q
|
||||||
|
|
||||||
@ -51,6 +55,21 @@ def update_history(apps, schema_editor):
|
|||||||
|
|
||||||
elif 'removed' in title and 'item' in title:
|
elif 'removed' in title and 'item' in title:
|
||||||
tracking_type = StockHistoryCode.STOCK_REMOVE
|
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:
|
elif 'split from existing' in title:
|
||||||
tracking_type = StockHistoryCode.SPLIT_FROM_PARENT
|
tracking_type = StockHistoryCode.SPLIT_FROM_PARENT
|
||||||
@ -73,6 +92,21 @@ def update_history(apps, schema_editor):
|
|||||||
elif 'added' in title:
|
elif 'added' in title:
|
||||||
tracking_type = StockHistoryCode.STOCK_ADD
|
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:
|
elif 'assigned to customer' in title:
|
||||||
tracking_type = StockHistoryCode.SENT_TO_CUSTOMER
|
tracking_type = StockHistoryCode.SENT_TO_CUSTOMER
|
||||||
|
|
||||||
@ -93,6 +127,7 @@ def update_history(apps, schema_editor):
|
|||||||
updated = True
|
updated = True
|
||||||
|
|
||||||
if updated:
|
if updated:
|
||||||
|
entry.deltas = deltas
|
||||||
entry.save()
|
entry.save()
|
||||||
update_count += 1
|
update_count += 1
|
||||||
|
|
||||||
|
@ -349,8 +349,6 @@ class StockTrackingSerializer(InvenTreeModelSerializer):
|
|||||||
if user_detail is not True:
|
if user_detail is not True:
|
||||||
self.fields.pop('user_detail')
|
self.fields.pop('user_detail')
|
||||||
|
|
||||||
url = serializers.CharField(source='get_absolute_url', read_only=True)
|
|
||||||
|
|
||||||
label = serializers.CharField(read_only=True)
|
label = serializers.CharField(read_only=True)
|
||||||
|
|
||||||
item_detail = StockItemSerializerBrief(source='item', many=False, read_only=True)
|
item_detail = StockItemSerializerBrief(source='item', many=False, read_only=True)
|
||||||
@ -363,7 +361,6 @@ class StockTrackingSerializer(InvenTreeModelSerializer):
|
|||||||
model = StockItemTracking
|
model = StockItemTracking
|
||||||
fields = [
|
fields = [
|
||||||
'pk',
|
'pk',
|
||||||
'url',
|
|
||||||
'item',
|
'item',
|
||||||
'item_detail',
|
'item_detail',
|
||||||
'date',
|
'date',
|
||||||
@ -376,7 +373,6 @@ class StockTrackingSerializer(InvenTreeModelSerializer):
|
|||||||
'tracking_type',
|
'tracking_type',
|
||||||
'user',
|
'user',
|
||||||
'user_detail',
|
'user_detail',
|
||||||
'system',
|
|
||||||
]
|
]
|
||||||
|
|
||||||
read_only_fields = [
|
read_only_fields = [
|
||||||
@ -384,4 +380,6 @@ class StockTrackingSerializer(InvenTreeModelSerializer):
|
|||||||
'user',
|
'user',
|
||||||
'system',
|
'system',
|
||||||
'quantity',
|
'quantity',
|
||||||
|
'label',
|
||||||
|
'tracking_type',
|
||||||
]
|
]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user