summaryrefslogtreecommitdiff
path: root/indoteknik_api/models
diff options
context:
space:
mode:
authorstephanchrst <stephanchrst@gmail.com>2023-04-28 09:03:04 +0700
committerstephanchrst <stephanchrst@gmail.com>2023-04-28 09:03:04 +0700
commit57d55f545da0fc501a9828bb3ca2988f126b241a (patch)
tree75b98126546eea20b90ca777b2887b4813946871 /indoteknik_api/models
parent3592c254ca5baf4a0a769f500f9e28a9cbc272a7 (diff)
parent6fa5de951abc02884eb37cdc6786c0f3d141ccc5 (diff)
Merge branch 'staging' into release
Diffstat (limited to 'indoteknik_api/models')
-rw-r--r--indoteknik_api/models/product_product.py53
-rw-r--r--indoteknik_api/models/product_template.py4
-rw-r--r--indoteknik_api/models/res_users.py17
-rw-r--r--indoteknik_api/models/sale_order.py4
4 files changed, 66 insertions, 12 deletions
diff --git a/indoteknik_api/models/product_product.py b/indoteknik_api/models/product_product.py
index 32bd7c21..49ea7804 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,33 @@ 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,
+ }
+ pricelist_id = pricelist.id if pricelist else False
+ 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 +66,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,
@@ -134,9 +159,13 @@ class ProductProduct(models.Model):
return math.floor(res)
def _get_pricelist_tier1(self):
+ product_pricelist_tier1 = int(self.env['ir.config_parameter'].get_param('product.pricelist.tier1'))
default_divide_tax = float(1.11)
base_price = discount = price = 0
- pricelist_item = self.env['product.pricelist.item'].search([('pricelist_id', '=', 15037), ('product_id', '=', self.id)], limit=1)
+ pricelist_item = self.env['product.pricelist.item'].search([
+ ('pricelist_id', '=', product_pricelist_tier1),
+ ('product_id', '=', self.id)
+ ], limit=1)
if pricelist_item:
# base_price = self._get_website_price_exclude_tax()
base_price_incl = self._get_website_price_include_tax()
@@ -152,9 +181,13 @@ class ProductProduct(models.Model):
return data
def _get_pricelist_tier2(self):
+ product_pricelist_tier2 = int(self.env['ir.config_parameter'].get_param('product.pricelist.tier2'))
default_divide_tax = float(1.11)
base_price = discount = price = 0
- pricelist_item = self.env['product.pricelist.item'].search([('pricelist_id', '=', 15038), ('product_id', '=', self.id)], limit=1)
+ pricelist_item = self.env['product.pricelist.item'].search([
+ ('pricelist_id', '=', product_pricelist_tier2),
+ ('product_id', '=', self.id)
+ ], limit=1)
if pricelist_item:
# base_price = self._get_website_price_exclude_tax()
base_price_incl = self._get_website_price_include_tax()
@@ -170,9 +203,13 @@ class ProductProduct(models.Model):
return data
def _get_pricelist_tier3(self):
+ product_pricelist_tier3 = int(self.env['ir.config_parameter'].get_param('product.pricelist.tier3'))
default_divide_tax = float(1.11)
base_price = discount = price = 0
- pricelist_item = self.env['product.pricelist.item'].search([('pricelist_id', '=', 15039), ('product_id', '=', self.id)], limit=1)
+ pricelist_item = self.env['product.pricelist.item'].search([
+ ('pricelist_id', '=', product_pricelist_tier3),
+ ('product_id', '=', self.id)
+ ], limit=1)
if pricelist_item:
# base_price = self._get_website_price_exclude_tax()
base_price_incl = self._get_website_price_include_tax()
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 84edb2b1..80de083d 100644
--- a/indoteknik_api/models/res_users.py
+++ b/indoteknik_api/models/res_users.py
@@ -5,6 +5,18 @@ 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
+ user_pricelist_id = user_pricelist.id if user_pricelist else False
+ pricelist_tier = False
+ if user_pricelist_id == product_pricelist_tier1: pricelist_tier = 'tier1'
+ if user_pricelist_id == product_pricelist_tier2: pricelist_tier = 'tier2'
+ if user_pricelist_id == product_pricelist_tier3: pricelist_tier = 'tier3'
+
data = {
'id': res_user.id,
'parent_id': res_user.parent_id.id or False,
@@ -14,8 +26,11 @@ 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': pricelist_tier
}
+
+
if res_user.parent_id:
data.update({ 'company': res_user.parent_id.company_type == 'company' })
diff --git a/indoteknik_api/models/sale_order.py b/indoteknik_api/models/sale_order.py
index 76532d20..21ee9396 100644
--- a/indoteknik_api/models/sale_order.py
+++ b/indoteknik_api/models/sale_order.py
@@ -10,6 +10,7 @@ class SaleOrder(models.Model):
'id': sale_order.id,
'name': sale_order.name,
'sales': sale_order.user_id.name,
+ 'amount_untaxed': sale_order.amount_untaxed,
'amount_tax': sale_order.amount_tax,
'amount_total': sale_order.amount_total,
'purchase_order_name': sale_order.partner_purchase_order_name,
@@ -60,7 +61,8 @@ class SaleOrder(models.Model):
product['price'] = {
'price': line.price_unit,
'discount_percentage': line.discount,
- 'price_discount': line.price_unit - (line.price_unit * (line.discount/100))
+ 'price_discount': line.price_reduce_taxexcl,
+ 'subtotal': line.price_subtotal
}
product['quantity'] = line.product_uom_qty
data_with_detail['products'].append(product)