summaryrefslogtreecommitdiff
path: root/indoteknik_api/models/product_template.py
diff options
context:
space:
mode:
authorIT Fixcomart <it@fixcomart.co.id>2022-10-11 15:58:58 +0700
committerIT Fixcomart <it@fixcomart.co.id>2022-10-11 15:58:58 +0700
commitdae117ce9bb219557c9a4fc995e93bc4a88ea03f (patch)
tree62f51e1c8290651606759fc8d31a2662e7878590 /indoteknik_api/models/product_template.py
parentfd6af0fbd83042c8471c3c58ff459f52bed45938 (diff)
init commit
Diffstat (limited to 'indoteknik_api/models/product_template.py')
-rw-r--r--indoteknik_api/models/product_template.py48
1 files changed, 48 insertions, 0 deletions
diff --git a/indoteknik_api/models/product_template.py b/indoteknik_api/models/product_template.py
index e69de29b..6b8973a2 100644
--- a/indoteknik_api/models/product_template.py
+++ b/indoteknik_api/models/product_template.py
@@ -0,0 +1,48 @@
+from odoo import models, fields
+
+
+class ProductTemplate(models.Model):
+ _inherit = 'product.template'
+
+ def api_single_response(self, product_template, with_detail=False):
+ base_url = self.env['ir.config_parameter'].get_param('web.base.url')
+ product_pricelist_default = self.env['ir.config_parameter'].get_param('product.pricelist.default')
+ product_pricelist_default = int(product_pricelist_default)
+ data = {
+ 'id': product_template.id,
+ 'image': base_url + 'api/image/product.template/image_128/' + str(product_template.id) if product_template.image_128 else '',
+ 'code': product_template.default_code,
+ 'name': product_template.name,
+ 'lowest_price': self.env['product.pricelist'].get_lowest_product_variant_price(product_template, product_pricelist_default),
+ 'variant_total': len(product_template.product_variant_ids),
+ 'stock_total': product_template.qty_stock_vendor,
+ 'manufacture': self.api_manufacture(product_template)
+ }
+ if with_detail:
+ detail_data = {
+ 'image': base_url + 'api/image/product.template/image_512/' + str(product_template.id) if product_template.image_512 else '',
+ 'variants': [],
+ 'description': product_template.website_description
+ }
+ for variant in product_template.product_variant_ids:
+ detail_data['variants'].append({
+ 'id': variant.id,
+ 'code': variant.default_code,
+ 'name': variant.name,
+ 'price': self.env['product.pricelist'].compute_price(product_pricelist_default, variant.id),
+ 'stock': variant.qty_stock_vendor
+ })
+ data.update(detail_data)
+ 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 '',
+ }
+ return {} \ No newline at end of file