Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Update a canCancel method
Maciej Korycinskibeeb3f9cadb7
diff --git a/saleor/graphql/order/tests/test_order.py b/saleor/graphql/order/tests/test_order.pyindex b807280d44..5644753b14 100644--- a/saleor/graphql/order/tests/test_order.py+++ b/saleor/graphql/order/tests/test_order.py@@ -16,7 +16,7 @@ from ....account.models import CustomerEventfrom ....core.prices import quantize_pricefrom ....core.taxes import TaxError, zero_taxed_moneyfrom ....discount.models import OrderDiscount-from ....order import OrderStatus+from ....order import FulfillmentStatus, OrderStatusfrom ....order import events as order_eventsfrom ....order.error_codes import OrderErrorCodefrom ....order.events import order_replacement_created@@ -3583,8 +3583,20 @@ def test_clean_order_capture():assert e.value.error_dict["payment"][0].message == msg-def test_clean_order_cancel(fulfilled_order_with_all_cancelled_fulfillments):- order = fulfilled_order_with_all_cancelled_fulfillments+ "status",+ [+ FulfillmentStatus.RETURNED,+ FulfillmentStatus.REFUNDED_AND_RETURNED,+ FulfillmentStatus.REFUNDED,+ FulfillmentStatus.CANCELED,+ FulfillmentStatus.REPLACED,+ ],+)+def test_clean_order_cancel(status, fulfillment):+ order = fulfillment.order+ fulfillment.status = status+ fulfillment.save()# Shouldn't raise any errorsassert clean_order_cancel(order) is Nonediff --git a/saleor/order/models.py b/saleor/order/models.pyindex 6aec0ef2c4..033b1198b0 100644--- a/saleor/order/models.py+++ b/saleor/order/models.py@@ -312,8 +312,17 @@ class Order(ModelWithMetadata):return self.status in statusesdef can_cancel(self):+ statuses_allowed_to_cancel = [+ FulfillmentStatus.CANCELED,+ FulfillmentStatus.REFUNDED,+ FulfillmentStatus.REPLACED,+ FulfillmentStatus.REFUNDED_AND_RETURNED,+ FulfillmentStatus.RETURNED,+ ]return (- not self.fulfillments.exclude(status=FulfillmentStatus.CANCELED).exists()+ not self.fulfillments.exclude(+ status__in=statuses_allowed_to_cancel+ ).exists()) and self.status not in {OrderStatus.CANCELED, OrderStatus.DRAFT}def can_capture(self, payment=None):