From 40dc5485a9fdc0ec4438b3b82dbf7b13fa768424 Mon Sep 17 00:00:00 2001 From: Alexis de Lattre Date: Wed, 7 Dec 2016 10:08:37 +0100 Subject: [PATCH] Port product_category_tax to v10 --- product_category_tax/README.rst | 20 +++---- product_category_tax/__init__.py | 22 +------- product_category_tax/__manifest__.py | 31 +++-------- product_category_tax/product.py | 76 +++++++++------------------ product_category_tax/product_view.xml | 17 +++--- 5 files changed, 46 insertions(+), 120 deletions(-) diff --git a/product_category_tax/README.rst b/product_category_tax/README.rst index 1441b91..b18bbe7 100644 --- a/product_category_tax/README.rst +++ b/product_category_tax/README.rst @@ -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 - -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 index d18a596..d7d7308 100644 --- a/product_category_tax/__init__.py +++ b/product_category_tax/__init__.py @@ -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 -# -# 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 . -# -############################################################################## +# -*- coding: utf-8 -*- from . import product diff --git a/product_category_tax/__manifest__.py b/product_category_tax/__manifest__.py index 189e425..92828e0 100644 --- a/product_category_tax/__manifest__.py +++ b/product_category_tax/__manifest__.py @@ -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 -# -# 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 . -# -############################################################################## - +# -*- coding: utf-8 -*- +# © 2015-2016 Akretion (http://www.akretion.com) +# @author Alexis de Lattre +# 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, } diff --git a/product_category_tax/product.py b/product_category_tax/product.py index 9be6504..64bb198 100644 --- a/product_category_tax/product.py +++ b/product_category_tax/product.py @@ -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 -# -# 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 . -# -############################################################################## +# -*- coding: utf-8 -*- +# © 2015-2016 Akretion (http://www.akretion.com) +# @author Alexis de Lattre +# 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')]) diff --git a/product_category_tax/product_view.xml b/product_category_tax/product_view.xml index c222fe6..a459148 100644 --- a/product_category_tax/product_view.xml +++ b/product_category_tax/product_view.xml @@ -1,25 +1,22 @@ - - - + product_category_tax.product.categ.form product.category - + - + - - +