Skip to content

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

Allow switching channel with the same currency. (#15002)

Piotr Zabieglik24f5b35c83f3
diff --git a/saleor/graphql/discount/mutations/promotion/promotion_rule_update.py b/saleor/graphql/discount/mutations/promotion/promotion_rule_update.py
index 88e96f9461..0253011a90 100644
--- a/saleor/graphql/discount/mutations/promotion/promotion_rule_update.py
+++ b/saleor/graphql/discount/mutations/promotion/promotion_rule_update.py
@@ -121,14 +121,14 @@ class PromotionRuleUpdate(ModelMutation):
channel_currencies = set(
instance.channels.values_list("currency_code", flat=True)
)
- if add_channels := cleaned_input.get("add_channels"):
- channel_currencies.update(
- [channel.currency_code for channel in add_channels]
- )
if remove_channels := cleaned_input.get("remove_channels"):
channel_currencies = channel_currencies - {
channel.currency_code for channel in remove_channels
}
+ if add_channels := cleaned_input.get("add_channels"):
+ channel_currencies.update(
+ [channel.currency_code for channel in add_channels]
+ )
if "reward_value" in cleaned_input or "reward_value_type" in cleaned_input:
reward_value = cleaned_input.get("reward_value") or instance.reward_value
diff --git a/saleor/graphql/discount/tests/mutations/test_promotion_rule_update.py b/saleor/graphql/discount/tests/mutations/test_promotion_rule_update.py
index 830d1074af..9730187877 100644
--- a/saleor/graphql/discount/tests/mutations/test_promotion_rule_update.py
+++ b/saleor/graphql/discount/tests/mutations/test_promotion_rule_update.py
@@ -444,6 +444,45 @@ def test_promotion_rule_update_remove_last_channel_from_fixed_discount(
assert errors[0]["field"] == "removeChannels"
+def test_promotion_rule_update_remove_and_add_channel_with_the_same_currency(
+ app_api_client,
+ permission_manage_discounts,
+ channel_USD,
+ other_channel_USD,
+ promotion,
+):
+ # given
+ rule = promotion.rules.get(name="Fixed promotion rule")
+ rule_id = graphene.Node.to_global_id("PromotionRule", rule.id)
+
+ remove_channel_ids = [graphene.Node.to_global_id("Channel", channel_USD.pk)]
+ add_channel_ids = [graphene.Node.to_global_id("Channel", other_channel_USD.pk)]
+ reward_value = Decimal("10")
+
+ variables = {
+ "id": rule_id,
+ "input": {
+ "removeChannels": remove_channel_ids,
+ "addChannels": add_channel_ids,
+ "rewardValue": reward_value,
+ },
+ }
+
+ # when
+ response = app_api_client.post_graphql(
+ PROMOTION_RULE_UPDATE_MUTATION,
+ variables,
+ permissions=(permission_manage_discounts,),
+ )
+
+ # then
+ content = get_graphql_content(response)
+ data = content["data"]["promotionRuleUpdate"]
+ assert data["promotionRule"]
+ assert len(data["promotionRule"]["channels"]) == 1
+ assert data["promotionRule"]["channels"][0]["slug"] == other_channel_USD.slug
+
+
def test_promotion_rule_update_change_reward_value_type_to_fixed_multiple_channels(
app_api_client,
permission_manage_discounts,