summaryrefslogtreecommitdiff
path: root/indoteknik_api/controllers/api_v1
diff options
context:
space:
mode:
authorRafi Zadanly <zadanlyr@gmail.com>2023-03-24 16:06:36 +0700
committerRafi Zadanly <zadanlyr@gmail.com>2023-03-24 16:06:36 +0700
commit4ab719732e495ad2eb42ee8ea1c63dc875b98f1d (patch)
tree8a847db61dc11ce0a9fa5f3411a26fefa7bee034 /indoteknik_api/controllers/api_v1
parentd7838ad087daf51826d3be27888df04eac09a293 (diff)
parent567da97c5ed74db8e06d2bf846479d14fdc34c13 (diff)
Merge branch 'release' of bitbucket.org:altafixco/indoteknik-addons into release
Diffstat (limited to 'indoteknik_api/controllers/api_v1')
-rw-r--r--indoteknik_api/controllers/api_v1/product.py58
1 files changed, 58 insertions, 0 deletions
diff --git a/indoteknik_api/controllers/api_v1/product.py b/indoteknik_api/controllers/api_v1/product.py
index c9672223..6789a8f5 100644
--- a/indoteknik_api/controllers/api_v1/product.py
+++ b/indoteknik_api/controllers/api_v1/product.py
@@ -4,6 +4,7 @@ from odoo.http import request
from datetime import datetime, timedelta
import ast
import logging
+import math
_logger = logging.getLogger(__name__)
@@ -11,6 +12,63 @@ _logger = logging.getLogger(__name__)
class Product(controller.Controller):
prefix = '/api/v1/'
+ @http.route(prefix + 'product/template/price/<id>', auth='public', methods=['GET'])
+ def get_product_template_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_template = request.env['product.template'].search([('id', '=', id)], limit=1)
+
+ 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(),
+ 'discount': product_template.product_variant_id._get_website_disc(partner_id),
+ 'price_include_after_discount': product_template.product_variant_id._get_website_price_after_disc(),
+ 'price_exclude_after_discount': product_template.product_variant_id._get_website_price_after_disc_and_tax(),
+ 'tax': product_template.product_variant_id._get_website_tax(),
+ }
+
+ if product_template.product_variant_count > 1:
+ price_excl_after_disc = price_excl = 0
+ for variant in product_template.product_variant_ids:
+ if price_excl_after_disc == 0:
+ price_excl = variant._get_website_price_exclude_tax()
+ price_excl_after_disc = variant._get_website_price_after_disc_and_tax()
+ elif variant._get_website_price_after_disc_and_tax() < price_excl_after_disc:
+ price_excl_after_disc = variant._get_website_price_after_disc_and_tax()
+ price_excl = variant._get_website_price_exclude_tax()
+ else:
+ price_excl_after_disc = price_excl_after_disc
+ price_excl = price_excl
+
+ start_from = {
+ 'price_start_from': price_excl,
+ 'price_disc_start_from': price_excl_after_disc
+ }
+ 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)
+
+ 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'])
@controller.Controller.must_authorized()
def get_new_product(self, **kw):