]> git.parisson.com Git - teleforma.git/commitdiff
Article 98 fixes pb-docker-dev
authorYoan Le Clanche <yoanl@pilotsystems.net>
Wed, 6 May 2026 15:38:05 +0000 (17:38 +0200)
committerYoan Le Clanche <yoanl@pilotsystems.net>
Wed, 6 May 2026 15:38:05 +0000 (17:38 +0200)
teleforma/models/core.py

index 37af82307b04b128e73e54425e064e605f94cda1..fd243a576873e7ab23c74ebb083fa809cb9e9a4d 100755 (executable)
@@ -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']),
             }