summaryrefslogtreecommitdiff
path: root/indoteknik_api/models
diff options
context:
space:
mode:
authorIT Fixcomart <it@fixcomart.co.id>2022-10-12 16:52:46 +0700
committerIT Fixcomart <it@fixcomart.co.id>2022-10-12 16:52:46 +0700
commitc4b6e2d594b8cbd7d424673d04741a1a4cb2ff81 (patch)
treeda13382d8d442a991a23e058f2021e0a96c73c87 /indoteknik_api/models
parentdae117ce9bb219557c9a4fc995e93bc4a88ea03f (diff)
Update Feature:
- filter product_name, manufactures, categories in flash sale - add categories in product response - create get manufacture and category by page
Diffstat (limited to 'indoteknik_api/models')
-rw-r--r--indoteknik_api/models/product_template.py23
1 files changed, 18 insertions, 5 deletions
diff --git a/indoteknik_api/models/product_template.py b/indoteknik_api/models/product_template.py
index 6b8973a2..0cbf605f 100644
--- a/indoteknik_api/models/product_template.py
+++ b/indoteknik_api/models/product_template.py
@@ -11,23 +11,24 @@ class ProductTemplate(models.Model):
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,
+ '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),
'variant_total': len(product_template.product_variant_ids),
'stock_total': product_template.qty_stock_vendor,
- 'manufacture': self.api_manufacture(product_template)
+ 'manufacture': self.api_manufacture(product_template),
+ 'categories': self.api_categories(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
+ 'description': product_template.website_description or '',
}
for variant in product_template.product_variant_ids:
detail_data['variants'].append({
'id': variant.id,
- 'code': variant.default_code,
+ 'code': variant.default_code or '',
'name': variant.name,
'price': self.env['product.pricelist'].compute_price(product_pricelist_default, variant.id),
'stock': variant.qty_stock_vendor
@@ -45,4 +46,16 @@ class ProductTemplate(models.Model):
'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
+ return {}
+
+ def api_categories(self, product_template):
+ if product_template.public_categ_ids:
+ categories = []
+ for category in product_template.public_categ_ids:
+ categories.append({
+ 'id': category.id,
+ 'name': category.name
+ })
+ return categories
+ return []
+ \ No newline at end of file