diff options
| author | Stephan Christianus <stephanchrst@gmail.com> | 2023-04-11 09:16:13 +0000 |
|---|---|---|
| committer | Stephan Christianus <stephanchrst@gmail.com> | 2023-04-11 09:16:13 +0000 |
| commit | 4e1b9b2ab230e24e594008340690c69c35b42037 (patch) | |
| tree | 07b4aba9bc8c61cbbc81ebcace23b4e142c37780 /indoteknik_api/models | |
| parent | a854c5cca6e374589449e54a2fb9efb7f2c24955 (diff) | |
| parent | d753a2b681dc14e47551e4525fddb23820b841af (diff) | |
Merged in flashsale-solr (pull request #30)
Flashsale solr
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 | 41 |
2 files changed, 67 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..409b69c2 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,36 @@ 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_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: + flashsale_id = pricelist.id + flashsale_name = pricelist.name + 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: + 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 |
