diff options
| author | stephanchrst <stephanchrst@gmail.com> | 2023-03-24 15:48:24 +0700 |
|---|---|---|
| committer | stephanchrst <stephanchrst@gmail.com> | 2023-03-24 15:48:24 +0700 |
| commit | a9fd6502729bbd337c0ba762d2cc88fcd8f60900 (patch) | |
| tree | 21cf933c6d1c4a810a10bbc34a3f58eaf950335e /indoteknik_api/models | |
| parent | 3aa64db9c10d0fcb8009e9e6f942672a12669099 (diff) | |
rest api for website pricelist
Diffstat (limited to 'indoteknik_api/models')
| -rw-r--r-- | indoteknik_api/models/product_product.py | 66 |
1 files changed, 65 insertions, 1 deletions
diff --git a/indoteknik_api/models/product_product.py b/indoteknik_api/models/product_product.py index 2e84b9f4..f83ede27 100644 --- a/indoteknik_api/models/product_product.py +++ b/indoteknik_api/models/product_product.py @@ -1,4 +1,5 @@ from odoo import models +import math class ProductProduct(models.Model): @@ -34,4 +35,67 @@ class ProductProduct(models.Model): 'image_promotion_1': self.env['ir.attachment'].api_image('x_manufactures', 'image_promotion_1', manufacture.id), 'image_promotion_2': self.env['ir.attachment'].api_image('x_manufactures', 'image_promotion_2', manufacture.id), } - return {}
\ No newline at end of file + return {} + + def _get_website_price_include_tax(self): + default_pricelist_id = int(1) + + query = [ + ('pricelist_id.id', '=', default_pricelist_id), + ('product_id.id', '=', self.id) + ] + pl_item1 = self.env['product.pricelist.item'].search(query, limit=1) + + retValue = pl_item1.fixed_price + retValue = math.floor(retValue) + return retValue + + def _get_website_price_exclude_tax(self): + default_divide_tax = float(1.11) + price_incl = self._get_website_price_include_tax() + res = price_incl / default_divide_tax + return math.floor(res) + + def _get_website_disc(self, partner_id): + default_discount_id = int(4) + + # compile partner + partner = self.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_discount_id), + ('product_id.id', '=', self.id) + ] + + pl_item2 = self.env['product.pricelist.item'].search(query, limit=1) + + retValue = pl_item2.price_discount + return retValue + + def _get_website_price_after_disc_and_tax(self): + default_divide_tax = float(1.11) + price_after_disc = self._get_website_price_after_disc() + res = price_after_disc / default_divide_tax + res = math.floor(res) + return res + + def _get_website_price_after_disc(self): + discount = self._get_website_disc(0) + price_incl = self._get_website_price_include_tax() + res = 0 + if discount > 0: + res = price_incl - (price_incl * discount / 100) + else: + res = price_incl + return math.floor(res) + + def _get_website_tax(self): + default_percent_tax = float(11) + price_after_disc = self._get_website_price_after_disc_and_tax() + res = price_after_disc * default_percent_tax / 100 + return math.floor(res) |
