Skip to content

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

Merge remote-tracking branch 'upstream/master' into display-correctly-for-order-without-payments

Unknown5d532f4d172f
diff --git a/CHANGELOG.md b/CHANGELOG.md
index b05dcdc824..b736330e37 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -16,3 +16,4 @@ All notable, unreleased changes to this project will be documented in this file.
- Add charges taxes on shipping field to shop settings in GraphQL Api - #3603 by @fowczarek
- Make order fields sequence same as dashboard 2.0 - #3606 by @jxltom
- Fix bug where orders can not be filtered by payment status - #3608 by @jxltom
+- Support get correct payment status for order without any payments - #3605 by @jxltom
diff --git a/saleor/graphql/order/types.py b/saleor/graphql/order/types.py
index 3a8b2b59dd..cb89d28dd7 100644
--- a/saleor/graphql/order/types.py
+++ b/saleor/graphql/order/types.py
@@ -269,12 +269,12 @@ class Order(CountableDjangoObjectType):
@staticmethod
@gql_optimizer.resolver_hints(prefetch_related='payments')
def resolve_payment_status(self, info):
- return self.get_last_payment_status()
+ return self.get_payment_status()
@staticmethod
@gql_optimizer.resolver_hints(prefetch_related='payments')
def resolve_payment_status_display(self, info):
- return self.get_last_payment_status_display()
+ return self.get_payment_status_display()
@staticmethod
def resolve_payments(self, info):
diff --git a/saleor/order/models.py b/saleor/order/models.py
index a6c4abd644..3b2a389a1d 100644
--- a/saleor/order/models.py
+++ b/saleor/order/models.py
@@ -188,6 +188,18 @@ class Order(models.Model):
return last_payment.get_charge_status_display()
return None
+ def get_payment_status(self):
+ status = self.get_last_payment_status()
+ if status is None:
+ return ChargeStatus.NOT_CHARGED
+ return status
+
+ def get_payment_status_display(self):
+ status = self.get_last_payment_status_display()
+ if status is None:
+ return dict(ChargeStatus.CHOICES).get(ChargeStatus.NOT_CHARGED)
+ return status
+
def is_pre_authorized(self):
return self.payments.filter(
is_active=True,
diff --git a/tests/api/test_order.py b/tests/api/test_order.py
index 2014183262..3f7390edaa 100644
--- a/tests/api/test_order.py
+++ b/tests/api/test_order.py
@@ -8,12 +8,13 @@ from saleor.graphql.core.enums import ReportingPeriod
from saleor.graphql.order.mutations.orders import (
clean_order_cancel, clean_order_capture, clean_order_mark_as_paid,
clean_refund_payment, clean_void_payment)
-from saleor.graphql.order.enums import OrderEventsEmailsEnum, OrderStatusFilter
+from saleor.graphql.order.enums import (
+ OrderEventsEmailsEnum, OrderStatusFilter)
from saleor.graphql.order.utils import can_finalize_draft_order
from saleor.graphql.payment.types import PaymentChargeStatusEnum
from saleor.order import OrderEvents, OrderEventsEmails, OrderStatus
from saleor.order.models import Order, OrderEvent
-from saleor.payment import CustomPaymentChoices
+from saleor.payment import ChargeStatus, CustomPaymentChoices
from saleor.payment.models import Payment
from saleor.shipping.models import ShippingMethod
from tests.api.utils import get_graphql_content
@@ -115,8 +116,10 @@ def test_order_query(
assert order_data['canFinalize'] is True
assert order_data['status'] == order.status.upper()
assert order_data['statusDisplay'] == order.get_status_display()
- assert order_data['paymentStatus'] == order.get_last_payment_status()
- payment_status_display = order.get_last_payment_status_display()
+ payment_status = PaymentChargeStatusEnum.get(
+ order.get_payment_status()).name
+ assert order_data['paymentStatus'] == payment_status
+ payment_status_display = order.get_payment_status_display()
assert order_data['paymentStatusDisplay'] == payment_status_display
assert order_data['isPaid'] == order.is_fully_paid()
assert order_data['userEmail'] == order.user_email
@@ -937,6 +940,7 @@ def test_order_capture(
orderCapture(id: $id, amount: $amount) {
order {
paymentStatus
+ paymentStatusDisplay
isPaid
totalCaptured {
amount
@@ -954,6 +958,9 @@ def test_order_capture(
data = content['data']['orderCapture']['order']
order.refresh_from_db()
assert data['paymentStatus'] == PaymentChargeStatusEnum.CHARGED.name
+ payment_status_display = dict(ChargeStatus.CHOICES).get(
+ ChargeStatus.CHARGED)
+ assert data['paymentStatusDisplay'] == payment_status_display
assert data['isPaid']
assert data['totalCaptured']['amount'] == float(amount)
@@ -1040,6 +1047,7 @@ def test_order_void(
orderVoid(id: $id) {
order {
paymentStatus
+ paymentStatusDisplay
}
}
}
@@ -1051,6 +1059,9 @@ def test_order_void(
content = get_graphql_content(response)
data = content['data']['orderVoid']['order']
assert data['paymentStatus'] == PaymentChargeStatusEnum.NOT_CHARGED.name
+ payment_status_display = dict(ChargeStatus.CHOICES).get(
+ ChargeStatus.NOT_CHARGED)
+ assert data['paymentStatusDisplay'] == payment_status_display
event_payment_voided = order.events.last()
assert event_payment_voided.type == OrderEvents.PAYMENT_VOIDED.value
assert event_payment_voided.user == staff_user
@@ -1065,6 +1076,7 @@ def test_order_refund(
orderRefund(id: $id, amount: $amount) {
order {
paymentStatus
+ paymentStatusDisplay
isPaid
status
}
@@ -1081,6 +1093,9 @@ def test_order_refund(
order.refresh_from_db()
assert data['status'] == order.status.upper()
assert data['paymentStatus'] == PaymentChargeStatusEnum.FULLY_REFUNDED.name
+ payment_status_display = dict(ChargeStatus.CHOICES).get(
+ ChargeStatus.FULLY_REFUNDED)
+ assert data['paymentStatusDisplay'] == payment_status_display
assert data['isPaid'] == False
order_event = order.events.last()