Port product_category_tax to v10
This commit is contained in:
@@ -1,3 +1,8 @@
|
|||||||
|
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg
|
||||||
|
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
|
||||||
|
:alt: License: AGPL-3
|
||||||
|
|
||||||
|
====================
|
||||||
Product Category Tax
|
Product Category Tax
|
||||||
====================
|
====================
|
||||||
|
|
||||||
@@ -6,7 +11,7 @@ This module will allow you to configure sale and purchase taxes on product categ
|
|||||||
Configuration
|
Configuration
|
||||||
=============
|
=============
|
||||||
|
|
||||||
Set the taxes on the product categories via the menu *Sales > Configuration > Product Categories > Product Categories*.
|
Set the taxes on the product categories via the menu *Sales > Configuration > Products > Product Categories*.
|
||||||
|
|
||||||
Credits
|
Credits
|
||||||
=======
|
=======
|
||||||
@@ -15,16 +20,3 @@ Contributors
|
|||||||
------------
|
------------
|
||||||
|
|
||||||
* Alexis de Lattre <alexis.delattre@akretion.com>
|
* 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.
|
|
||||||
|
|||||||
@@ -1,23 +1,3 @@
|
|||||||
# -*- encoding: utf-8 -*-
|
# -*- coding: 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
|
from . import product
|
||||||
|
|||||||
@@ -1,29 +1,11 @@
|
|||||||
# -*- encoding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
##############################################################################
|
# © 2015-2016 Akretion (http://www.akretion.com)
|
||||||
#
|
# @author Alexis de Lattre <alexis.delattre@akretion.com>
|
||||||
# Product Category Tax module for Odoo
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||||
# 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',
|
'name': 'Product Category Tax',
|
||||||
'version': '0.1',
|
'version': '10.0.1.0.0',
|
||||||
'category': 'Accounting & Finance',
|
'category': 'Accounting & Finance',
|
||||||
'license': 'AGPL-3',
|
'license': 'AGPL-3',
|
||||||
'summary': 'Adds sale and purchase taxes on product category',
|
'summary': 'Adds sale and purchase taxes on product category',
|
||||||
@@ -32,6 +14,5 @@
|
|||||||
'website': 'http://www.akretion.com',
|
'website': 'http://www.akretion.com',
|
||||||
'depends': ['account'],
|
'depends': ['account'],
|
||||||
'data': ['product_view.xml'],
|
'data': ['product_view.xml'],
|
||||||
'demo': [],
|
'installable': True,
|
||||||
'installable': False,
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,27 +1,10 @@
|
|||||||
# -*- encoding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
##############################################################################
|
# © 2015-2016 Akretion (http://www.akretion.com)
|
||||||
#
|
# @author Alexis de Lattre <alexis.delattre@akretion.com>
|
||||||
# Product Category Tax module for Odoo
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||||
# 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 odoo import models, fields, api, _
|
||||||
from openerp.exceptions import ValidationError
|
from odoo.exceptions import ValidationError
|
||||||
|
|
||||||
|
|
||||||
class ProductCategTaxMixin(models.AbstractModel):
|
class ProductCategTaxMixin(models.AbstractModel):
|
||||||
@@ -34,23 +17,22 @@ class ProductCategTaxMixin(models.AbstractModel):
|
|||||||
self.apply_tax_from_category(self.categ_id))
|
self.apply_tax_from_category(self.categ_id))
|
||||||
|
|
||||||
@api.model
|
@api.model
|
||||||
def apply_tax_from_category(self, categ_id):
|
def apply_tax_from_category(self, categ):
|
||||||
# self.ensure_one()
|
# I cannot use the commented line below:
|
||||||
# I cannot use the commented line below:
|
|
||||||
# self.taxes_id = self.categ_id.sale_tax_ids.ids
|
# self.taxes_id = self.categ_id.sale_tax_ids.ids
|
||||||
# because it ADDS the taxes (equivalent of (4, ID)) instead
|
# because it ADDS the taxes (equivalent of (4, ID)) instead
|
||||||
# of replacing the taxes... and I want to REPLACE the taxes
|
# of replacing the taxes... and I want to REPLACE the taxes
|
||||||
# So I have to use the awful syntax (6, 0, [IDs])
|
# So I have to use the awful syntax (6, 0, [IDs])
|
||||||
# values are sent to ('taxes_id' and 'supplier_taxes_id')
|
# values are sent to ('taxes_id' and 'supplier_taxes_id')
|
||||||
return ([(6, 0, categ_id.sale_tax_ids.ids)],
|
return ([(6, 0, categ.sale_tax_ids.ids)],
|
||||||
[(6, 0, categ_id.purchase_tax_ids.ids)])
|
[(6, 0, categ.purchase_tax_ids.ids)])
|
||||||
|
|
||||||
@api.model
|
@api.model
|
||||||
def write_or_create(self, vals):
|
def write_or_create(self, vals):
|
||||||
if vals.get('categ_id'):
|
if vals.get('categ_id'):
|
||||||
vals['taxes_id'], vals['supplier_taxes_id'] = (
|
categ = self.env['product.category'].browse(vals['categ_id'])
|
||||||
self.apply_tax_from_category(
|
vals['taxes_id'], vals['supplier_taxes_id'] =\
|
||||||
self.categ_id.browse(vals['categ_id'])))
|
self.apply_tax_from_category(categ)
|
||||||
|
|
||||||
@api.model
|
@api.model
|
||||||
def create(self, vals):
|
def create(self, vals):
|
||||||
@@ -72,21 +54,21 @@ class ProductTemplate(models.Model):
|
|||||||
def _check_tax_categ(self):
|
def _check_tax_categ(self):
|
||||||
# self.name != 'Pay Debt' is a stupid hack to avoid blocking the
|
# self.name != 'Pay Debt' is a stupid hack to avoid blocking the
|
||||||
# installation of the module 'pos_debt_notebook'
|
# installation of the module 'pos_debt_notebook'
|
||||||
if self.categ_id and self.name != 'Pay Debt':
|
if self.categ_id: # and self.name != 'Pay Debt':
|
||||||
if self.categ_id.sale_tax_ids.ids != self.taxes_id.ids:
|
if self.categ_id.sale_tax_ids.ids != self.taxes_id.ids:
|
||||||
raise ValidationError(
|
raise ValidationError(_(
|
||||||
_("The sale taxes configured on the product '%s' "
|
"The sale taxes configured on the product '%s' "
|
||||||
"are not the same as the sale taxes configured "
|
"are not the same as the sale taxes configured "
|
||||||
"on it's related product category '%s'.")
|
"on it's related internal category '%s'.")
|
||||||
% (self.name, self.categ_id.complete_name))
|
% (self.name, self.categ_id.name_get()[0][1]))
|
||||||
if (
|
if (
|
||||||
self.categ_id.purchase_tax_ids.ids !=
|
self.categ_id.purchase_tax_ids.ids !=
|
||||||
self.supplier_taxes_id.ids):
|
self.supplier_taxes_id.ids):
|
||||||
raise ValidationError(
|
raise ValidationError(_(
|
||||||
_("The purchase taxes configured on the product '%s' "
|
"The purchase taxes configured on the product '%s' "
|
||||||
"are not the same as the purchase taxes configured "
|
"are not the same as the purchase taxes configured "
|
||||||
"on it's related product category '%s'.")
|
"on it's related internal category '%s'.")
|
||||||
% (self.name, self.categ_id.complete_name))
|
% (self.name, self.categ_id.name_get()[0][1]))
|
||||||
|
|
||||||
|
|
||||||
class ProductProduct(models.Model):
|
class ProductProduct(models.Model):
|
||||||
@@ -99,13 +81,7 @@ class ProductCategory(models.Model):
|
|||||||
|
|
||||||
sale_tax_ids = fields.Many2many(
|
sale_tax_ids = fields.Many2many(
|
||||||
'account.tax', 'product_categ_sale_tax_rel', 'categ_id', 'tax_id',
|
'account.tax', 'product_categ_sale_tax_rel', 'categ_id', 'tax_id',
|
||||||
string="Sale Taxes",
|
string="Sale Taxes", domain=[('type_tax_use', '=', 'sale')])
|
||||||
domain=[
|
|
||||||
('parent_id', '=', False),
|
|
||||||
('type_tax_use', 'in', ['sale', 'all'])])
|
|
||||||
purchase_tax_ids = fields.Many2many(
|
purchase_tax_ids = fields.Many2many(
|
||||||
'account.tax', 'product_categ_purchase_tax_rel', 'categ_id', 'tax_id',
|
'account.tax', 'product_categ_purchase_tax_rel', 'categ_id', 'tax_id',
|
||||||
string="Purchase Taxes",
|
string="Purchase Taxes", domain=[('type_tax_use', '=', 'purchase')])
|
||||||
domain=[
|
|
||||||
('parent_id', '=', False),
|
|
||||||
('type_tax_use', 'in', ['purchase', 'all'])])
|
|
||||||
|
|||||||
@@ -1,25 +1,22 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
|
||||||
<!--
|
<!--
|
||||||
Copyright (C) 2015 Akretion (http://www.akretion.com/)
|
© 2015-2016 Akretion (http://www.akretion.com/)
|
||||||
@author Alexis de Lattre <alexis.delattre@akretion.com>
|
@author Alexis de Lattre <alexis.delattre@akretion.com>
|
||||||
The licence is in the file __openerp__.py
|
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||||
-->
|
-->
|
||||||
|
|
||||||
<openerp>
|
<odoo>
|
||||||
<data>
|
|
||||||
|
|
||||||
<record id="view_category_property_form" model="ir.ui.view">
|
<record id="view_category_property_form" model="ir.ui.view">
|
||||||
<field name="name">product_category_tax.product.categ.form</field>
|
<field name="name">product_category_tax.product.categ.form</field>
|
||||||
<field name="model">product.category</field>
|
<field name="model">product.category</field>
|
||||||
<field name="inherit_id" ref="account.view_category_property_form" />
|
<field name="inherit_id" ref="account.view_category_property_form" />
|
||||||
<field name="arch" type="xml">
|
<field name="arch" type="xml">
|
||||||
<group name="account_property" position="inside">
|
<field name="property_account_expense_categ_id" position="after">
|
||||||
<field name="sale_tax_ids" widget="many2many_tags"/>
|
<field name="sale_tax_ids" widget="many2many_tags"/>
|
||||||
<field name="purchase_tax_ids" widget="many2many_tags"/>
|
<field name="purchase_tax_ids" widget="many2many_tags"/>
|
||||||
</group>
|
</field>
|
||||||
</field>
|
</field>
|
||||||
</record>
|
</record>
|
||||||
|
|
||||||
</data>
|
</odoo>
|
||||||
</openerp>
|
|
||||||
|
|||||||
Reference in New Issue
Block a user