Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Status property on order

Anna Siwik8483079c3950
diff --git a/saleor/order/models.py b/saleor/order/models.py
index cf994f7c7a..ec2cf9af35 100644
--- a/saleor/order/models.py
+++ b/saleor/order/models.py
@@ -153,6 +153,15 @@ class Order(models.Model, ItemSet):
def is_shipping_required(self):
return any(group.is_shipping_required() for group in self.groups.all())
+ @property
+ def status(self):
+ statuses = set([group.status for group in self.groups.all()])
+ if statuses == {OrderStatus.CANCELLED}:
+ return OrderStatus.CANCELLED
+ if OrderStatus.NEW in statuses:
+ return OrderStatus.NEW
+ return OrderStatus.SHIPPED
+
@property
def total(self):
if self.total_net is not None:
diff --git a/saleor/search/backends/elasticsearch_dashboard.py b/saleor/search/backends/elasticsearch_dashboard.py
index cf5b0c32c8..b337f284bb 100644
--- a/saleor/search/backends/elasticsearch_dashboard.py
+++ b/saleor/search/backends/elasticsearch_dashboard.py
@@ -23,7 +23,7 @@ def _search_users(phrase):
def _search_orders(phrase):
order_query = MultiMatch(
- fields=['user', 'status', 'discount_name'], query=phrase)
+ fields=['user', 'discount_name'], query=phrase)
return OrderDocument.search().query(order_query).source(False)
diff --git a/saleor/search/backends/test_elasticsearch_dashboard.py b/saleor/search/backends/test_elasticsearch_dashboard.py
index 33c3e14346..8de21aed70 100644
--- a/saleor/search/backends/test_elasticsearch_dashboard.py
+++ b/saleor/search/backends/test_elasticsearch_dashboard.py
@@ -16,7 +16,7 @@ ORDERS_QUERY = {
'_source': False,
'query': {
'multi_match': {
- 'fields': ['user', 'status', 'discount_name'],
+ 'fields': ['user', 'discount_name'],
'query': PHRASE
}
}
diff --git a/saleor/search/documents.py b/saleor/search/documents.py
index 2f07490c96..21caff48c9 100644
--- a/saleor/search/documents.py
+++ b/saleor/search/documents.py
@@ -74,4 +74,4 @@ class OrderDocument(DocType):
class Meta:
model = Order
- fields = ['status', 'user_email', 'discount_name']
+ fields = ['user_email', 'discount_name']