Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Generate fulfillment id based on order id
Anna Siwik5dc3760ff30f
diff --git a/saleor/order/migrations/0035_auto_20180220_0739.py b/saleor/order/migrations/0035_auto_20180222_0318.pysimilarity index 84%rename from saleor/order/migrations/0035_auto_20180220_0739.pyrename to saleor/order/migrations/0035_auto_20180222_0318.pyindex 767dda6ab8..2680150e7b 100644--- a/saleor/order/migrations/0035_auto_20180220_0739.py+++ b/saleor/order/migrations/0035_auto_20180222_0318.py@@ -1,4 +1,4 @@-# Generated by Django 2.0.2 on 2018-02-20 13:39+# Generated by Django 2.0.2 on 2018-02-22 09:18from django.db import migrations, modelsimport django.db.models.deletion@@ -19,6 +19,11 @@ class Migration(migrations.Migration):model_name='orderline',name='delivery_group',),+ migrations.AddField(+ model_name='fulfillment',+ name='fulfillment_order',+ field=models.PositiveIntegerField(editable=False, null=True),+ ),migrations.AddField(model_name='order',name='shipping_method_name',diff --git a/saleor/order/models.py b/saleor/order/models.pyindex 0043015a2d..8d9f383fd2 100644--- a/saleor/order/models.py+++ b/saleor/order/models.py@@ -4,6 +4,7 @@ from uuid import uuid4from django.conf import settingsfrom django.core.validators import MaxValueValidator, MinValueValidatorfrom django.db import models+from django.db.models import Maxfrom django.urls import reversefrom django.utils.timezone import nowfrom django.utils.translation import pgettext_lazy@@ -198,6 +199,7 @@ class OrderLine(models.Model):class Fulfillment(models.Model):+ fulfillment_order = models.PositiveIntegerField(editable=False, null=True)order = models.ForeignKey(Order, related_name='fulfillments', editable=False,on_delete=models.CASCADE)@@ -206,7 +208,21 @@ class Fulfillment(models.Model):def __str__(self):return pgettext_lazy(- 'Fulfillment str', 'Fulfillment #%d') % (self.id,)+ 'Fulfillment str', 'Fulfillment #%s') % (self.composed_id,)++ def save(self, *args, **kwargs):+ """"Assign an auto incremented value as a fulfillment order."""+ if not self.pk:+ groups = self.order.fulfillments.all()+ existing_max = groups.aggregate(Max('fulfillment_order'))+ existing_max = existing_max.get('fulfillment_order__max')+ self.fulfillment_order = (+ existing_max + 1 if existing_max is not None else 1)+ return super().save(*args, **kwargs)++ @property+ def composed_id(self):+ return '%s-%s' % (self.order.id, self.fulfillment_order)class FulfillmentLine(models.Model):diff --git a/templates/dashboard/order/detail.html b/templates/dashboard/order/detail.htmlindex c9c7eecfb3..3de454b37c 100644--- a/templates/dashboard/order/detail.html+++ b/templates/dashboard/order/detail.html@@ -407,7 +407,7 @@<div class="card shipment-table"><div class="data-table-header"><h5 class="data-table-title">- {% blocktrans trimmed with fulfillment=fulfillment.id context "Fulfillment table title" %}+ {% blocktrans trimmed with fulfillment=fulfillment.composed_id context "Fulfillment table title" %}Fulfillment #{{ fulfillment }}{% endblocktrans %}</h5>