Features: 1) Prevent duplicate "order finished" emails with added check on system_email_sent attribute; 2) Automatically update system_email_sent attribute after sending order email;
Fixes: 1) Remove unused `_` import in `drf.py`; 2) Trim redundant newline in `apply_addresses` method; Extra: 1) Fix minor formatting in `deepl_translate.py` command; 2) Simplify `SPECTACULAR_PLATFORM_DESCRIPTION` string handling; 3) Minor refactoring and cleanup in email utility and related logic.
This commit is contained in:
parent
e9d17eddab
commit
0a2b4b65a0
5 changed files with 13 additions and 7 deletions
|
|
@ -1543,7 +1543,6 @@ class Order(ExportModelOperationsMixin("order"), NiceModel): # type: ignore [mi
|
|||
|
||||
def apply_addresses(self, billing_address_uuid: str | None = None, shipping_address_uuid: str | None = None):
|
||||
try:
|
||||
|
||||
if not any([shipping_address_uuid, billing_address_uuid]) and not self.is_whole_digital:
|
||||
raise ValueError(_("you can only buy physical products with shipping address specified"))
|
||||
|
||||
|
|
|
|||
|
|
@ -115,7 +115,7 @@ def process_order_changes(instance, created, **_kwargs):
|
|||
instance.status = "FAILED"
|
||||
instance.save()
|
||||
|
||||
if instance.status == "FINISHED":
|
||||
if instance.status == "FINISHED" and not instance.attributes.get("system_email_sent", False):
|
||||
send_order_finished_email.delay(instance.uuid)
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -132,6 +132,9 @@ def send_order_finished_email(order_pk: str) -> tuple[bool, str]:
|
|||
if not order.user:
|
||||
return False, f"Order's user not found with the given pk: {order_pk}"
|
||||
|
||||
if order.attributes.get("system_email_sent"):
|
||||
return True, str(order.uuid)
|
||||
|
||||
digital_ops = []
|
||||
|
||||
for digital_op in order.order_products.filter(
|
||||
|
|
@ -160,4 +163,10 @@ def send_order_finished_email(order_pk: str) -> tuple[bool, str]:
|
|||
|
||||
send_thank_you_email(shipped_ops)
|
||||
|
||||
if type(order.attributes) is not dict:
|
||||
order.attributes = {}
|
||||
|
||||
order.attributes["system_email_sent"] = True
|
||||
order.save()
|
||||
|
||||
return True, str(order.uuid)
|
||||
|
|
|
|||
|
|
@ -1,8 +1,6 @@
|
|||
from datetime import timedelta
|
||||
from os import getenv
|
||||
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
from evibes.settings.base import DEBUG, EVIBES_VERSION, SECRET_KEY
|
||||
from evibes.settings.constance import CONSTANCE_CONFIG
|
||||
|
||||
|
|
@ -74,7 +72,7 @@ Current API version: {EVIBES_VERSION}
|
|||
"""
|
||||
) # noqa: E501, F405
|
||||
|
||||
SPECTACULAR_PLATFORM_DESCRIPTION = (f"""
|
||||
SPECTACULAR_PLATFORM_DESCRIPTION = f"""
|
||||
Welcome to the {
|
||||
CONSTANCE_CONFIG.get("PROJECT_NAME")[0] # type: ignore [index]
|
||||
} Platform API documentation.
|
||||
|
|
@ -106,7 +104,7 @@ The {
|
|||
|
||||
## Version
|
||||
Current API version: {EVIBES_VERSION}
|
||||
""") # noqa: E501, F405
|
||||
""" # noqa: E501, F405
|
||||
|
||||
SPECTACULAR_PLATFORM_SETTINGS = {
|
||||
"TITLE": f"{CONSTANCE_CONFIG.get('PROJECT_NAME')[0]} API", # type: ignore [index]
|
||||
|
|
|
|||
Loading…
Reference in a new issue