diff options
| author | stephanchrst <stephanchrst@gmail.com> | 2023-04-11 13:57:01 +0700 |
|---|---|---|
| committer | stephanchrst <stephanchrst@gmail.com> | 2023-04-11 13:57:01 +0700 |
| commit | 000a7fa68a738843c443145c1a8d102783e04fac (patch) | |
| tree | 04b7c6bf423ce0cf93ea4a526408d71426caaf9e /indoteknik_api/models/product_template.py | |
| parent | d1b86303b0934c9f6348e7016822d449349540d3 (diff) | |
| parent | 3b5871b8c364e819a2fbaf268e4693e848e6af0a (diff) | |
Merge branch 'release' into flashsale-solr
Diffstat (limited to 'indoteknik_api/models/product_template.py')
| -rw-r--r-- | indoteknik_api/models/product_template.py | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/indoteknik_api/models/product_template.py b/indoteknik_api/models/product_template.py index 72dda17f..4d16727f 100644 --- a/indoteknik_api/models/product_template.py +++ b/indoteknik_api/models/product_template.py @@ -51,6 +51,53 @@ class ProductTemplate(models.Model): data.update(data_with_detail) return data + def v2_api_single_response(self, product_template, with_detail=''): + 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) + data = { + 'id': product_template.id, + 'image': self.env['ir.attachment'].api_image('product.template', 'image_128', product_template.id), + 'code': product_template.default_code or '', + 'name': product_template.name, + 'lowest_price': self.env['product.pricelist'].get_lowest_product_variant_price(product_template, product_pricelist_default_discount_id), + 'variant_total': len(product_template.product_variant_ids), + 'stock_total': product_template.qty_stock_vendor, + 'weight': product_template.weight, + 'manufacture': self.api_manufacture(product_template), + 'categories': self.api_categories(product_template), + } + + if with_detail != '': + data_with_detail = { + 'image': self.env['ir.attachment'].api_image('product.template', 'image_512', product_template.id), + 'display_name': product_template.display_name, + 'variants': [self.env['product.product'].v2_api_single_response(variant) for variant in product_template.product_variant_ids], + 'description': product_template.website_description or '', + } + data.update(data_with_detail) + + if with_detail == 'SOLR': + is_image_found = self.env['ir.attachment'].is_found('product.template', 'image_128', product_template.id) + rate = 0 + if data['lowest_price']['price'] > 0: + rate += 1 + if product_template.have_promotion_program: + rate += 1 + if is_image_found: + rate += 1 + if product_template.website_description: + rate += 1 + if product_template.qty_stock_vendor > 0: + rate += 1 + data_with_detail = { + 'solr_flag': product_template.solr_flag, + 'product_rating': rate, + 'search_rank': product_template.search_rank, + 'search_rank_weekly': product_template.search_rank_weekly + } + data.update(data_with_detail) + return data + def api_manufacture(self, product_template): if product_template.x_manufacture: manufacture = product_template.x_manufacture |
