Skip to content

Commit

Permalink
Fix recalculate_order dismissing weight unit (#9527)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomaszszymanski129 committed Apr 20, 2022
1 parent 9f8dd19 commit 9aea317
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
7 changes: 7 additions & 0 deletions saleor/order/tests/test_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,13 @@ def test_order_get_subtotal(order_with_lines):
assert order_with_lines.get_subtotal() == target_subtotal


def test_recalculate_order_keeps_weight_unit(order_with_lines):
initial_weight_unit = order_with_lines.weight.unit
recalculate_order(order_with_lines)
recalculated_weight_unit = order_with_lines.weight.unit
assert initial_weight_unit == recalculated_weight_unit


def test_add_variant_to_order_adds_line_for_new_variant(
order_with_lines, product, product_translation_fr, settings, info, site_settings
):
Expand Down
1 change: 1 addition & 0 deletions saleor/order/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ def recalculate_order_weight(order):
for line in order.lines.all():
if line.variant:
weight += line.variant.get_weight() * line.quantity
weight.unit = order.weight.unit
order.weight = weight
order.save(update_fields=["weight", "updated_at"])

Expand Down
11 changes: 4 additions & 7 deletions saleor/plugins/webhook/shipping.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,18 +54,15 @@ def parse_list_shipping_methods_response(


def _compare_order_payloads(payload: str, cached_payload: str) -> bool:
"""Compare two string of order payloads.
Compare them while ignoring excluded_keys.
"""
EXCLUDED_KEYS = ["weight", "meta"]
"""Compare two strings of order payloads ignoring meta."""
EXCLUDED_KEY = "meta"
try:
order_payload = json.loads(payload)["order"]
cached_order_payload = json.loads(cached_payload)["order"]
except: # noqa
return False
return {k: v for k, v in order_payload.items() if k not in EXCLUDED_KEYS} == {
k: v for k, v in cached_order_payload.items() if k not in EXCLUDED_KEYS
return {k: v for k, v in order_payload.items() if k != EXCLUDED_KEY} == {
k: v for k, v in cached_order_payload.items() if k != EXCLUDED_KEY
}


Expand Down

0 comments on commit 9aea317

Please sign in to comment.