summaryrefslogtreecommitdiff
path: root/indoteknik_api/models
diff options
context:
space:
mode:
authorRafi Zadanly <zadanlyr@gmail.com>2023-04-18 15:45:05 +0700
committerRafi Zadanly <zadanlyr@gmail.com>2023-04-18 15:45:05 +0700
commit60d754cb1b2044adafddd4893212028a3264f620 (patch)
tree4b034580ffe571245c3b7b51810a50952b70d53d /indoteknik_api/models
parent456d4b07e52c3664fd2c22e2b7748cbb2912539d (diff)
price tier on user session, variant and product
Diffstat (limited to 'indoteknik_api/models')
-rw-r--r--indoteknik_api/models/product_product.py34
-rw-r--r--indoteknik_api/models/product_template.py4
-rw-r--r--indoteknik_api/models/res_users.py17
3 files changed, 47 insertions, 8 deletions
diff --git a/indoteknik_api/models/product_product.py b/indoteknik_api/models/product_product.py
index 9c59040f..a648ad51 100644
--- a/indoteknik_api/models/product_product.py
+++ b/indoteknik_api/models/product_product.py
@@ -1,4 +1,5 @@
from odoo import models
+from odoo.http import request
import math
@@ -26,9 +27,32 @@ class ProductProduct(models.Model):
}
return data
- def v2_api_single_response(self, product_product):
- 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_product, pricelist=False):
+ 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()
+
+ price_tier = False
+ pricelists = {
+ 'tier1': product_product._get_pricelist_tier1,
+ 'tier2': product_product._get_pricelist_tier2,
+ 'tier3': product_product._get_pricelist_tier3,
+ }
+ if pricelist.id == product_pricelist_tier1: price_tier = 'tier1'
+ if pricelist.id == product_pricelist_tier2: price_tier = 'tier2'
+ if pricelist.id == product_pricelist_tier3: price_tier = 'tier3'
+
+ if price_tier:
+ price = pricelists[price_tier]()
+ discount_key = 'discount_%s' % price_tier
+ price_key = 'price_%s' % price_tier
+ if price[discount_key] > 0: discount_percentage = price[discount_key]
+ if price[price_key] > 0: price_discount = price[price_key]
+
product_template = product_product.product_tmpl_id
data = {
'id': product_product.id,
@@ -41,8 +65,8 @@ class ProductProduct(models.Model):
'name': product_product.display_name,
'price': {
'price': product_product._get_website_price_exclude_tax(),
- 'discount_percentage': product_product._get_website_disc(0),
- 'price_discount': product_product._get_website_price_after_disc_and_tax()
+ 'discount_percentage': discount_percentage,
+ 'price_discount': price_discount
},
'stock': product_product.qty_stock_vendor,
'weight': product_product.weight,
diff --git a/indoteknik_api/models/product_template.py b/indoteknik_api/models/product_template.py
index 4d16727f..b9df0f5f 100644
--- a/indoteknik_api/models/product_template.py
+++ b/indoteknik_api/models/product_template.py
@@ -51,7 +51,7 @@ class ProductTemplate(models.Model):
data.update(data_with_detail)
return data
- def v2_api_single_response(self, product_template, with_detail=''):
+ 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)
data = {
@@ -71,7 +71,7 @@ class ProductTemplate(models.Model):
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],
+ 'variants': [self.env['product.product'].v2_api_single_response(variant, pricelist=pricelist) for variant in product_template.product_variant_ids],
'description': product_template.website_description or '',
}
data.update(data_with_detail)
diff --git a/indoteknik_api/models/res_users.py b/indoteknik_api/models/res_users.py
index 5032f3af..b0807e9f 100644
--- a/indoteknik_api/models/res_users.py
+++ b/indoteknik_api/models/res_users.py
@@ -5,6 +5,12 @@ class ResUsers(models.Model):
_inherit = 'res.users'
def api_single_response(self, res_user, with_detail=''):
+ 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'))
+
+ user_pricelist = res_user.property_product_pricelist
data = {
'id': res_user.id,
'parent_id': res_user.parent_id.id or False,
@@ -14,8 +20,17 @@ class ResUsers(models.Model):
'phone': res_user.phone or '',
'mobile': res_user.mobile or '',
'external': res_user.share,
- 'company': res_user.company_type == 'company'
+ 'company': res_user.company_type == 'company',
+ 'pricelist': False
}
+
+ if user_pricelist.id == product_pricelist_tier1:
+ data['pricelist'] = 'tier1'
+ if user_pricelist.id == product_pricelist_tier2:
+ data['pricelist'] = 'tier2'
+ if user_pricelist.id == product_pricelist_tier3:
+ data['pricelist'] = 'tier3'
+
if res_user.parent_id:
data.update({ 'company': res_user.parent_id.company_type == 'company' })