Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Calculate order status
Anna Siwike4340704ed9a
diff --git a/saleor/order/models.py b/saleor/order/models.pyindex 22f10911ae..c4f948d789 100644--- a/saleor/order/models.py+++ b/saleor/order/models.py@@ -4,7 +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 Q+from django.db.models import F, Sum, Qfrom django.urls import reversefrom django.utils.timezone import nowfrom django.utils.translation import pgettext_lazy@@ -24,7 +24,7 @@ from .transitions import (class OrderQuerySet(models.QuerySet):- """Filters orders by status deduced from shipment groups."""+ """Filter orders by status deduced from fulfillment quantities."""def open(self):"""Orders having at least one shipment group with status NEW."""@@ -147,11 +147,9 @@ class Order(models.Model):@propertydef status(self):- """Order status deduced from shipment groups."""- statuses = set([group.status for group in self.groups.all()])- return (- OrderStatus.OPEN if GroupStatus.NEW in statuses- else OrderStatus.CLOSED)+ """Order status deduced from fulfillment lines."""+ is_fulfilled = all(line.is_fulfilled() for line in self.lines.all())+ return OrderStatus.CLOSED if is_fulfilled else OrderStatus.OPEN@propertydef is_open(self):@@ -262,6 +260,10 @@ class OrderLine(models.Model):def get_total(self):return self.unit_price * self.quantity+ def is_fulfilled(self):+ lines = FulfillmentLine.objects.filter(order_line=self)+ return sum([line.quantity for line in lines]) >= self.quantity+class Fulfillment(models.Model):order = models.ForeignKey(