Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Fix invalid allocation after migration
fowczrekd14ba8e9a9bf
diff --git a/saleor/warehouse/migrations/0007_auto_20200406_0341.py b/saleor/warehouse/migrations/0007_auto_20200406_0341.pyindex e414e51318..74ebbd4ad7 100644--- a/saleor/warehouse/migrations/0007_auto_20200406_0341.py+++ b/saleor/warehouse/migrations/0007_auto_20200406_0341.py@@ -3,6 +3,9 @@import django.db.models.deletionfrom django.db import migrations, models+UNFULFILLED = "unfulfilled"+PARTIALLY_FULFILLED = "partially fulfilled"+def create_allocation(product_variant, warehouse, order_line, quantity_allocated, Allocation@@ -24,6 +27,7 @@ def create_allocations(apps, schema_editor):shipping_zone_pk = shipping_zone.pkfor order_line in OrderLine.objects.filter(order__shipping_method__shipping_zone__pk=shipping_zone_pk,+ order__status__in=[UNFULFILLED, PARTIALLY_FULFILLED],).iterator():quantity_unfulfilled = order_line.quantity - order_line.quantity_fulfilledif quantity_unfulfilled > 0 and order_line.variant:diff --git a/saleor/warehouse/migrations/0009_remove_invalid_allocation.py b/saleor/warehouse/migrations/0009_remove_invalid_allocation.pynew file mode 100644index 0000000000..e8db6a6c8d--- /dev/null+++ b/saleor/warehouse/migrations/0009_remove_invalid_allocation.py@@ -0,0 +1,25 @@+# Generated by Django 3.0.6 on 2020-05-21 07:18++from django.db import migrations++DRAFT = "draft"+CANCELED = "canceled"+++def create_allocations(apps, schema_editor):+ Allocation = apps.get_model("warehouse", "Allocation")+ invalid_allocation = Allocation.objects.filter(+ order_line__order__status__in=[DRAFT, CANCELED]+ )+ invalid_allocation.delete()+++class Migration(migrations.Migration):++ dependencies = [+ ("warehouse", "0008_auto_20200430_0239"),+ ]++ operations = [+ migrations.RunPython(create_allocations),+ ]