diff options
| author | Rafi Zadanly <zadanlyr@gmail.com> | 2023-10-04 13:37:24 +0700 |
|---|---|---|
| committer | Rafi Zadanly <zadanlyr@gmail.com> | 2023-10-04 13:37:24 +0700 |
| commit | 7eef1519e2b89b25a86cd0563f98df93a1041ddf (patch) | |
| tree | 1fc660e79a38963ef3358e80dd10c0715c6161ef | |
| parent | d238f43442cc27db0d0c05bba99b42b41eaadf54 (diff) | |
| parent | f8ae554ea2fe3d9dcce59811941f63c58fdaae3c (diff) | |
Merge branch 'change/feature/pricelist' into dev/pricelist
| -rw-r--r-- | indoteknik_api/models/product_product.py | 34 | ||||
| -rw-r--r-- | indoteknik_api/models/res_users.py | 9 | ||||
| -rw-r--r-- | indoteknik_custom/models/product_pricelist.py | 23 |
3 files changed, 30 insertions, 36 deletions
diff --git a/indoteknik_api/models/product_product.py b/indoteknik_api/models/product_product.py index fdc90533..f01c4ed1 100644 --- a/indoteknik_api/models/product_product.py +++ b/indoteknik_api/models/product_product.py @@ -59,35 +59,31 @@ class ProductProduct(models.Model): def calculate_website_price(self, pricelist=False): pricelist = pricelist or self.env.user_pricelist + default_price_tier = '1_v2' - discount_percentage = self._get_website_disc(0) - price_discount = self._get_website_price_after_disc_and_tax() + price_tier = pricelist.get_tier_level() + price_tier = price_tier if price_tier else default_price_tier - pricelists = { - 'tier1': self._get_pricelist_tier1, - 'tier2': self._get_pricelist_tier2, - 'tier3': self._get_pricelist_tier3, - } - - price_tier = pricelist.get_tier_name() - if price_tier: - price = pricelists[price_tier]() - discount_key = 'discount_%s' % price_tier - price_key = 'price_%s' % price_tier - if price[discount_key] > 0: discount_percentage = price[discount_key] - if price[price_key] > 0: price_discount = price[price_key] + pricelist = self._get_pricelist_tier(price_tier) + discount_key = f'discount_tier{price_tier}' + price_key = f'price_tier{price_tier}' + + price = self._v2_get_website_price_exclude_tax() + discount_percentage = pricelist.get(discount_key, 0) + price_discount = pricelist.get(price_key, 0) + flashsale = self._get_flashsale_price() flashsale_price = flashsale.get('flashsale_price', 0) flashsale_discount = flashsale.get('flashsale_discount', 0) if flashsale_price > 0 and flashsale_price < price_discount: price_discount = flashsale_price discount_percentage = flashsale_discount - + return { - 'price': self._get_website_price_exclude_tax(), + 'price': price, 'discount_percentage': discount_percentage, - 'price_discount': price_discount + 'price_discount': price_discount if price_discount > 0 else price } def api_manufacture(self, product_template): @@ -262,7 +258,7 @@ class ProductProduct(models.Model): if not item: return result - base_price = self._get_website_price_exclude_tax() + base_price = self._v2_get_website_price_exclude_tax() discount = 0 price_flashsale = 0 if item.price_discount > 0: diff --git a/indoteknik_api/models/res_users.py b/indoteknik_api/models/res_users.py index 0fe9008b..f331321f 100644 --- a/indoteknik_api/models/res_users.py +++ b/indoteknik_api/models/res_users.py @@ -6,16 +6,9 @@ class ResUsers(models.Model): def api_single_response(self, res_user, with_detail=''): config = self.env['ir.config_parameter'] - product_pricelist_tier1 = int(config.get_param('product.pricelist.tier1')) - product_pricelist_tier2 = int(config.get_param('product.pricelist.tier2')) - product_pricelist_tier3 = int(config.get_param('product.pricelist.tier3')) user_pricelist = res_user.property_product_pricelist - user_pricelist_id = user_pricelist.id if user_pricelist else False - pricelist_tier = False - if user_pricelist_id == product_pricelist_tier1: pricelist_tier = 'tier1' - if user_pricelist_id == product_pricelist_tier2: pricelist_tier = 'tier2' - if user_pricelist_id == product_pricelist_tier3: pricelist_tier = 'tier3' + pricelist_tier = user_pricelist.sudo().get_tier_name() data = { 'id': res_user.id, diff --git a/indoteknik_custom/models/product_pricelist.py b/indoteknik_custom/models/product_pricelist.py index 026977f8..384d1353 100644 --- a/indoteknik_custom/models/product_pricelist.py +++ b/indoteknik_custom/models/product_pricelist.py @@ -24,17 +24,22 @@ class ProductPricelist(models.Model): remaining_time = round(remaining_time) return max(remaining_time, 0) - def get_tier_name(self): + def get_tier_level(self): config = self.env['ir.config_parameter'] - product_pricelist_tier1 = int(config.get_param('product.pricelist.tier1', 0)) - product_pricelist_tier2 = int(config.get_param('product.pricelist.tier2', 0)) - product_pricelist_tier3 = int(config.get_param('product.pricelist.tier3', 0)) + tier_keys = ['1', '2', '3', '1_v2', '2_v2', '3_v2', '4_v2', '5_v2'] + + for tier in tier_keys: + tier_id = config.get_param('product.pricelist.tier' + tier, 0) + if self.id == int(tier_id): + return tier - price_tier = None - if self.id == product_pricelist_tier1: price_tier = 'tier1' - if self.id == product_pricelist_tier2: price_tier = 'tier2' - if self.id == product_pricelist_tier3: price_tier = 'tier3' - return price_tier + return None + + def get_tier_name(self): + tier_level = self.get_tier_level() + tier_name = f'tier{tier_level}' if tier_level else None + + return tier_name class ProductPricelistItem(models.Model): _inherit = 'product.pricelist.item' |
