diff options
| author | Rafi Zadanly <zadanlyr@gmail.com> | 2023-01-23 14:44:12 +0700 |
|---|---|---|
| committer | Rafi Zadanly <zadanlyr@gmail.com> | 2023-01-23 14:44:12 +0700 |
| commit | 8af5ee591aabc2d5d946c0eece93a5caab989975 (patch) | |
| tree | a81740fff5f248bd4dd6b190f8650cdfa8849b47 /indoteknik_api/models/product_template.py | |
| parent | 4bc68435bc20d7da0f38bd2370057481cb995584 (diff) | |
Fix get api image logic
Diffstat (limited to 'indoteknik_api/models/product_template.py')
| -rw-r--r-- | indoteknik_api/models/product_template.py | 13 |
1 files changed, 6 insertions, 7 deletions
diff --git a/indoteknik_api/models/product_template.py b/indoteknik_api/models/product_template.py index 9e8d04bc..72dda17f 100644 --- a/indoteknik_api/models/product_template.py +++ b/indoteknik_api/models/product_template.py @@ -5,12 +5,11 @@ class ProductTemplate(models.Model): _inherit = 'product.template' def api_single_response(self, product_template, with_detail=''): - base_url = self.env['ir.config_parameter'].get_param('web.base.url') 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': base_url + 'api/image/product.template/image_128/' + str(product_template.id) if product_template.image_128 else '', + '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), @@ -23,7 +22,7 @@ class ProductTemplate(models.Model): if with_detail != '': data_with_detail = { - 'image': base_url + 'api/image/product.template/image_512/' + str(product_template.id) if product_template.image_512 else '', + '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'].api_single_response(variant) for variant in product_template.product_variant_ids], 'description': product_template.website_description or '', @@ -31,12 +30,13 @@ class ProductTemplate(models.Model): 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 product_template.image_128: + if is_image_found: rate += 1 if product_template.website_description: rate += 1 @@ -52,14 +52,13 @@ class ProductTemplate(models.Model): return data def api_manufacture(self, product_template): - base_url = self.env['ir.config_parameter'].get_param('web.base.url') if product_template.x_manufacture: manufacture = product_template.x_manufacture return { 'id': manufacture.id, 'name': manufacture.x_name, - 'image_promotion_1': base_url + 'api/image/x_manufactures/image_promotion_1/' + str(manufacture.id) if manufacture.image_promotion_1 else '', - 'image_promotion_2': base_url + 'api/image/x_manufactures/image_promotion_2/' + str(manufacture.id) if manufacture.image_promotion_2 else '', + 'image_promotion_1': self.env['ir.attachment'].api_image('x_manufactures', 'image_promotion_1', manufacture.id), + 'image_promotion_2': self.env['ir.attachment'].api_image('x_manufactures', 'image_promotion_2', manufacture.id), } return {} |
