Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft order should be able to clear its shipping method #3472

Merged
merged 4 commits into from
Dec 17, 2018
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ All notable, unreleased changes to this project will be documented in this file.
- Improve several payment validations - #3418 by @jxltom
- Fix decimal value argument in GraphQL = #3457 by @fowczarek
- Bump `urllib3` and `elasticsearch` to latest versions - #3460 by @maarcingebala
- Draft order should be able to clear its shipping method - #3472 by @fowczarek
2 changes: 1 addition & 1 deletion saleor/graphql/order/mutations/orders.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ def mutate(cls, root, info, id, input):
order = cls.get_node_or_error(info, id, errors, 'id', Order)

if not input['shipping_method']:
if order.is_shipping_required():
if not order.is_draft() and order.is_shipping_required():
cls.add_error(
errors, 'shippingMethod',
'Shipping method is required for this order.')
Expand Down
17 changes: 17 additions & 0 deletions tests/api/test_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -1264,6 +1264,23 @@ def test_order_update_shipping_incorrect_shipping_method(
'Shipping method cannot be used with this order.')


def test_draft_order_clear_shipping_method(
staff_api_client, draft_order, permission_manage_orders):
assert draft_order.shipping_method
query = ORDER_UPDATE_SHIPPING_QUERY
order_id = graphene.Node.to_global_id('Order', draft_order.id)
variables = {'order': order_id, 'shippingMethod': None}
response = staff_api_client.post_graphql(
query, variables, permissions=[permission_manage_orders])
content = get_graphql_content(response)
data = content['data']['orderUpdateShipping']
assert data['order']['id'] == order_id
draft_order.refresh_from_db()
assert draft_order.shipping_method is None
assert draft_order.shipping_price == ZERO_TAXED_MONEY
assert draft_order.shipping_method_name is None


def test_orders_total(
staff_api_client, permission_manage_orders, order_with_lines):
query = """
Expand Down