Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Recalculate order prices on marinkg as paid mutations (#10260)
Filip Owczarek4e45b83e7475
diff --git a/saleor/graphql/order/mutations/order_mark_as_paid.py b/saleor/graphql/order/mutations/order_mark_as_paid.pyindex 2afb8a9e7c..4e594c8f60 100644--- a/saleor/graphql/order/mutations/order_mark_as_paid.py+++ b/saleor/graphql/order/mutations/order_mark_as_paid.py@@ -3,6 +3,7 @@ from django.core.exceptions import ValidationErrorfrom ....core.permissions import OrderPermissionsfrom ....order.actions import clean_mark_order_as_paid, mark_order_as_paid+from ....order.calculations import fetch_order_prices_if_expiredfrom ....order.error_codes import OrderErrorCodefrom ....order.search import update_order_search_vectorfrom ...core.mutations import BaseMutation@@ -37,6 +38,8 @@ class OrderMarkAsPaid(BaseMutation):@classmethoddef perform_mutation(cls, _root, info, **data):order = cls.get_node_or_error(info, data.get("id"), only_type=Order)+ manager = info.context.plugins+ order, _ = fetch_order_prices_if_expired(order, manager)transaction_reference = data.get("transaction_reference")cls.clean_billing_address(order)user = info.context.userdiff --git a/saleor/graphql/order/tests/test_order.py b/saleor/graphql/order/tests/test_order.pyindex 83cd61af6f..4eba1e3e20 100644--- a/saleor/graphql/order/tests/test_order.py+++ b/saleor/graphql/order/tests/test_order.py@@ -6560,6 +6560,42 @@ def test_order_mark_as_paid_no_billing_address(assert data[0]["code"] == OrderErrorCode.BILLING_ADDRESS_NOT_SET.name+def test_draft_order_mark_as_paid_check_price_recalculation(+ staff_api_client, permission_manage_orders, order_with_lines, staff_user+):+ # given+ order = order_with_lines+ # we need to change order total and set it as invalidated prices.+ # we couldn't use `order.total.gross` because this test don't use any tax app+ # or plugin.+ expected_total_net = order.total.net+ expected_total = TaxedMoney(net=expected_total_net, gross=expected_total_net)+ order.total = TaxedMoney(net=Money(0, "USD"), gross=Money(0, "USD"))+ order.should_refresh_prices = True+ order.status = OrderStatus.DRAFT+ order.save()+ query = MUTATION_MARK_ORDER_AS_PAID+ order_id = graphene.Node.to_global_id("Order", order.id)+ variables = {"id": order_id}++ # when+ response = staff_api_client.post_graphql(+ query, variables, permissions=[permission_manage_orders]+ )+ content = get_graphql_content(response)++ # then+ data = content["data"]["orderMarkAsPaid"]["order"]+ order.refresh_from_db()+ assert order.total == expected_total+ payment = order.payments.get()+ assert payment.total == expected_total_net.amount+ assert data["isPaid"] is True is order.is_fully_paid()+ event_order_paid = order.events.first()+ assert event_order_paid.type == order_events.OrderEvents.ORDER_MARKED_AS_PAID+ assert event_order_paid.user == staff_user++ORDER_VOID = """mutation voidOrder($id: ID!) {orderVoid(id: $id) {