mirror of
https://github.com/inventree/InvenTree.git
synced 2025-07-02 11:40:58 +00:00
Replace "addTrasactionNote" function with "add_tracking_entry"
- Does not add translated strings to the database
This commit is contained in:
28
InvenTree/stock/migrations/0060_auto_20210511_1713.py
Normal file
28
InvenTree/stock/migrations/0060_auto_20210511_1713.py
Normal file
@ -0,0 +1,28 @@
|
||||
# Generated by Django 3.2 on 2021-05-11 07:13
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('stock', '0059_auto_20210404_2016'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='stockitemtracking',
|
||||
name='deltas',
|
||||
field=models.JSONField(blank=True, null=True),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='stockitemtracking',
|
||||
name='tracking_type',
|
||||
field=models.IntegerField(default=0),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='stockitemtracking',
|
||||
name='title',
|
||||
field=models.CharField(blank=True, help_text='Tracking entry title', max_length=250, verbose_name='Title'),
|
||||
),
|
||||
]
|
59
InvenTree/stock/migrations/0061_auto_20210511_0911.py
Normal file
59
InvenTree/stock/migrations/0061_auto_20210511_0911.py
Normal file
@ -0,0 +1,59 @@
|
||||
# Generated by Django 3.2 on 2021-05-10 23:11
|
||||
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
def update_history(apps, schema_editor):
|
||||
"""
|
||||
Update each existing StockItemTracking object,
|
||||
convert the recorded "quantity" to a delta
|
||||
"""
|
||||
|
||||
StockItem = apps.get_model('stock', 'stockitem')
|
||||
StockItemTracking = apps.get_model('stock', 'stockitemtracking')
|
||||
|
||||
update_count = 0
|
||||
|
||||
for item in StockItem.objects.all():
|
||||
|
||||
history = StockItemTracking.objects.filter(item=item).order_by('date')
|
||||
|
||||
if history.count() == 0:
|
||||
continue
|
||||
|
||||
quantity = history[0].quantity
|
||||
|
||||
for entry in history:
|
||||
|
||||
q = entry.quantity
|
||||
|
||||
if not q == quantity:
|
||||
|
||||
entry.deltas = {
|
||||
'quantity': float(q),
|
||||
}
|
||||
|
||||
entry.save()
|
||||
|
||||
update_count += 1
|
||||
|
||||
quantity = q
|
||||
|
||||
print(f"Updated {update_count} StockItemHistory entries")
|
||||
|
||||
|
||||
def reverse_update(apps, schema_editor):
|
||||
"""
|
||||
"""
|
||||
pass
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('stock', '0060_auto_20210511_1713'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RunPython(update_history, reverse_code=reverse_update)
|
||||
]
|
Reference in New Issue
Block a user