mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Add a data migration which deletes any stock items which have been scheduled for deletion.
Also deletes any instance of the "delete_old_stock_items" worker task
This commit is contained in:
parent
7ba01612d8
commit
a821717103
47
InvenTree/stock/migrations/0071_auto_20211205_1733.py
Normal file
47
InvenTree/stock/migrations/0071_auto_20211205_1733.py
Normal file
@ -0,0 +1,47 @@
|
||||
# Generated by Django 3.2.5 on 2021-12-05 06:33
|
||||
|
||||
from django.db import migrations
|
||||
|
||||
import logging
|
||||
|
||||
|
||||
logger = logging.getLogger('inventree')
|
||||
|
||||
|
||||
def delete_scheduled(apps, schema_editor):
|
||||
"""
|
||||
Delete all stock items which are marked as 'scheduled_for_deletion'.
|
||||
|
||||
The issue that this field was addressing has now been fixed,
|
||||
and so we can all move on with our lives...
|
||||
"""
|
||||
|
||||
StockItem = apps.get_model('stock', 'stockitem')
|
||||
|
||||
items = StockItem.objects.filter(scheduled_for_deletion=True)
|
||||
|
||||
logger.info(f"Removing {items.count()} stock items scheduled for deletion")
|
||||
|
||||
items.delete()
|
||||
|
||||
Task = apps.get_model('django_q', 'schedule')
|
||||
|
||||
Task.objects.filter(func='stock.tasks.delete_old_stock_items').delete()
|
||||
|
||||
|
||||
def reverse(apps, schema_editor):
|
||||
pass
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('stock', '0070_auto_20211128_0151'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RunPython(
|
||||
delete_scheduled,
|
||||
reverse_code=reverse,
|
||||
)
|
||||
]
|
Loading…
Reference in New Issue
Block a user