diff options
| author | Rafi Zadanly <zadanlyr@gmail.com> | 2023-03-24 16:06:36 +0700 |
|---|---|---|
| committer | Rafi Zadanly <zadanlyr@gmail.com> | 2023-03-24 16:06:36 +0700 |
| commit | 4ab719732e495ad2eb42ee8ea1c63dc875b98f1d (patch) | |
| tree | 8a847db61dc11ce0a9fa5f3411a26fefa7bee034 | |
| parent | d7838ad087daf51826d3be27888df04eac09a293 (diff) | |
| parent | 567da97c5ed74db8e06d2bf846479d14fdc34c13 (diff) | |
Merge branch 'release' of bitbucket.org:altafixco/indoteknik-addons into release
| -rw-r--r-- | indoteknik_api/controllers/api_v1/product.py | 58 | ||||
| -rw-r--r-- | indoteknik_api/models/product_product.py | 66 | ||||
| -rw-r--r-- | indoteknik_custom/models/res_partner.py | 1 | ||||
| -rw-r--r-- | indoteknik_custom/views/stock_picking.xml | 2 |
4 files changed, 125 insertions, 2 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): 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) diff --git a/indoteknik_custom/models/res_partner.py b/indoteknik_custom/models/res_partner.py index 1cdf7c72..ad88957f 100644 --- a/indoteknik_custom/models/res_partner.py +++ b/indoteknik_custom/models/res_partner.py @@ -6,3 +6,4 @@ class ResPartner(models.Model): reference_number = fields.Char(string="Reference Number") company_type_id = fields.Many2one('res.partner.company_type', string='Company Type') + custom_pricelist_id = fields.Many2one('product.pricelist', string='Price Matrix') diff --git a/indoteknik_custom/views/stock_picking.xml b/indoteknik_custom/views/stock_picking.xml index 0ff79ea8..e4e9f722 100644 --- a/indoteknik_custom/views/stock_picking.xml +++ b/indoteknik_custom/views/stock_picking.xml @@ -34,7 +34,7 @@ <button name="action_create_invoice_from_mr" string="Create Bill" type="object" - attrs="{'invisible': [('state', '!=', 'done')]}" + attrs="{'invisible': ['|', ('state', '!=', 'done'), ('name', 'ilike', 'out')]}" /> </button> <field name="backorder_id" position="after"> |
