Skip to content

Commit

Permalink
Merge pull request #16027 from saleor/SHOPX-136-fix-ValueError-on-che…
Browse files Browse the repository at this point in the history
…ckout-shipping-update-3.15

Disallow to update checkout shipping method with mismatching currency
  • Loading branch information
aniav committed May 24, 2024
2 parents ba925f0 + d191c7c commit ed731db
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,17 @@ def perform_on_external_shipping_method(
checkout_info, lines, shipping_method=delivery_method, collection_point=None
)

if delivery_method and delivery_method.price.currency != checkout.currency:
raise ValidationError(
{
"delivery_method_id": ValidationError(
"Cannot choose shipping method with different currency "
"than the checkout.",
code=CheckoutErrorCode.DELIVERY_METHOD_NOT_APPLICABLE.value,
)
}
)

cls._update_delivery_method(
manager,
checkout_info,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,14 @@
id
}
}
totalPrice {
gross {
amount
}
net {
amount
}
}
}
errors {
field
Expand Down Expand Up @@ -261,6 +269,50 @@ def test_checkout_delivery_method_update_external_shipping(
)


@mock.patch("saleor.plugins.webhook.tasks.send_webhook_request_sync")
def test_checkout_delivery_method_update_external_shipping_invalid_currency(
mock_send_request,
api_client,
checkout_with_item_for_cc,
settings,
shipping_app,
):
# given
settings.PLUGINS = ["saleor.plugins.webhook.plugin.WebhookPlugin"]
checkout = checkout_with_item_for_cc
response_method_id = "abcd"
mock_json_response = [
{
"id": response_method_id,
"name": "Provider - Economy",
"amount": "10",
"currency": "AUD", # checkout currency is USD
"maximum_delivery_days": "7",
}
]
mock_send_request.return_value = mock_json_response
method_id = graphene.Node.to_global_id(
"app", f"{shipping_app.id}:{response_method_id}"
)
query = MUTATION_UPDATE_DELIVERY_METHOD

# when
response = api_client.post_graphql(
query, {"id": to_global_id_or_none(checkout), "deliveryMethodId": method_id}
)

# then
data = get_graphql_content(response)["data"]["checkoutDeliveryMethodUpdate"]
errors = data["errors"]
assert len(errors) == 1
assert errors[0]["field"] == "deliveryMethodId"
assert errors[0]["code"] == CheckoutErrorCode.DELIVERY_METHOD_NOT_APPLICABLE.name
assert (
errors[0]["message"]
== "Cannot choose shipping method with different currency than the checkout."
)


@patch(
"saleor.graphql.checkout.mutations.checkout_shipping_method_update."
"clean_delivery_method"
Expand Down

0 comments on commit ed731db

Please sign in to comment.