summaryrefslogtreecommitdiff
path: root/indoteknik_api/models
diff options
context:
space:
mode:
authorIT Fixcomart <it@fixcomart.co.id>2023-07-24 03:31:59 +0000
committerIT Fixcomart <it@fixcomart.co.id>2023-07-24 03:31:59 +0000
commitc1ac22304b557b9982b5fb79d23d29b6faf48090 (patch)
treea1e6db531a5bf19994374e895d5d8a8c9abf1ffa /indoteknik_api/models
parent6966c00bf2ef2bd9c2261d9363ac6b463a7766dd (diff)
parent30909e82d7ff1f3cac4700e284f80552a0d38523 (diff)
Merged in feature/voucher-cart (pull request #65)
Feature/voucher cart
Diffstat (limited to 'indoteknik_api/models')
-rw-r--r--indoteknik_api/models/product_product.py71
-rw-r--r--indoteknik_api/models/product_template.py6
2 files changed, 38 insertions, 39 deletions
diff --git a/indoteknik_api/models/product_product.py b/indoteknik_api/models/product_product.py
index edf95a58..334b58c5 100644
--- a/indoteknik_api/models/product_product.py
+++ b/indoteknik_api/models/product_product.py
@@ -29,20 +29,46 @@ class ProductProduct(models.Model):
}
return data
- def v2_api_single_response(self, product_product, pricelist=False):
+ def v2_api_single_response(self, product_product):
+ product_template = product_product.product_tmpl_id
+ data = {
+ 'id': product_product.id,
+ 'parent': {
+ 'id': product_template.id,
+ 'name': product_template.name,
+ 'image': self.env['ir.attachment'].api_image('product.template', 'image_256', product_template.id),
+ },
+ 'code': product_product.default_code or '',
+ 'name': product_product.display_name,
+ 'price': product_product.calculate_website_price(),
+ 'stock': product_product.qty_stock_vendor,
+ 'weight': product_product.weight,
+ 'attributes': [x.name for x in product_product.product_template_attribute_value_ids],
+ 'manufacture' : self.api_manufacture(product_product)
+ }
+ return data
+
+ def has_active_program(self):
+ program_line = self.env['promotion.program.line']
+ product_promotions = program_line.get_active_promotions(self.id)
+ return True if len(product_promotions) > 0 else False
+
+ def calculate_website_price(self):
+ pricelist = self.env.user_pricelist
+
config = self.env['ir.config_parameter']
product_pricelist_tier1 = int(config.get_param('product.pricelist.tier1'))
product_pricelist_tier2 = int(config.get_param('product.pricelist.tier2'))
product_pricelist_tier3 = int(config.get_param('product.pricelist.tier3'))
- discount_percentage = product_product._get_website_disc(0)
- price_discount = product_product._get_website_price_after_disc_and_tax()
+ discount_percentage = self._get_website_disc(0)
+ price_discount = self._get_website_price_after_disc_and_tax()
price_tier = False
pricelists = {
- 'tier1': product_product._get_pricelist_tier1,
- 'tier2': product_product._get_pricelist_tier2,
- 'tier3': product_product._get_pricelist_tier3,
+ 'tier1': self._get_pricelist_tier1,
+ 'tier2': self._get_pricelist_tier2,
+ 'tier3': self._get_pricelist_tier3,
}
pricelist_id = pricelist.id if pricelist else False
if pricelist_id == product_pricelist_tier1: price_tier = 'tier1'
@@ -56,36 +82,11 @@ class ProductProduct(models.Model):
if price[discount_key] > 0: discount_percentage = price[discount_key]
if price[price_key] > 0: price_discount = price[price_key]
- flashsale = product_product._get_flashsale_price()
- flashsale_price = flashsale['flashsale_price']
- flashsale_discount = flashsale['flashsale_discount']
- if flashsale_price > 0 and flashsale_price < price_discount:
- price_discount = flashsale_price
- discount_percentage = flashsale_discount
-
- stock = product_product.qty_stock_vendor
- stock = stock if stock > 0 else 1
- product_template = product_product.product_tmpl_id
- data = {
- 'id': product_product.id,
- 'parent': {
- 'id': product_template.id,
- 'name': product_template.name,
- 'image': self.env['ir.attachment'].api_image('product.template', 'image_256', product_template.id),
- },
- 'code': product_product.default_code or '',
- 'name': product_product.display_name,
- 'price': {
- 'price': product_product._get_website_price_exclude_tax(),
- 'discount_percentage': discount_percentage,
- 'price_discount': price_discount
- },
- 'stock': stock,
- 'weight': product_product.weight,
- 'attributes': [x.name for x in product_product.product_template_attribute_value_ids],
- 'manufacture' : self.api_manufacture(product_product)
+ return {
+ 'price': self._get_website_price_exclude_tax(),
+ 'discount_percentage': discount_percentage,
+ 'price_discount': price_discount
}
- return data
def api_manufacture(self, product_template):
if product_template.x_manufacture:
diff --git a/indoteknik_api/models/product_template.py b/indoteknik_api/models/product_template.py
index 1a345967..68ab79c2 100644
--- a/indoteknik_api/models/product_template.py
+++ b/indoteknik_api/models/product_template.py
@@ -51,9 +51,7 @@ class ProductTemplate(models.Model):
data.update(data_with_detail)
return data
- def v2_api_single_response(self, product_template, pricelist=False, 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)
+ def v2_api_single_response(self, product_template, with_detail=''):
data = {
'id': product_template.id,
'image': self.env['ir.attachment'].api_image('product.template', 'image_128', product_template.id),
@@ -67,7 +65,7 @@ class ProductTemplate(models.Model):
}
if with_detail != '':
- variants = [self.env['product.product'].v2_api_single_response(variant, pricelist=pricelist) for variant in product_template.product_variant_ids]
+ variants = [self.env['product.product'].v2_api_single_response(variant) for variant in product_template.product_variant_ids]
lowest_price = variants[0]['price']
for variant in variants:
if variant["price"]["price_discount"] < lowest_price["price_discount"]: