Add module product_category_tax
This commit is contained in:
30
product_category_tax/README.rst
Normal file
30
product_category_tax/README.rst
Normal file
@@ -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 <alexis.delattre@akretion.com>
|
||||
|
||||
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.
|
||||
23
product_category_tax/__init__.py
Normal file
23
product_category_tax/__init__.py
Normal file
@@ -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 <alexis.delattre@akretion.com>
|
||||
#
|
||||
# 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 <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
from . import product
|
||||
37
product_category_tax/__openerp__.py
Normal file
37
product_category_tax/__openerp__.py
Normal file
@@ -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 <alexis.delattre@akretion.com>
|
||||
#
|
||||
# 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 <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
|
||||
{
|
||||
'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,
|
||||
}
|
||||
80
product_category_tax/product.py
Normal file
80
product_category_tax/product.py
Normal file
@@ -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 <alexis.delattre@akretion.com>
|
||||
#
|
||||
# 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 <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
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'])])
|
||||
25
product_category_tax/product_view.xml
Normal file
25
product_category_tax/product_view.xml
Normal file
@@ -0,0 +1,25 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<!--
|
||||
Copyright (C) 2015 Akretion (http://www.akretion.com/)
|
||||
@author Alexis de Lattre <alexis.delattre@akretion.com>
|
||||
The licence is in the file __openerp__.py
|
||||
-->
|
||||
|
||||
<openerp>
|
||||
<data>
|
||||
|
||||
<record id="view_category_property_form" model="ir.ui.view">
|
||||
<field name="name">product_category_tax.product.categ.form</field>
|
||||
<field name="model">product.category</field>
|
||||
<field name="inherit_id" ref="account.view_category_property_form" />
|
||||
<field name="arch" type="xml">
|
||||
<group name="account_property" position="inside">
|
||||
<field name="sale_tax_ids" widget="many2many_tags"/>
|
||||
<field name="purchase_tax_ids" widget="many2many_tags"/>
|
||||
</group>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
</data>
|
||||
</openerp>
|
||||
Reference in New Issue
Block a user