diff options
| author | stephanchrst <stephanchrst@gmail.com> | 2023-04-28 09:03:04 +0700 |
|---|---|---|
| committer | stephanchrst <stephanchrst@gmail.com> | 2023-04-28 09:03:04 +0700 |
| commit | 57d55f545da0fc501a9828bb3ca2988f126b241a (patch) | |
| tree | 75b98126546eea20b90ca777b2887b4813946871 /indoteknik_api/models/product_product.py | |
| parent | 3592c254ca5baf4a0a769f500f9e28a9cbc272a7 (diff) | |
| parent | 6fa5de951abc02884eb37cdc6786c0f3d141ccc5 (diff) | |
Merge branch 'staging' into release
Diffstat (limited to 'indoteknik_api/models/product_product.py')
| -rw-r--r-- | indoteknik_api/models/product_product.py | 53 |
1 files changed, 45 insertions, 8 deletions
diff --git a/indoteknik_api/models/product_product.py b/indoteknik_api/models/product_product.py index 32bd7c21..49ea7804 100644 --- a/indoteknik_api/models/product_product.py +++ b/indoteknik_api/models/product_product.py @@ -1,4 +1,5 @@ from odoo import models +from odoo.http import request import math @@ -26,9 +27,33 @@ class ProductProduct(models.Model): } return data - def v2_api_single_response(self, product_product): - product_pricelist_default_discount_id = self.env['ir.config_parameter'].get_param('product.pricelist.default_discount_id') - product_pricelist_default_discount_id = int(product_pricelist_default_discount_id) + def v2_api_single_response(self, product_product, pricelist=False): + 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')) + + discount_percentage = product_product._get_website_disc(0) + price_discount = product_product._get_website_price_after_disc_and_tax() + + price_tier = False + pricelists = { + 'tier1': product_product._get_pricelist_tier1, + 'tier2': product_product._get_pricelist_tier2, + 'tier3': product_product._get_pricelist_tier3, + } + pricelist_id = pricelist.id if pricelist else False + if pricelist_id == product_pricelist_tier1: price_tier = 'tier1' + if pricelist_id == product_pricelist_tier2: price_tier = 'tier2' + if pricelist_id == product_pricelist_tier3: price_tier = 'tier3' + + 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] + product_template = product_product.product_tmpl_id data = { 'id': product_product.id, @@ -41,8 +66,8 @@ class ProductProduct(models.Model): 'name': product_product.display_name, 'price': { 'price': product_product._get_website_price_exclude_tax(), - 'discount_percentage': product_product._get_website_disc(0), - 'price_discount': product_product._get_website_price_after_disc_and_tax() + 'discount_percentage': discount_percentage, + 'price_discount': price_discount }, 'stock': product_product.qty_stock_vendor, 'weight': product_product.weight, @@ -134,9 +159,13 @@ class ProductProduct(models.Model): return math.floor(res) def _get_pricelist_tier1(self): + product_pricelist_tier1 = int(self.env['ir.config_parameter'].get_param('product.pricelist.tier1')) default_divide_tax = float(1.11) base_price = discount = price = 0 - pricelist_item = self.env['product.pricelist.item'].search([('pricelist_id', '=', 15037), ('product_id', '=', self.id)], limit=1) + pricelist_item = self.env['product.pricelist.item'].search([ + ('pricelist_id', '=', product_pricelist_tier1), + ('product_id', '=', self.id) + ], limit=1) if pricelist_item: # base_price = self._get_website_price_exclude_tax() base_price_incl = self._get_website_price_include_tax() @@ -152,9 +181,13 @@ class ProductProduct(models.Model): return data def _get_pricelist_tier2(self): + product_pricelist_tier2 = int(self.env['ir.config_parameter'].get_param('product.pricelist.tier2')) default_divide_tax = float(1.11) base_price = discount = price = 0 - pricelist_item = self.env['product.pricelist.item'].search([('pricelist_id', '=', 15038), ('product_id', '=', self.id)], limit=1) + pricelist_item = self.env['product.pricelist.item'].search([ + ('pricelist_id', '=', product_pricelist_tier2), + ('product_id', '=', self.id) + ], limit=1) if pricelist_item: # base_price = self._get_website_price_exclude_tax() base_price_incl = self._get_website_price_include_tax() @@ -170,9 +203,13 @@ class ProductProduct(models.Model): return data def _get_pricelist_tier3(self): + product_pricelist_tier3 = int(self.env['ir.config_parameter'].get_param('product.pricelist.tier3')) default_divide_tax = float(1.11) base_price = discount = price = 0 - pricelist_item = self.env['product.pricelist.item'].search([('pricelist_id', '=', 15039), ('product_id', '=', self.id)], limit=1) + pricelist_item = self.env['product.pricelist.item'].search([ + ('pricelist_id', '=', product_pricelist_tier3), + ('product_id', '=', self.id) + ], limit=1) if pricelist_item: # base_price = self._get_website_price_exclude_tax() base_price_incl = self._get_website_price_include_tax() |
