Skip to content

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

Error on adding free shipping voucher to draft order 3.1 (#8253)

Dawid Matuszczyke2a450f17a23
diff --git a/saleor/graphql/order/tests/test_order.py b/saleor/graphql/order/tests/test_order.py
index 37e876170a..e4ef065526 100644
--- a/saleor/graphql/order/tests/test_order.py
+++ b/saleor/graphql/order/tests/test_order.py
@@ -2762,6 +2762,51 @@ def test_draft_order_update_doing_nothing_generates_no_events(
assert not OrderEvent.objects.exists()
+def test_draft_order_update_free_shipping_voucher(
+ staff_api_client, permission_manage_orders, draft_order, voucher_free_shipping
+):
+ order = draft_order
+ assert not order.voucher
+ query = """
+ mutation draftUpdate(
+ $id: ID!
+ $voucher: ID!
+ ) {
+ draftOrderUpdate(
+ id: $id
+ input: {
+ voucher: $voucher
+ }
+ ) {
+ errors {
+ field
+ message
+ code
+ }
+ order {
+ id
+ }
+ }
+ }
+ """
+ voucher = voucher_free_shipping
+ order_id = graphene.Node.to_global_id("Order", order.id)
+ voucher_id = graphene.Node.to_global_id("Voucher", voucher.id)
+ variables = {
+ "id": order_id,
+ "voucher": voucher_id,
+ }
+ response = staff_api_client.post_graphql(
+ query, variables, permissions=[permission_manage_orders]
+ )
+ content = get_graphql_content(response)
+ data = content["data"]["draftOrderUpdate"]
+ assert not data["errors"]
+ assert data["order"]["id"] == variables["id"]
+ order.refresh_from_db()
+ assert order.voucher
+
+
def test_draft_order_delete(staff_api_client, permission_manage_orders, draft_order):
order = draft_order
query = """
diff --git a/saleor/order/tests/test_order.py b/saleor/order/tests/test_order.py
index 33258198a0..8a70ea91c5 100644
--- a/saleor/order/tests/test_order.py
+++ b/saleor/order/tests/test_order.py
@@ -827,7 +827,9 @@ def test_shipping_voucher_order_discount(
)
subtotal = Money(100, "USD")
subtotal = TaxedMoney(net=subtotal, gross=subtotal)
- shipping_total = Money(shipping_cost, "USD")
+ shipping_total = TaxedMoney(
+ gross=Money(shipping_cost, "USD"), net=Money(shipping_cost, "USD")
+ )
order = Mock(
get_subtotal=Mock(return_value=subtotal),
shipping_price=shipping_total,
diff --git a/saleor/order/utils.py b/saleor/order/utils.py
index e2814e0a1a..0dc740f579 100644
--- a/saleor/order/utils.py
+++ b/saleor/order/utils.py
@@ -711,7 +711,7 @@ def get_voucher_discount_for_order(order: Order) -> Money:
return order.voucher.get_discount_amount_for(subtotal.gross, order.channel)
if order.voucher.type == VoucherType.SHIPPING:
return order.voucher.get_discount_amount_for(
- order.shipping_price, order.channel
+ order.shipping_price.gross, order.channel
)
if order.voucher.type == VoucherType.SPECIFIC_PRODUCT:
return get_products_voucher_discount_for_order(order)