summaryrefslogtreecommitdiff
path: root/indoteknik_api/controllers/api_v1
diff options
context:
space:
mode:
authorstephanchrst <stephanchrst@gmail.com>2023-03-24 16:04:54 +0700
committerstephanchrst <stephanchrst@gmail.com>2023-03-24 16:04:54 +0700
commit567da97c5ed74db8e06d2bf846479d14fdc34c13 (patch)
tree010ed60289cd81c35d248cbdb140c4708d3048fc /indoteknik_api/controllers/api_v1
parent8787033026f974b0664e8fe24c87f1db480f7959 (diff)
add missing api product product price
Diffstat (limited to 'indoteknik_api/controllers/api_v1')
-rw-r--r--indoteknik_api/controllers/api_v1/product.py86
1 files changed, 17 insertions, 69 deletions
diff --git a/indoteknik_api/controllers/api_v1/product.py b/indoteknik_api/controllers/api_v1/product.py
index 22030eab..b8a44f5b 100644
--- a/indoteknik_api/controllers/api_v1/product.py
+++ b/indoteknik_api/controllers/api_v1/product.py
@@ -20,7 +20,6 @@ class Product(controller.Controller):
partner_id = int(kw.get('partner_id', 0))
product_template = request.env['product.template'].search([('id', '=', id)], limit=1)
- data = self.get_product_price_for_website(product_template.product_variant_id.id, partner_id)
data = {
'price_include': product_template.product_variant_id._get_website_price_include_tax(),
'price_exclude': product_template.product_variant_id._get_website_price_exclude_tax(),
@@ -50,76 +49,25 @@ class Product(controller.Controller):
data.update(start_from)
return self.response(data)
+
+ @http.route(prefix + 'product/product/price/<id>', auth='public', methods=['GET'])
+ def get_product_product_price_by_id(self, **kw):
+ if not self.authenticate():
+ return self.response(code=401, description='Unauthorized')
+ id = kw.get('id')
+ partner_id = int(kw.get('partner_id', 0))
+ product_product = request.env['product.product'].search([('id', '=', id)], limit=1)
- def get_product_price_for_website(self, product_id, partner_id=0):
- # default_pricelist_id = request.env['ir.config_parameter'].get_param('product.pricelist.default_price_id')
- # default_discount_id = request.env['ir.config.parameter'].get_param('product.pricelist.default_discount_id')
- # default_divide_tax = request.env['ir.config.parameter'].get_param('product.pricelist.default_divide_tax')
- default_pricelist_id = int(1)
- default_discount_id = int(4)
- default_divide_tax = float(1.11)
-
- # compile partner
- partner = request.env['res.partner'].search([('id', '=', partner_id)], limit=1)
-
- if partner:
- if not partner.parent_id: # it means this is a parent
- default_discount_id = partner.custom_pricelist_id
- else: # it means this is NOT parent
- default_discount_id = partner.parent_id.custom_pricelist_id
-
- query = [
- ('pricelist_id.id', '=', default_pricelist_id),
- ('product_id.id', '=', product_id)
- ]
- pl_item1 = request.env['product.pricelist.item'].search(query, limit=1)
- query = [
- ('pricelist_id.id', '=', default_discount_id),
- ('product_id.id', '=', product_id)
- ]
- pl_item2 = request.env['product.pricelist.item'].search(query, limit=1)
-
- price_coret = float(pl_item1.fixed_price)
- price_include = math.floor(price_coret)
- discount = float(pl_item2.price_discount)
-
- data = []
- if price_coret > 0 and discount > 0:
- price_coret = price_coret / default_divide_tax
- price_coret = math.floor(price_coret)
- price_discount = price_coret - (price_coret * discount / 100)
- price_discount = math.floor(price_discount)
- ppn = price_discount * 11/100
- ppn = math.floor(ppn)
-
- data = {
- 'price_include': price_include,
- 'price': price_coret,
- 'discount': discount,
- 'price_discount': price_discount,
- 'ppn': ppn
- }
- elif price_coret > 0:
- price_coret = price_coret / default_divide_tax
- price_coret = math.floor(price_coret)
- ppn = price_coret * 11/100
- ppn = math.floor(ppn)
- data = {
- 'price_include': price_include,
- 'price': price_coret,
- 'discount': 0,
- 'price_discount': price_coret,
- 'ppn': ppn
- }
- else:
- data = {
- 'price': 0,
- 'discount': 0,
- 'price_discount': 0,
- 'ppn': 0
- }
- return data
+ data = {
+ 'price_include': product_product._get_website_price_include_tax(),
+ 'price_exclude': product_product._get_website_price_exclude_tax(),
+ 'discount': product_product._get_website_disc(partner_id),
+ 'price_include_after_discount': product_product._get_website_price_after_disc(),
+ 'price_exclude_after_discount': product_product._get_website_price_after_disc_and_tax(),
+ 'tax': product_product._get_website_tax()
+ }
+ return self.response(data)
@http.route(prefix + 'new_product', auth='public', methods=['GET', 'OPTIONS'])
def get_new_product(self, **kw):