From cef81ad749a6ff0dc76c830c85a785c4a3554dc0 Mon Sep 17 00:00:00 2001 From: Alexis de Lattre Date: Thu, 18 Feb 2021 09:48:17 +0100 Subject: [PATCH] Add Tax include / tax exclude next the prices on product form view --- account_usability/__manifest__.py | 1 + account_usability/models/product.py | 45 ++++++++++++++++++ account_usability/views/product.xml | 73 +++++++++++++++++++++++++++++ 3 files changed, 119 insertions(+) create mode 100644 account_usability/models/product.py create mode 100644 account_usability/views/product.xml diff --git a/account_usability/__manifest__.py b/account_usability/__manifest__.py index 27332e5..fed8cc9 100644 --- a/account_usability/__manifest__.py +++ b/account_usability/__manifest__.py @@ -25,6 +25,7 @@ 'views/account_move.xml', 'views/account_menu.xml', 'views/account_tax.xml', + 'views/product.xml', 'views/res_config_settings.xml', 'views/res_partner.xml', 'views/account_report.xml', diff --git a/account_usability/models/product.py b/account_usability/models/product.py new file mode 100644 index 0000000..2e4070d --- /dev/null +++ b/account_usability/models/product.py @@ -0,0 +1,45 @@ +# Copyright 2015-2021 Akretion (http://www.akretion.com) +# @author Alexis de Lattre +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import api, fields, models, _ + + +class ProductTemplate(models.Model): + _inherit = 'product.template' + + # DON'T put store=True on those fields, because they are company dependent + sale_price_type = fields.Selection( + '_sale_purchase_price_type_sel', compute='_compute_sale_price_type', + string='Sale Price Type', compute_sudo=False, readonly=True) + purchase_price_type = fields.Selection( + '_sale_purchase_price_type_sel', compute='_compute_purchase_price_type', + string='Purchase Price Type', compute_sudo=False, readonly=True) + + @api.model + def _sale_purchase_price_type_sel(self): + return [('incl', _('Tax incl.')), ('excl', _('Tax excl.'))] + + @api.depends('taxes_id') + def _compute_sale_price_type(self): + for pt in self: + sale_price_type = 'incl' + if pt.taxes_id and all([not t.price_include for t in pt.taxes_id if t.amount_type == 'percent']): + sale_price_type = 'excl' + pt.sale_price_type = sale_price_type + + @api.depends('supplier_taxes_id') + def _compute_purchase_price_type(self): + for pt in self: + purchase_price_type = 'incl' + if pt.supplier_taxes_id and all([not t.price_include for t in pt.supplier_taxes_id if t.amount_type == 'percent']): + purchase_price_type = 'excl' + pt.purchase_price_type = purchase_price_type + + +class ProductSupplierinfo(models.Model): + _inherit = 'product.supplierinfo' + + # DON'T put store=True on those fields, because they are company dependent + purchase_price_type = fields.Selection( + related='product_tmpl_id.purchase_price_type', related_sudo=False) diff --git a/account_usability/views/product.xml b/account_usability/views/product.xml new file mode 100644 index 0000000..5519141 --- /dev/null +++ b/account_usability/views/product.xml @@ -0,0 +1,73 @@ + + + + + + + + + account_usability.product.template.form + product.template + 100 + + + + account.group_account_invoice + + + account.group_account_invoice + + + + + + + + account_usability.product.category.form + product.category + + + + account.group_account_invoice + + + + + + account_usability.product.supplierinfo.form + product.supplierinfo + + + + + + + + + + account_usability.product.supplierinfo.tree + product.supplierinfo + + + + + + + + + +