From c024d695f663fb0b3e11cac9d07ec649d73e90ee Mon Sep 17 00:00:00 2001 From: Yoan Le Clanche Date: Wed, 6 May 2026 17:38:05 +0200 Subject: [PATCH] Article 98 fixes --- teleforma/models/core.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/teleforma/models/core.py b/teleforma/models/core.py index 37af8230..fd243a57 100755 --- a/teleforma/models/core.py +++ b/teleforma/models/core.py @@ -1035,7 +1035,8 @@ class Conference(Displayable, WebclassMixin, ProductCodeMixin, SuggestionsMixin) """ Total price for the given quantity, applying any pack rule from PACK_PRICING. Pass unit_price (e.g. CartItem's locked-in price) - to override self.price. + to override self.price. Each full multiple of pack_size triggers + a new pack, remaining units use extra_unit_price. """ if unit_price is None: unit_price = self.price or 0 @@ -1045,30 +1046,32 @@ class Conference(Displayable, WebclassMixin, ProductCodeMixin, SuggestionsMixin) cast = type(unit_price) pack_price = cast(rule['pack_price']) extra_price = cast(rule['extra_unit_price']) - return pack_price + (quantity - rule['pack_size']) * extra_price + packs, extras = divmod(quantity, rule['pack_size']) + return packs * pack_price + extras * extra_price def get_invoice_lines(self, unit_price, quantity, description): """ Yield invoice line dicts for this conference at the given quantity, splitting into a pack line + extras line when a pack rule applies. + Number of packs = quantity // pack_size. """ rule = self.pack_pricing if not rule or quantity < rule['pack_size']: yield {'designation': description, 'VAT': 0, 'qte': quantity, 'PUHT': unit_price} return cast = type(unit_price) + packs, extras = divmod(quantity, rule['pack_size']) yield { 'designation': "Pack de %d - %s" % (rule['pack_size'], description), 'VAT': 0, - 'qte': 1, + 'qte': packs, 'PUHT': cast(rule['pack_price']), } - extra = quantity - rule['pack_size'] - if extra > 0: + if extras > 0: yield { 'designation': description, 'VAT': 0, - 'qte': extra, + 'qte': extras, 'PUHT': cast(rule['extra_unit_price']), } -- 2.47.3