From 822697085cc5ffd6be1f685fb55adbabd25d524e Mon Sep 17 00:00:00 2001 From: AaronHForgeFlow Date: Wed, 18 Nov 2020 18:05:58 +0100 Subject: [PATCH] [IMP] product_category_tax * add a boleean to exclude specific products to be updated --- product_category_tax/README.rst | 4 --- product_category_tax/__manifest__.py | 2 +- .../models/product_category.py | 4 ++- .../models/product_template.py | 4 ++- product_category_tax/readme/CONFIGURATION.rst | 3 ++ product_category_tax/readme/USAGE.rst | 4 --- .../static/description/index.html | 3 -- .../tests/test_product_category_tax.py | 32 +++++++++++++++++++ .../views/product_template.xml | 16 ++++++++++ 9 files changed, 58 insertions(+), 14 deletions(-) create mode 100644 product_category_tax/readme/CONFIGURATION.rst create mode 100644 product_category_tax/views/product_template.xml diff --git a/product_category_tax/README.rst b/product_category_tax/README.rst index aceee36fa..e7d0b50ec 100644 --- a/product_category_tax/README.rst +++ b/product_category_tax/README.rst @@ -40,10 +40,6 @@ In case all the products within the category will use the same tax setup: #. Select the taxes in the product category form #. Click on "Apply to Products" -In case a specific product need a different tax configuration you have to -either to include it in a subcategory or adjust its taxes after applying those -to the others - Bug Tracker =========== diff --git a/product_category_tax/__manifest__.py b/product_category_tax/__manifest__.py index 2f83813ec..0f0b9259b 100644 --- a/product_category_tax/__manifest__.py +++ b/product_category_tax/__manifest__.py @@ -9,5 +9,5 @@ "author": "ForgeFlow S.L., Odoo Community Association (OCA)", "website": "https://github.com/OCA/account-financial-tools", "depends": ["account"], - "data": ["views/product_category.xml"], + "data": ["views/product_category.xml", "views/product_template.xml"], } diff --git a/product_category_tax/models/product_category.py b/product_category_tax/models/product_category.py index 5372c6468..23f269912 100644 --- a/product_category_tax/models/product_category.py +++ b/product_category_tax/models/product_category.py @@ -32,5 +32,7 @@ class ProductCategory(models.Model): ) def update_product_taxes(self): - for template in self.product_template_ids: + for template in self.product_template_ids.filtered( + lambda p: p.taxes_updeatable_from_category + ): template.set_tax_from_category() diff --git a/product_category_tax/models/product_template.py b/product_category_tax/models/product_template.py index 23c024734..bd4c3f8e7 100644 --- a/product_category_tax/models/product_template.py +++ b/product_category_tax/models/product_template.py @@ -1,12 +1,14 @@ # Copyright 2020 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 +from odoo import api, fields, models class ProductTemplate(models.Model): _inherit = "product.template" + taxes_updeatable_from_category = fields.Boolean(default=True) + @api.onchange("categ_id") def onchange_categ_id(self): if self.categ_id: diff --git a/product_category_tax/readme/CONFIGURATION.rst b/product_category_tax/readme/CONFIGURATION.rst new file mode 100644 index 000000000..2b1382c66 --- /dev/null +++ b/product_category_tax/readme/CONFIGURATION.rst @@ -0,0 +1,3 @@ +In case a specific product need a different tax configuration you have to +check the option "Taxes Updeatable From Category" in the Accounting tab in the +product form. diff --git a/product_category_tax/readme/USAGE.rst b/product_category_tax/readme/USAGE.rst index 2136550f5..47d8f208b 100644 --- a/product_category_tax/readme/USAGE.rst +++ b/product_category_tax/readme/USAGE.rst @@ -2,7 +2,3 @@ In case all the products within the category will use the same tax setup: #. Select the taxes in the product category form #. Click on "Apply to Products" - -In case a specific product need a different tax configuration you have to -either to include it in a subcategory or adjust its taxes after applying those -to the others diff --git a/product_category_tax/static/description/index.html b/product_category_tax/static/description/index.html index c6b60d41c..06199707f 100644 --- a/product_category_tax/static/description/index.html +++ b/product_category_tax/static/description/index.html @@ -389,9 +389,6 @@ ul.auto-toc {
  • Select the taxes in the product category form
  • Click on “Apply to Products”
  • -

    In case a specific product need a different tax configuration you have to -either to include it in a subcategory or adjust its taxes after applying those -to the others

    Bug Tracker

    diff --git a/product_category_tax/tests/test_product_category_tax.py b/product_category_tax/tests/test_product_category_tax.py index 8901c2bc2..bc1d0b393 100644 --- a/product_category_tax/tests/test_product_category_tax.py +++ b/product_category_tax/tests/test_product_category_tax.py @@ -76,3 +76,35 @@ class ProductCategoryTax(common.SavepointCase): self.product_test.categ_id = test_categ.id test_categ.update_product_taxes() self.assertEquals(self.product_test.supplier_taxes_id, self.tax_purchase) + + def test_03_taxes_not_updeatable(self): + """ Avoid update specific products""" + self.product_test3 = self.product_obj.create( + { + "name": "TEST 03", + "default_code": "TESTcode3", + "list_price": 155.0, + "supplier_taxes_id": [(6, 0, self.tax_purchase2.ids)], + } + ) + self.product_test4 = self.product_obj.create( + { + "name": "TEST 04", + "default_code": "TESTcode3", + "list_price": 155.0, + "taxes_updeatable_from_category": False, + "supplier_taxes_id": [(6, 0, self.tax_purchase2.ids)], + } + ) + test_categ = self.categ_obj.create( + { + "name": "Super Category", + "taxes_id": [(6, 0, self.tax_sale.ids)], + "supplier_taxes_id": [(6, 0, self.tax_purchase.ids)], + } + ) + self.product_test3.categ_id = test_categ.id + self.product_test4.categ_id = test_categ.id + test_categ.update_product_taxes() + self.assertEquals(self.product_test3.supplier_taxes_id, self.tax_purchase) + self.assertNotEquals(self.product_test4.supplier_taxes_id, self.tax_purchase) diff --git a/product_category_tax/views/product_template.xml b/product_category_tax/views/product_template.xml new file mode 100644 index 000000000..63024c4db --- /dev/null +++ b/product_category_tax/views/product_template.xml @@ -0,0 +1,16 @@ + + + + product.template.form.tax.updeatable + product.template + + + + + + + +