From 6c7c80b9cf3f4146af1fcfc4c9b24881a7b29b3c Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Wed, 25 Sep 2024 14:39:16 +0700 Subject: add price_tier to program line --- .../models/promotion/promotion_program_line.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'indoteknik_custom/models/promotion') diff --git a/indoteknik_custom/models/promotion/promotion_program_line.py b/indoteknik_custom/models/promotion/promotion_program_line.py index a57f1f2c..903e95cf 100644 --- a/indoteknik_custom/models/promotion/promotion_program_line.py +++ b/indoteknik_custom/models/promotion/promotion_program_line.py @@ -34,6 +34,28 @@ class PromotionProgramLine(models.Model): active = fields.Boolean(string="Active", default=True) solr_flag = fields.Integer(string="Solr Flag", default=1) description = fields.Char('Description') + price_tier_1 = fields.Float('Price Tier 1') + price_tier_2 = fields.Float('Price Tier 2') + price_tier_3 = fields.Float('Price Tier 3') + price_tier_4 = fields.Float('Price Tier 4') + price_tier_5 = fields.Float('Price Tier 5') + + def get_price_tier(self, product_id, qty): + product = self.env['product.product'].browse(product_id.id) # Get the product record + + tiers = ['1_v2', '2_v2', '3_v2', '4_v2', '5_v2'] + + for index, tier in enumerate(tiers, start=1): # Automatically count from 1 to 5 + # Call the function _get_pricelist_tier from product.product model + price_tier_data = product._get_pricelist_tier(tier) + + # Use the index as the tier number (1, 2, 3, etc.) + price_field = f'price_tier_{index}' # 'price_tier_1', 'price_tier_2', etc. + + # Update the corresponding price_tier_X field + if price_field in self._fields: # Ensure the field exists in the model + price = price_tier_data.get(f'price_tier{tier}', 0) * qty # Multiply by qty + self[price_field] = price def get_active_promotions(self, product_id): current_time = datetime.now().strftime('%Y-%m-%d %H:%M:%S') -- cgit v1.2.3