Port product_category_tax to v10

This commit is contained in:
Alexis de Lattre
2016-12-07 10:08:37 +01:00
parent eb91ae6a48
commit 40dc5485a9
5 changed files with 46 additions and 120 deletions

View File

@@ -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
====================
@@ -6,7 +11,7 @@ This module will allow you to configure sale and purchase taxes on product categ
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
=======
@@ -15,16 +20,3 @@ 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.

View File

@@ -1,23 +1,3 @@
# -*- 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/>.
#
##############################################################################
# -*- coding: utf-8 -*-
from . import product

View File

@@ -1,29 +1,11 @@
# -*- 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/>.
#
##############################################################################
# -*- coding: utf-8 -*-
# © 2015-2016 Akretion (http://www.akretion.com)
# @author Alexis de Lattre <alexis.delattre@akretion.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
{
'name': 'Product Category Tax',
'version': '0.1',
'version': '10.0.1.0.0',
'category': 'Accounting & Finance',
'license': 'AGPL-3',
'summary': 'Adds sale and purchase taxes on product category',
@@ -32,6 +14,5 @@
'website': 'http://www.akretion.com',
'depends': ['account'],
'data': ['product_view.xml'],
'demo': [],
'installable': False,
'installable': True,
}

View File

@@ -1,27 +1,10 @@
# -*- 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/>.
#
##############################################################################
# -*- coding: utf-8 -*-
# © 2015-2016 Akretion (http://www.akretion.com)
# @author Alexis de Lattre <alexis.delattre@akretion.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from openerp import models, fields, api, _
from openerp.exceptions import ValidationError
from odoo import models, fields, api, _
from odoo.exceptions import ValidationError
class ProductCategTaxMixin(models.AbstractModel):
@@ -34,23 +17,22 @@ class ProductCategTaxMixin(models.AbstractModel):
self.apply_tax_from_category(self.categ_id))
@api.model
def apply_tax_from_category(self, categ_id):
# self.ensure_one()
# I cannot use the commented line below:
def apply_tax_from_category(self, categ):
# I cannot use the commented line below:
# self.taxes_id = self.categ_id.sale_tax_ids.ids
# because it ADDS the taxes (equivalent of (4, ID)) instead
# of replacing the taxes... and I want to REPLACE the taxes
# So I have to use the awful syntax (6, 0, [IDs])
# values are sent to ('taxes_id' and 'supplier_taxes_id')
return ([(6, 0, categ_id.sale_tax_ids.ids)],
[(6, 0, categ_id.purchase_tax_ids.ids)])
return ([(6, 0, categ.sale_tax_ids.ids)],
[(6, 0, categ.purchase_tax_ids.ids)])
@api.model
def write_or_create(self, vals):
if vals.get('categ_id'):
vals['taxes_id'], vals['supplier_taxes_id'] = (
self.apply_tax_from_category(
self.categ_id.browse(vals['categ_id'])))
categ = self.env['product.category'].browse(vals['categ_id'])
vals['taxes_id'], vals['supplier_taxes_id'] =\
self.apply_tax_from_category(categ)
@api.model
def create(self, vals):
@@ -72,21 +54,21 @@ class ProductTemplate(models.Model):
def _check_tax_categ(self):
# self.name != 'Pay Debt' is a stupid hack to avoid blocking the
# 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:
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))
raise ValidationError(_(
"The sale taxes configured on the product '%s' "
"are not the same as the sale taxes configured "
"on it's related internal category '%s'.")
% (self.name, self.categ_id.name_get()[0][1]))
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))
raise ValidationError(_(
"The purchase taxes configured on the product '%s' "
"are not the same as the purchase taxes configured "
"on it's related internal category '%s'.")
% (self.name, self.categ_id.name_get()[0][1]))
class ProductProduct(models.Model):
@@ -99,13 +81,7 @@ class ProductCategory(models.Model):
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'])])
string="Sale Taxes", domain=[('type_tax_use', '=', 'sale')])
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'])])
string="Purchase Taxes", domain=[('type_tax_use', '=', 'purchase')])

View File

@@ -1,25 +1,22 @@
<?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
© 2015-2016 Akretion (http://www.akretion.com/)
@author Alexis de Lattre <alexis.delattre@akretion.com>
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
-->
<openerp>
<data>
<odoo>
<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="property_account_expense_categ_id" position="after">
<field name="sale_tax_ids" widget="many2many_tags"/>
<field name="purchase_tax_ids" widget="many2many_tags"/>
</group>
</field>
</field>
</record>
</data>
</openerp>
</odoo>