diff options
| author | Rafi Zadanly <zadanlyr@gmail.com> | 2023-04-17 11:52:04 +0700 |
|---|---|---|
| committer | Rafi Zadanly <zadanlyr@gmail.com> | 2023-04-17 11:52:04 +0700 |
| commit | 015ca8f0ae8ecdaaf388ee08420af54a84fb2d0c (patch) | |
| tree | 6e95bf27732dc9958ab161363a121bd46d68b717 /indoteknik_api/models | |
| parent | 719dc824379bff729a97007432ef6871954b0980 (diff) | |
| parent | 4eb477f655231e39eaacb4453f216692a8355bac (diff) | |
Merge branch 'release' into staging
Diffstat (limited to 'indoteknik_api/models')
| -rw-r--r-- | indoteknik_api/models/product_pricelist.py | 26 | ||||
| -rw-r--r-- | indoteknik_api/models/product_product.py | 95 |
2 files changed, 121 insertions, 0 deletions
diff --git a/indoteknik_api/models/product_pricelist.py b/indoteknik_api/models/product_pricelist.py index 4e5c9501..f05fa82d 100644 --- a/indoteknik_api/models/product_pricelist.py +++ b/indoteknik_api/models/product_pricelist.py @@ -107,3 +107,29 @@ class ProductPricelist(models.Model): if product_id in pricelist_product_ids: return pricelist.id return False + + +class ProductPricelistItem(models.Model): + _inherit = 'product.pricelist.item' + + def api_single_response(self, item): + data = { + 'id': item.product_id.id, + 'parent': { + 'id': item.product_id.product_tmpl_id.id, + 'name': item.product_id.product_tmpl_id.name, + 'image': self.env['ir.attachment'].api_image('product.template', 'image_256', item.product_id.product_tmpl_id.id) + }, + 'code': item.product_id.default_code or item.product_tmpl_id.default_code or '', + 'name': item.product_id.display_name, + 'price':{ + 'price': item.product_id._get_website_price_exclude_tax(), + 'discount': item.product_id._get_website_disc(0), + 'price_discount': item.product_id._get_website_price_after_disc_and_tax() + }, + 'stock': item.product_id.qty_stock_vendor, + 'weight': item.product_id.weight, + 'attributes': [x.name for x in item.product_id.product_template_attribute_value_ids], + 'manufacture': item.product_id.api_manufacture(item.product_id) + } + return data
\ No newline at end of file diff --git a/indoteknik_api/models/product_product.py b/indoteknik_api/models/product_product.py index c867eaa0..32bd7c21 100644 --- a/indoteknik_api/models/product_product.py +++ b/indoteknik_api/models/product_product.py @@ -62,6 +62,14 @@ class ProductProduct(models.Model): } return {} + def _is_have_flashsale(self): + active_flashsale = self.env['product.pricelist'].get_active_flash_sale() + for pricelist in active_flashsale: + found_product = self.env['product.pricelist.item'].search([('pricelist_id', '=', pricelist.id), ('product_id', '=', self.id)]) + if found_product: + return True + return False + def _get_website_price_include_tax(self): default_pricelist_id = int(1) @@ -124,3 +132,90 @@ class ProductProduct(models.Model): price_after_disc = self._get_website_price_after_disc_and_tax() res = price_after_disc * default_percent_tax / 100 return math.floor(res) + + def _get_pricelist_tier1(self): + 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) + if pricelist_item: + # base_price = self._get_website_price_exclude_tax() + base_price_incl = self._get_website_price_include_tax() + discount = pricelist_item.price_discount + price = base_price_incl - (base_price_incl * discount / 100) + price = price / default_divide_tax + price = math.floor(price) + data = { + # 'base_price_tier1': base_price or 0, + 'discount_tier1': discount or 0, + 'price_tier1': price or 0 + } + return data + + def _get_pricelist_tier2(self): + 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) + if pricelist_item: + # base_price = self._get_website_price_exclude_tax() + base_price_incl = self._get_website_price_include_tax() + discount = pricelist_item.price_discount + price = base_price_incl - (base_price_incl * discount / 100) + price = price / default_divide_tax + price = math.floor(price) + data = { + # 'base_price_tier2': base_price or 0, + 'discount_tier2': discount or 0, + 'price_tier2': price or 0 + } + return data + + def _get_pricelist_tier3(self): + 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) + if pricelist_item: + # base_price = self._get_website_price_exclude_tax() + base_price_incl = self._get_website_price_include_tax() + discount = pricelist_item.price_discount + price = base_price_incl - (base_price_incl * discount / 100) + price = price / default_divide_tax + price = math.floor(price) + data = { + # 'base_price_tier3': base_price or 0, + 'discount_tier3': discount or 0, + 'price_tier3': price or 0 + } + return data + + def _get_flashsale_price(self): + # must get active pricelist + active_flash_sale = self.env['product.pricelist'].get_active_flash_sale() + flashsale_id = 0 + flashsale_name = '' + # loop pricelist items + base_price = discount = price_flashsale = 0 + for pricelist in active_flash_sale: + query = [ + ('pricelist_id', '=', pricelist.id), + ('product_id', '=', self.id), + ] + pricelist_items = self.env['product.pricelist.item'].search(query, limit=1) + for item in pricelist_items: + flashsale_id = pricelist.id + flashsale_name = pricelist.name + base_price = self._get_website_price_exclude_tax() + if item.price_discount > 0: + discount = item.price_discount + # base_item = self.env['product.pricelist.item'].search([('pricelist_id', '=', item.base_pricelist_id.id), ('product_id', '=', self.id)], limit=1) + price_flashsale = base_price - (base_price * discount // 100) + elif item.fixed_price > 0: + price_flashsale = item.fixed_price # ask darren for include or exclude + discount = (base_price - price_flashsale) // base_price * 100 + data = { + 'flashsale_id': flashsale_id, + 'flashsale_name': flashsale_name, + 'flashsale_base_price': base_price, + 'flashsale_discount': discount, + 'flashsale_price': price_flashsale + } + return data |
