From 03d3f30df6c64ecb84625a7ff4c0b0038f6f837c Mon Sep 17 00:00:00 2001 From: Alexis de Lattre Date: Thu, 22 May 2025 16:12:31 +0200 Subject: [PATCH] [MIG] product_category_tax from v14 to v16 --- product_category_tax/__manifest__.py | 8 ++++---- product_category_tax/product.py | 23 +++++++++++------------ 2 files changed, 15 insertions(+), 16 deletions(-) diff --git a/product_category_tax/__manifest__.py b/product_category_tax/__manifest__.py index 5e25db3..c508ebd 100644 --- a/product_category_tax/__manifest__.py +++ b/product_category_tax/__manifest__.py @@ -1,17 +1,17 @@ -# Copyright 2015-2020 Akretion (http://www.akretion.com) +# Copyright 2015-2025 Akretion France (https://www.akretion.com) # @author Alexis de Lattre # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). { 'name': 'Product Category Tax', - 'version': '14.0.1.0.0', + 'version': '16.0.1.0.0', 'category': 'Accounting & Finance', 'license': 'AGPL-3', 'summary': 'Adds sale and purchase taxes on product category', 'description': "", 'author': 'Akretion', - 'website': 'http://www.akretion.com', + 'website': 'https://github.com/akretion/odoo-usability', 'depends': ['account'], 'data': ['product_view.xml'], - 'installable': False, + 'installable': True, } diff --git a/product_category_tax/product.py b/product_category_tax/product.py index 560de2f..bc71b15 100644 --- a/product_category_tax/product.py +++ b/product_category_tax/product.py @@ -1,8 +1,8 @@ -# Copyright 2015-2020 Akretion (http://www.akretion.com) +# Copyright 2015-2025 Akretion France (https://www.akretion.com) # @author Alexis de Lattre # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -from odoo import api, fields, models, _ +from odoo import api, fields, models, Command, _ from odoo.exceptions import ValidationError @@ -24,8 +24,8 @@ class ProductCategTaxMixin(models.AbstractModel): # 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.sale_tax_ids.ids)], - [(6, 0, categ.purchase_tax_ids.ids)]) + return ([Command.set(categ.sale_tax_ids.ids)], + [Command.set(categ.purchase_tax_ids.ids)]) @api.model def write_or_create(self, vals): @@ -34,10 +34,11 @@ class ProductCategTaxMixin(models.AbstractModel): vals['taxes_id'], vals['supplier_taxes_id'] =\ self.apply_tax_from_category(categ) - @api.model - def create(self, vals): - self.write_or_create(vals) - return super().create(vals) + @api.model_create_multi + def create(self, vals_list): + for vals in vals_list: + self.write_or_create(vals) + return super().create(vals_list) def write(self, vals): self.write_or_create(vals) @@ -48,12 +49,10 @@ class ProductTemplate(models.Model): _inherit = ['product.template', 'product.categ.tax.mixin'] _name = 'product.template' - @api.constrains('taxes_id', 'supplier_taxes_id') + @api.constrains('taxes_id', 'supplier_taxes_id', 'categ_id') def _check_tax_categ(self): - # self.name != 'Pay Debt' is a stupid hack to avoid blocking the - # installation of the module 'pos_debt_notebook' for pt in self: - if pt.categ_id: # and self.name != 'Pay Debt': + if pt.categ_id: if pt.categ_id.sale_tax_ids.ids != pt.taxes_id.ids: raise ValidationError(_( "The sale taxes configured on the product '%s' "