Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Unify status choices
Artur Smęt005c4c19ed00
diff --git a/saleor/dashboard/order/forms.py b/saleor/dashboard/order/forms.pyindex df9f6381c7..e96a6c2383 100644--- a/saleor/dashboard/order/forms.py+++ b/saleor/dashboard/order/forms.py@@ -11,8 +11,9 @@ from payments.models import PAYMENT_STATUS_CHOICESfrom satchless.item import InsufficientStockfrom ...cart.forms import QuantityField-from ...order.models import DeliveryGroup, Order, OrderedItem, OrderNote+from ...order.models import DeliveryGroup, OrderedItem, OrderNotefrom ...product.models import ProductVariant, Stock+from ...order import Statusclass OrderNoteForm(forms.ModelForm):@@ -182,7 +183,7 @@ class ShipGroupForm(forms.ModelForm):ORDER_STATUS_CHOICES = (('', pgettext_lazy('Order status field value',- 'All')),) + Order.STATUS_CHOICES+ 'All')),) + Status.CHOICESPAYMENT_STATUS_CHOICES = (('', pgettext_lazy('Payment status field value','All')),) + PAYMENT_STATUS_CHOICESdiff --git a/saleor/order/__init__.py b/saleor/order/__init__.pyindex e69de29bb2..980694266a 100644--- a/saleor/order/__init__.py+++ b/saleor/order/__init__.py@@ -0,0 +1,17 @@+from django.utils.translation import pgettext_lazy+++class Status(object):+ NEW = 'new'+ CANCELLED = 'cancelled'+ SHIPPED = 'shipped'+ PAYMENT_PENDING = 'payment-pending'+ FULLY_PAID = 'fully-paid'++ CHOICES = (+ (NEW, pgettext_lazy('order status', 'Processing')),+ (CANCELLED, pgettext_lazy('order status', 'Cancelled')),+ (SHIPPED, pgettext_lazy('order status', 'Shipped')),+ (PAYMENT_PENDING, pgettext_lazy('order status', 'Payment pending')),+ (FULLY_PAID, pgettext_lazy('order status', 'Fully paid')),+ )diff --git a/saleor/order/migrations/0012_auto_20160216_1032.py b/saleor/order/migrations/0012_auto_20160216_1032.pynew file mode 100644index 0000000000..720bc3a32d--- /dev/null+++ b/saleor/order/migrations/0012_auto_20160216_1032.py@@ -0,0 +1,30 @@+# -*- coding: utf-8 -*-+# Generated by Django 1.9.1 on 2016-02-16 16:32+from __future__ import unicode_literals++from django.db import migrations, models+++class Migration(migrations.Migration):++ dependencies = [+ ('order', '0011_auto_20160207_0534'),+ ]++ operations = [+ migrations.AlterField(+ model_name='deliverygroup',+ name='status',+ field=models.CharField(choices=[(b'new', 'Processing'), (b'cancelled', 'Cancelled'), (b'shipped', 'Shipped'), (b'payment-pending', 'Payment pending'), (b'fully-paid', 'Fully paid')], default=b'new', max_length=32, verbose_name='delivery status'),+ ),+ migrations.AlterField(+ model_name='order',+ name='status',+ field=models.CharField(choices=[(b'new', 'Processing'), (b'cancelled', 'Cancelled'), (b'shipped', 'Shipped'), (b'payment-pending', 'Payment pending'), (b'fully-paid', 'Fully paid')], default=b'new', max_length=32, verbose_name='order status'),+ ),+ migrations.AlterField(+ model_name='orderhistoryentry',+ name='status',+ field=models.CharField(choices=[(b'new', 'Processing'), (b'cancelled', 'Cancelled'), (b'shipped', 'Shipped'), (b'payment-pending', 'Payment pending'), (b'fully-paid', 'Fully paid')], max_length=32, verbose_name='order status'),+ ),+ ]diff --git a/saleor/order/models.py b/saleor/order/models.pyindex e7b1720181..19d7995f96 100644--- a/saleor/order/models.py+++ b/saleor/order/models.py@@ -22,21 +22,13 @@ from ..core.utils import build_absolute_urifrom ..discount.models import Voucherfrom ..product.models import Product, Stockfrom ..userprofile.models import Address-+from . import Status@python_2_unicode_compatibleclass Order(models.Model, ItemSet):- STATUS_CHOICES = (- ('new', pgettext_lazy('Order status field value', 'Processing')),- ('cancelled', pgettext_lazy('Order status field value', 'Cancelled')),- ('payment-pending', pgettext_lazy('Order status field value',- 'Waiting for payment')),- ('fully-paid', pgettext_lazy('Order status field value',- 'Fully paid')),- ('shipped', pgettext_lazy('Order status field value', 'Shipped')))status = models.CharField(pgettext_lazy('Order field', 'order status'),- max_length=32, choices=STATUS_CHOICES, default='new')+ max_length=32, choices=Status.CHOICES, default=Status.NEW)created = models.DateTimeField(pgettext_lazy('Order field', 'created'),default=now, editable=False)@@ -168,18 +160,14 @@ class Order(models.Model, ItemSet):self.total_net = priceself.total_tax = Price(price.tax, currency=price.currency)+ def can_cancel(self):+ return self.status not in (Status.CANCELLED, Status.SHIPPED)+class DeliveryGroup(models.Model, ItemSet):- STATUS_CHOICES = (- ('new',- pgettext_lazy('Delivery group status field value', 'Processing')),- ('cancelled', pgettext_lazy('Delivery group status field value',- 'Cancelled')),- ('shipped', pgettext_lazy('Delivery group status field value',- 'Shipped')))status = models.CharField(pgettext_lazy('Delivery group field', 'delivery status'),- max_length=32, default='new', choices=STATUS_CHOICES)+ max_length=32, default=Status.NEW, choices=Status.CHOICES)order = models.ForeignKey(Order, related_name='groups', editable=False)shipping_price = PriceField(pgettext_lazy('Delivery group field', 'shipping price'),@@ -380,7 +368,7 @@ class OrderHistoryEntry(models.Model):order = models.ForeignKey(Order, related_name='history')status = models.CharField(pgettext_lazy('Order field', 'order status'),- max_length=32, choices=Order.STATUS_CHOICES)+ max_length=32, choices=Status.CHOICES)comment = models.CharField(max_length=100, default='', blank=True)user = models.ForeignKey(settings.AUTH_USER_MODEL, blank=True, null=True)