From 733e8c5f5c95c1a827e817f4979f7d570abc0760 Mon Sep 17 00:00:00 2001 From: JordiMForgeFlow Date: Fri, 27 May 2022 10:37:57 +0200 Subject: [PATCH] [IMP] product_category_tax: apply onchanges on product variant --- product_category_tax/models/__init__.py | 1 + product_category_tax/models/product_product.py | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) create mode 100644 product_category_tax/models/product_product.py diff --git a/product_category_tax/models/__init__.py b/product_category_tax/models/__init__.py index f154bb528..ccf4778b0 100644 --- a/product_category_tax/models/__init__.py +++ b/product_category_tax/models/__init__.py @@ -1,2 +1,3 @@ from . import product_category +from . import product_product from . import product_template diff --git a/product_category_tax/models/product_product.py b/product_category_tax/models/product_product.py new file mode 100644 index 000000000..16c41a503 --- /dev/null +++ b/product_category_tax/models/product_product.py @@ -0,0 +1,18 @@ +# Copyright 2022 ForgeFlow S.L. (https://www.forgeflow.com) +# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html). + +from odoo import api, models + + +class ProductProduct(models.Model): + _inherit = "product.product" + + @api.onchange("categ_id") + def onchange_categ_id(self): + if self.categ_id: + self.set_tax_from_category() + + def set_tax_from_category(self): + self.ensure_one() + self.taxes_id = [(6, 0, self.categ_id.taxes_id.ids)] + self.supplier_taxes_id = [(6, 0, self.categ_id.supplier_taxes_id.ids)]