Skip to content

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

Update gift card events names (#7980)

Iga Karbowiak4cbec186740c
diff --git a/saleor/giftcard/events.py b/saleor/giftcard/events.py
index 2864e818a9..9f7a46660d 100644
--- a/saleor/giftcard/events.py
+++ b/saleor/giftcard/events.py
@@ -31,7 +31,7 @@ def gift_card_issued_event(
)
-def gift_card_sent(
+def gift_card_sent_event(
gift_card_id: int, user_id: Optional[int], app_id: Optional[int], email: str
):
return GiftCardEvent.objects.create(
@@ -43,25 +43,7 @@ def gift_card_sent(
)
-def gift_cards_sent(
- gift_cards: Iterable[GiftCard], user: UserType, app: AppType, email: str
-):
- if not user_is_valid(user):
- user = None
- gift_cards_events = [
- GiftCardEvent(
- gift_card=gift_card,
- user=user,
- app=app,
- type=GiftCardEvents.SENT_TO_CUSTOMER,
- parameters={"email": email},
- )
- for gift_card in gift_cards
- ]
- return GiftCardEvent.objects.bulk_create(gift_cards_events)
-
-
-def gift_card_resent(
+def gift_card_resent_event(
gift_card_id: int, user_id: Optional[int], app_id: Optional[int], email: str
):
return GiftCardEvent.objects.create(
@@ -73,7 +55,7 @@ def gift_card_resent(
)
-def gift_card_balance_reset(
+def gift_card_balance_reset_event(
gift_card: GiftCard,
old_gift_card: GiftCard,
user: UserType,
@@ -98,7 +80,7 @@ def gift_card_balance_reset(
)
-def gift_card_expiry_date_updated(
+def gift_card_expiry_date_updated_event(
gift_card: GiftCard,
old_gift_card: GiftCard,
user: UserType,
@@ -118,7 +100,7 @@ def gift_card_expiry_date_updated(
)
-def gift_card_activated(
+def gift_card_activated_event(
gift_card: GiftCard,
user: UserType,
app: AppType,
@@ -133,7 +115,7 @@ def gift_card_activated(
)
-def gift_card_deactivated(
+def gift_card_deactivated_event(
gift_card: GiftCard,
user: UserType,
app: AppType,
@@ -148,7 +130,7 @@ def gift_card_deactivated(
)
-def gift_cards_activated(
+def gift_cards_activated_event(
gift_card_ids: Iterable[int],
user: UserType,
app: AppType,
@@ -167,7 +149,7 @@ def gift_cards_activated(
return GiftCardEvent.objects.bulk_create(events)
-def gift_cards_deactivated(
+def gift_cards_deactivated_event(
gift_card_ids: Iterable[int],
user: UserType,
app: AppType,
@@ -186,7 +168,7 @@ def gift_cards_deactivated(
return GiftCardEvent.objects.bulk_create(events)
-def gift_card_note_added(
+def gift_card_note_added_event(
gift_card: GiftCard, user: UserType, app: AppType, message: str
) -> GiftCardEvent:
if not user_is_valid(user):
@@ -200,7 +182,7 @@ def gift_card_note_added(
)
-def gift_cards_used_in_order(
+def gift_cards_used_in_order_event(
balance_data: Iterable[Tuple[GiftCard, float]],
order_id: int,
user: UserType,
@@ -228,7 +210,7 @@ def gift_cards_used_in_order(
return GiftCardEvent.objects.bulk_create(events)
-def gift_cards_bought(
+def gift_cards_bought_event(
gift_cards: Iterable[GiftCard], order_id: int, user: UserType, app: AppType
):
if not user_is_valid(user):
diff --git a/saleor/giftcard/utils.py b/saleor/giftcard/utils.py
index 043d2e830a..7b64c52794 100644
--- a/saleor/giftcard/utils.py
+++ b/saleor/giftcard/utils.py
@@ -196,7 +196,7 @@ def gift_cards_create(
non_shippable_gift_cards.extend(line_gift_cards)
gift_cards = GiftCard.objects.bulk_create(gift_cards)
- events.gift_cards_bought(gift_cards, order.id, requestor_user, app)
+ events.gift_cards_bought_event(gift_cards, order.id, requestor_user, app)
channel_slug = order.channel.slug
# send to customer all non-shippable gift cards
diff --git a/saleor/graphql/giftcard/bulk_mutations.py b/saleor/graphql/giftcard/bulk_mutations.py
index cff3bd1bc1..13b7dfff9b 100644
--- a/saleor/graphql/giftcard/bulk_mutations.py
+++ b/saleor/graphql/giftcard/bulk_mutations.py
@@ -39,7 +39,7 @@ class GiftCardBulkActivate(BaseBulkMutation):
queryset = queryset.filter(is_active=False)
gift_card_ids = [gift_card.id for gift_card in queryset]
queryset.update(is_active=True)
- events.gift_cards_activated(
+ events.gift_cards_activated_event(
gift_card_ids, user=info.context.user, app=info.context.app
)
@@ -64,6 +64,6 @@ class GiftCardBulkDeactivate(BaseBulkMutation):
queryset = queryset.filter(is_active=True)
gift_card_ids = [gift_card.id for gift_card in queryset]
queryset.update(is_active=False)
- events.gift_cards_deactivated(
+ events.gift_cards_deactivated_event(
gift_card_ids, user=info.context.user, app=info.context.app
)
diff --git a/saleor/graphql/giftcard/mutations.py b/saleor/graphql/giftcard/mutations.py
index 5091a5e2cb..c986304328 100644
--- a/saleor/graphql/giftcard/mutations.py
+++ b/saleor/graphql/giftcard/mutations.py
@@ -243,11 +243,11 @@ class GiftCardUpdate(GiftCardCreate):
cls.save(info, instance, cleaned_input)
if "initial_balance_amount" in cleaned_input:
- events.gift_card_balance_reset(
+ events.gift_card_balance_reset_event(
instance, old_instance, info.context.user, info.context.app
)
if "expiry_date" in cleaned_input:
- events.gift_card_expiry_date_updated(
+ events.gift_card_expiry_date_updated_event(
instance, old_instance, info.context.user, info.context.app
)
@@ -288,7 +288,7 @@ class GiftCardDeactivate(BaseMutation):
create_event = gift_card.is_active
deactivate_gift_card(gift_card)
if create_event:
- events.gift_card_deactivated(
+ events.gift_card_deactivated_event(
gift_card=gift_card, user=info.context.user, app=info.context.app
)
return GiftCardDeactivate(gift_card=gift_card)
@@ -316,7 +316,7 @@ class GiftCardActivate(BaseMutation):
create_event = not gift_card.is_active
activate_gift_card(gift_card)
if create_event:
- events.gift_card_activated(
+ events.gift_card_activated_event(
gift_card=gift_card, user=info.context.user, app=info.context.app
)
return GiftCardActivate(gift_card=gift_card)
@@ -440,7 +440,7 @@ class GiftCardAddNote(BaseMutation):
def perform_mutation(cls, _root, info, **data):
gift_card = cls.get_node_or_error(info, data.get("id"), only_type=GiftCard)
cleaned_input = cls.clean_input(info, gift_card, data)
- event = events.gift_card_note_added(
+ event = events.gift_card_note_added_event(
gift_card=gift_card,
user=info.context.user,
app=info.context.app,
diff --git a/saleor/graphql/giftcard/tests/queries/test_gift_card.py b/saleor/graphql/giftcard/tests/queries/test_gift_card.py
index 5257ed14ac..1b17dd3b82 100644
--- a/saleor/graphql/giftcard/tests/queries/test_gift_card.py
+++ b/saleor/graphql/giftcard/tests/queries/test_gift_card.py
@@ -522,7 +522,7 @@ def test_query_gift_card_expiry_date_set_event(
gift_card.expiry_date = expiry_date
gift_card.save(update_fields=["expiry_date"])
- events.gift_card_expiry_date_updated(gift_card, old, staff_user, None)
+ events.gift_card_expiry_date_updated_event(gift_card, old, staff_user, None)
variables = {"id": graphene.Node.to_global_id("GiftCard", gift_card.pk)}
# when
@@ -557,7 +557,7 @@ def test_query_gift_card_used_in_order_event(
previous_balance = 10.0
balance_data = [(gift_card, previous_balance)]
order_id = 1
- events.gift_cards_used_in_order(balance_data, order_id, None, app)
+ events.gift_cards_used_in_order_event(balance_data, order_id, None, app)
variables = {"id": graphene.Node.to_global_id("GiftCard", gift_card.pk)}
# when
@@ -599,7 +599,7 @@ def test_query_gift_card_bought_event(
permission_manage_users,
):
# given
- events.gift_cards_bought([gift_card_expiry_date], order.id, None, app)
+ events.gift_cards_bought_event([gift_card_expiry_date], order.id, None, app)
variables = {"id": graphene.Node.to_global_id("GiftCard", gift_card_expiry_date.pk)}
# when
diff --git a/saleor/order/utils.py b/saleor/order/utils.py
index b2b810f903..9f12318a8f 100644
--- a/saleor/order/utils.py
+++ b/saleor/order/utils.py
@@ -435,7 +435,7 @@ def add_gift_cards_to_order(
"used_by_email",
]
GiftCard.objects.bulk_update(gift_cards_to_update, update_fields)
- gift_card_events.gift_cards_used_in_order(balance_data, order.id, user, app)
+ gift_card_events.gift_cards_used_in_order_event(balance_data, order.id, user, app)
def update_gift_card_balance(
diff --git a/saleor/plugins/sendgrid/tasks.py b/saleor/plugins/sendgrid/tasks.py
index 5763508547..80a8f35146 100644
--- a/saleor/plugins/sendgrid/tasks.py
+++ b/saleor/plugins/sendgrid/tasks.py
@@ -310,9 +310,9 @@ def send_gift_card_email_task(payload: dict, configuration: dict):
"email": payload["recipient_email"],
}
if payload["resending"] is True:
- gift_card_events.gift_card_resent(**email_data)
+ gift_card_events.gift_card_resent_event(**email_data)
else:
- gift_card_events.gift_card_sent(**email_data)
+ gift_card_events.gift_card_sent_event(**email_data)
@app.task(
diff --git a/saleor/plugins/user_email/tasks.py b/saleor/plugins/user_email/tasks.py
index 82dcdc01f6..2d912d55a8 100644
--- a/saleor/plugins/user_email/tasks.py
+++ b/saleor/plugins/user_email/tasks.py
@@ -131,9 +131,9 @@ def send_gift_card_email_task(recipient_email, payload, config, subject, templat
"email": payload["recipient_email"],
}
if payload["resending"] is True:
- gift_card_events.gift_card_resent(**email_data)
+ gift_card_events.gift_card_resent_event(**email_data)
else:
- gift_card_events.gift_card_sent(**email_data)
+ gift_card_events.gift_card_sent_event(**email_data)
@app.task(compression="zlib")