Features: 1) Switch Promotion creation to update_or_create to handle existing records;
Fixes: 1) Ensure Promotion update logic correctly applies changes to existing entries; Extra: 1) Code formatting adjustments to improve readability;
This commit is contained in:
parent
d001e238f8
commit
5c98129a6f
1 changed files with 2 additions and 1 deletions
|
|
@ -209,7 +209,8 @@ def process_promotions() -> tuple[bool, str]:
|
|||
product = eligible_products.order_by("?").first()
|
||||
selected_products.append(product)
|
||||
|
||||
promotion = Promotion.objects.create(name=promotion_name, discount_percent=discount_percent, is_active=True)
|
||||
promotion = Promotion.objects.update_or_create(name=promotion_name,
|
||||
defaults={"discount_percent": discount_percent, "is_active": True})
|
||||
|
||||
promotion.products.set(selected_products)
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue