diff options
| author | Azka Nathan <darizkyfaz@gmail.com> | 2023-10-06 14:22:12 +0700 |
|---|---|---|
| committer | Azka Nathan <darizkyfaz@gmail.com> | 2023-10-06 14:22:12 +0700 |
| commit | 5f9c6e2837c8201ca8132f3d3d71627bf799fb6d (patch) | |
| tree | df2b9d4d0b52a6cf8d45d153dff977e04785abb2 /indoteknik_api/models | |
| parent | bb3c3c6cac4382220ae8a521e8c2162a5fe3d3e9 (diff) | |
| parent | 7a23a18a45fbd38fabc33f4e1a74d9f31e86cd60 (diff) | |
Merge branch 'production' of bitbucket.org:altafixco/indoteknik-addons into production
Diffstat (limited to 'indoteknik_api/models')
| -rw-r--r-- | indoteknik_api/models/product_product.py | 54 | ||||
| -rw-r--r-- | indoteknik_api/models/res_users.py | 9 |
2 files changed, 36 insertions, 27 deletions
diff --git a/indoteknik_api/models/product_product.py b/indoteknik_api/models/product_product.py index fdc90533..aa9e0ad7 100644 --- a/indoteknik_api/models/product_product.py +++ b/indoteknik_api/models/product_product.py @@ -58,36 +58,38 @@ class ProductProduct(models.Model): return True if len(product_promotions) > 0 else False def calculate_website_price(self, pricelist=False): - pricelist = pricelist or self.env.user_pricelist + price_for = self.env.context.get('price_for', 'odoo') + pricelist = pricelist or self.env.context.get('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, - } + pricelist = self._get_pricelist_tier(price_tier) + + discount_key = f'discount_tier{price_tier}' + price_key = f'price_tier{price_tier}' - 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] + discount_percentage = pricelist.get(discount_key, 0) + price_discount = pricelist.get(price_key, 0) + if price_for == 'web': + discount_percentage = 0 + price = price_discount + else: + price = self._v2_get_website_price_include_tax() + 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): @@ -249,6 +251,7 @@ class ProductProduct(models.Model): return data def _get_flashsale_price(self): + price_for = self.env.context.get('price_for', 'odoo') result = {} current_time = datetime.now().strftime('%Y-%m-%d %H:%M:%S') @@ -262,7 +265,16 @@ class ProductProduct(models.Model): if not item: return result - base_price = self._get_website_price_exclude_tax() + tier1_id = self.env['ir.config_parameter'].get_param('product.pricelist.tier1_v2', 0) + base_pricelist = self.env['product.pricelist.item'].search([ + ('pricelist_id', '=', int(tier1_id)), + ('product_id', '=', self.id) + ], limit=1) + + base_price = 0 + if base_pricelist: + base_price = base_pricelist.computed_price / 1.11 + discount = 0 price_flashsale = 0 if item.price_discount > 0: @@ -272,6 +284,10 @@ class ProductProduct(models.Model): price_flashsale = item.fixed_price # ask darren for include or exclude discount = (base_price - price_flashsale) // base_price * 100 + if price_for == 'odoo': + base_price = self._v2_get_website_price_exclude_tax() + discount = (base_price - price_flashsale) / base_price * 100 + jkt_tz = pytz.timezone('Asia/Jakarta') result.update({ 'flashsale_id': item.pricelist_id.id, 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, |
