Skip to content

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

Copy metadata fields when creating reissue (#7358)

Iga Karbowiake6ec735812ab
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 8008952678..c39e60e479 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -83,6 +83,7 @@ All notable, unreleased changes to this project will be documented in this file.
- `undiscounted_unit_price_gross_amount`
- `undiscounted_total_price_net_amount`
- `undiscounted_total_price_gross_amount`
+- Copy metadata fields when creating reissue - #7358 by @IKarbowiak
### Breaking
- Multichannel MVP: Multicurrency - #6242 by @fowczarek @d-wysocki
diff --git a/saleor/order/actions.py b/saleor/order/actions.py
index 8cfef706cf..134c1f22a0 100644
--- a/saleor/order/actions.py
+++ b/saleor/order/actions.py
@@ -757,6 +757,8 @@ def _populate_replace_order_fields(original_order: "Order"):
replace_order.redirect_url = original_order.redirect_url
replace_order.original = original_order
replace_order.origin = OrderOrigin.REISSUE
+ replace_order.metadata = original_order.metadata
+ replace_order.private_metadata = original_order.private_metadata
if original_order.billing_address:
original_order.billing_address.pk = None
diff --git a/saleor/order/tests/test_order_actions_create_fulfillments_for_returned_products.py b/saleor/order/tests/test_order_actions_create_fulfillments_for_returned_products.py
index a4cb05aeae..3c1b74862e 100644
--- a/saleor/order/tests/test_order_actions_create_fulfillments_for_returned_products.py
+++ b/saleor/order/tests/test_order_actions_create_fulfillments_for_returned_products.py
@@ -259,6 +259,11 @@ def test_create_return_fulfillment_only_order_lines_with_replace_request(
order_lines_data[0].replace = True
order_lines_data[0].quantity = quantity_to_replace
+ # set metadata
+ order_with_lines.metadata = {"test_key": "test_val"}
+ order_with_lines.private_metadata = {"priv_test_key": "priv_test_val"}
+ order_with_lines.save(update_fields=["metadata", "private_metadata"])
+
response = create_fulfillments_for_returned_products(
requester=staff_user,
order=order_with_lines,
@@ -320,6 +325,8 @@ def test_create_return_fulfillment_only_order_lines_with_replace_request(
assert replace_order.billing_address == order_with_lines.billing_address
assert replace_order.original == order_with_lines
assert replace_order.origin == OrderOrigin.REISSUE
+ assert replace_order.metadata == order_with_lines.metadata
+ assert replace_order.private_metadata == order_with_lines.private_metadata
expected_replaced_line = order_lines_to_return[0]