From e6761de3678830882174844bd10dc45a0095461f Mon Sep 17 00:00:00 2001 From: Alexis de Lattre Date: Thu, 5 Mar 2015 08:26:09 +0100 Subject: [PATCH] Add module product_category_tax --- product_category_tax/README.rst | 30 ++++++++++ product_category_tax/__init__.py | 23 ++++++++ product_category_tax/__openerp__.py | 37 +++++++++++++ product_category_tax/product.py | 80 +++++++++++++++++++++++++++ product_category_tax/product_view.xml | 25 +++++++++ 5 files changed, 195 insertions(+) create mode 100644 product_category_tax/README.rst create mode 100644 product_category_tax/__init__.py create mode 100644 product_category_tax/__openerp__.py create mode 100644 product_category_tax/product.py create mode 100644 product_category_tax/product_view.xml diff --git a/product_category_tax/README.rst b/product_category_tax/README.rst new file mode 100644 index 0000000..1441b91 --- /dev/null +++ b/product_category_tax/README.rst @@ -0,0 +1,30 @@ +Product Category Tax +==================== + +This module will allow you to configure sale and purchase taxes on product categories. When you set the product category of a product, the taxes configured on the product category will be copied to the product. It also adds a constraint on products that checks that the taxes configured on the product are the same as the taxes configured on it's related product category. + +Configuration +============= + +Set the taxes on the product categories via the menu *Sales > Configuration > Product Categories > Product Categories*. + +Credits +======= + +Contributors +------------ + +* Alexis de Lattre + +Maintainer +---------- + +.. image:: http://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: http://odoo-community.org + +This module is maintained by the OCA. + +OCA, or the Odoo Community Association, is a nonprofit organization whose mission is to support the collaborative development of Odoo features and promote its widespread use. + +To contribute to this module, please visit http://odoo-community.org. diff --git a/product_category_tax/__init__.py b/product_category_tax/__init__.py new file mode 100644 index 0000000..d18a596 --- /dev/null +++ b/product_category_tax/__init__.py @@ -0,0 +1,23 @@ +# -*- encoding: utf-8 -*- +############################################################################## +# +# Product Category Tax module for Odoo +# Copyright (C) 2015 Akretion (http://www.akretion.com) +# @author Alexis de Lattre +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## + +from . import product diff --git a/product_category_tax/__openerp__.py b/product_category_tax/__openerp__.py new file mode 100644 index 0000000..a7cfbc0 --- /dev/null +++ b/product_category_tax/__openerp__.py @@ -0,0 +1,37 @@ +# -*- encoding: utf-8 -*- +############################################################################## +# +# Product Category Tax module for Odoo +# Copyright (C) 2015 Akretion (http://www.akretion.com) +# @author Alexis de Lattre +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## + + +{ + 'name': 'Product Category Tax', + 'version': '0.1', + 'category': 'Accounting & Finance', + 'license': 'AGPL-3', + 'summary': 'Adds sale and purchase taxes on product category', + 'description': "", + 'author': 'Akretion', + 'website': 'http://www.akretion.com', + 'depends': ['account'], + 'data': ['product_view.xml'], + 'demo': [], + 'installable': True, +} diff --git a/product_category_tax/product.py b/product_category_tax/product.py new file mode 100644 index 0000000..d26f29d --- /dev/null +++ b/product_category_tax/product.py @@ -0,0 +1,80 @@ +# -*- encoding: utf-8 -*- +############################################################################## +# +# Product Category Tax module for Odoo +# Copyright (C) 2015 Akretion (http://www.akretion.com) +# @author Alexis de Lattre +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## + +from openerp import models, fields, api, _ +from openerp.exceptions import ValidationError + + +class ProductTemplate(models.Model): + _inherit = 'product.template' + + @api.onchange('categ_id') + def onchange_categ_id(self): + if self.categ_id: + self.taxes_id = self.categ_id.sale_tax_ids.ids + self.supplier_taxes_id = self.categ_id.purchase_tax_ids.ids + + @api.one + @api.constrains('taxes_id', 'supplier_taxes_id') + def _check_tax_categ(self): + if self.categ_id: + if self.categ_id.sale_tax_ids.ids != self.taxes_id.ids: + raise ValidationError( + _("The sale taxes configured on the product '%s' " + "are not the same as the sale taxes configured " + "on it's related product category '%s'.") + % (self.name, self.categ_id.complete_name)) + if ( + self.categ_id.purchase_tax_ids.ids != + self.supplier_taxes_id.ids): + raise ValidationError( + _("The purchase taxes configured on the product '%s' " + "are not the same as the purchase taxes configured " + "on it's related product category '%s'.") + % (self.name, self.categ_id.complete_name)) + + +class ProductProduct(models.Model): + _inherit = 'product.product' + + @api.onchange('categ_id') + def onchange_categ_id(self): + if self.categ_id: + self.taxes_id = self.categ_id.sale_tax_ids.ids + self.supplier_taxes_id = self.categ_id.purchase_tax_ids.ids + + +class ProductCategory(models.Model): + _inherit = 'product.category' + + sale_tax_ids = fields.Many2many( + 'account.tax', 'product_categ_sale_tax_rel', 'categ_id', 'tax_id', + string="Sale Taxes", + domain=[ + ('parent_id', '=', False), + ('type_tax_use', 'in', ['sale', 'all'])]) + purchase_tax_ids = fields.Many2many( + 'account.tax', 'product_categ_purchase_tax_rel', 'categ_id', 'tax_id', + string="Purchase Taxes", + domain=[ + ('parent_id', '=', False), + ('type_tax_use', 'in', ['purchase', 'all'])]) diff --git a/product_category_tax/product_view.xml b/product_category_tax/product_view.xml new file mode 100644 index 0000000..c222fe6 --- /dev/null +++ b/product_category_tax/product_view.xml @@ -0,0 +1,25 @@ + + + + + + + + + product_category_tax.product.categ.form + product.category + + + + + + + + + + +