Browse Source

Merge pull request #4315 from django-oscar/fix-line-allocations

[Fix] Set num_allocated to quantity if None
master
Voxin Muyli 1 year ago
parent
commit
c818efbe5b
No account linked to committer's email address

+ 1
- 0
sandbox/fixtures/orders.json View File

59
         "unit_price_incl_tax": "7.99",
59
         "unit_price_incl_tax": "7.99",
60
         "partner": 3,
60
         "partner": 3,
61
         "order": 1,
61
         "order": 1,
62
+        "num_allocated": 1,
62
         "quantity": 1
63
         "quantity": 1
63
     },
64
     },
64
     "model": "order.line",
65
     "model": "order.line",

+ 2
- 4
src/oscar/apps/order/abstract_models.py View File

623
     # own business processes.
623
     # own business processes.
624
     status = models.CharField(_("Status"), max_length=255, blank=True)
624
     status = models.CharField(_("Status"), max_length=255, blank=True)
625
 
625
 
626
-    num_allocated = models.PositiveIntegerField(
627
-        _("Number allocated"), blank=True, null=True
628
-    )
626
+    num_allocated = models.PositiveIntegerField(_("Number allocated"))
629
 
627
 
630
     # Checks whether line allocation was cancelled or not
628
     # Checks whether line allocation was cancelled or not
631
     allocation_cancelled = models.BooleanField(default=False)
629
     allocation_cancelled = models.BooleanField(default=False)
888
         if self.allocation_cancelled:
886
         if self.allocation_cancelled:
889
             return False
887
             return False
890
 
888
 
891
-        return quantity <= (self.num_allocated or 0)
889
+        return quantity <= self.num_allocated
892
 
890
 
893
     def consume_allocation(self, quantity):
891
     def consume_allocation(self, quantity):
894
         if not self.can_track_allocations:
892
         if not self.can_track_allocations:

+ 20
- 0
src/oscar/apps/order/migrations/0017_set_num_allocated_to_quantity.py View File

1
+# Generated by Django 4.2.9 on 2024-06-03 8:06
2
+from django.db import migrations
3
+
4
+
5
+def update_line_num_allocated(apps, schema_editor):
6
+    Line = apps.get_model("order", "Line")
7
+    for line in Line.objects.all():
8
+        if line.num_allocated is None:
9
+            line.num_allocated = line.quantity
10
+            line.save(update_fields=["num_allocated"])
11
+
12
+
13
+class Migration(migrations.Migration):
14
+    dependencies = [
15
+        ('order', '0016_line_allocation_cancelled_line_num_allocated'),
16
+    ]
17
+
18
+    operations = [
19
+        migrations.RunPython(update_line_num_allocated, migrations.RunPython.noop),
20
+    ]

+ 18
- 0
src/oscar/apps/order/migrations/0018_alter_line_num_allocated.py View File

1
+# Generated by Django 4.2.11 on 2024-06-14 15:44
2
+
3
+from django.db import migrations, models
4
+
5
+
6
+class Migration(migrations.Migration):
7
+
8
+    dependencies = [
9
+        ("order", "0017_set_num_allocated_to_quantity"),
10
+    ]
11
+
12
+    operations = [
13
+        migrations.AlterField(
14
+            model_name="line",
15
+            name="num_allocated",
16
+            field=models.PositiveIntegerField(verbose_name="Number allocated"),
17
+        ),
18
+    ]

+ 1
- 0
src/oscar/test/factories/order.py View File

106
     partner_sku = factory.LazyAttribute(lambda x: x.product.upc)
106
     partner_sku = factory.LazyAttribute(lambda x: x.product.upc)
107
     stockrecord = factory.LazyAttribute(lambda s: s.product.stockrecords.first())
107
     stockrecord = factory.LazyAttribute(lambda s: s.product.stockrecords.first())
108
     quantity = 1
108
     quantity = 1
109
+    num_allocated = 1
109
 
110
 
110
     line_price_incl_tax = factory.LazyAttribute(
111
     line_price_incl_tax = factory.LazyAttribute(
111
         lambda obj: tax_add(obj.stockrecord.price) * obj.quantity
112
         lambda obj: tax_add(obj.stockrecord.price) * obj.quantity

+ 6
- 9
tests/integration/order/test_models.py View File

193
 
193
 
194
         self.assertTrue(actual)
194
         self.assertTrue(actual)
195
 
195
 
196
-    def test_is_allocation_consumption_possible_when_num_allocated_is_null(self):
197
-        self.line.num_allocated = None
198
-
199
-        actual = self.line.is_allocation_consumption_possible(1)
200
-
201
-        self.assertFalse(actual)
202
-
203
     def event(self, event_type, quantity=None):
196
     def event(self, event_type, quantity=None):
204
         """
197
         """
205
         Creates a shipping event for the test line
198
         Creates a shipping event for the test line
447
     def test_shipping_status(self):
440
     def test_shipping_status(self):
448
         order = OrderFactory()
441
         order = OrderFactory()
449
 
442
 
450
-        line_1 = OrderLineFactory(order=order, partner_sku="SKU1234", quantity=2)
451
-        line_2 = OrderLineFactory(order=order, partner_sku="SKU5678", quantity=1)
443
+        line_1 = OrderLineFactory(
444
+            order=order, partner_sku="SKU1234", quantity=2, num_allocated=2
445
+        )
446
+        line_2 = OrderLineFactory(
447
+            order=order, partner_sku="SKU5678", quantity=1, num_allocated=1
448
+        )
452
         self.assertEqual(order.shipping_status, "")
449
         self.assertEqual(order.shipping_status, "")
453
 
450
 
454
         event_1 = ShippingEventFactory(order=order, event_type__name="Shipped")
451
         event_1 = ShippingEventFactory(order=order, event_type__name="Shipped")

Loading…
Cancel
Save