fix: allow clearing all period discounts from promo groups
Empty period_discounts dict was normalized to None by the schema, making it indistinguishable from "field absent" (don't update). Now empty dict passes through to CRUD which correctly sets period_discounts=None in DB, clearing all discounts.
This commit is contained in:
@@ -166,7 +166,7 @@ async def update_promo_group(
|
||||
group.device_discount_percent = max(0, min(100, device_discount_percent))
|
||||
if period_discounts is not None:
|
||||
normalized_period_discounts = _normalize_period_discounts(period_discounts)
|
||||
group.period_discounts = normalized_period_discounts or None
|
||||
group.period_discounts = normalized_period_discounts if normalized_period_discounts else None
|
||||
if auto_assign_total_spent_kopeks is not None:
|
||||
value = max(0, auto_assign_total_spent_kopeks)
|
||||
group.auto_assign_total_spent_kopeks = value if value > 0 else None
|
||||
|
||||
@@ -18,7 +18,9 @@ def _normalize_period_discounts(value: dict[object, object] | None) -> dict[int,
|
||||
except (TypeError, ValueError):
|
||||
continue
|
||||
|
||||
return normalized or None
|
||||
# Return empty dict (not None) so the backend can distinguish
|
||||
# "clear all discounts" ({}) from "don't touch discounts" (None/absent).
|
||||
return normalized
|
||||
|
||||
|
||||
class PromoGroupResponse(BaseModel):
|
||||
|
||||
Reference in New Issue
Block a user