diff --git a/product_category_tax/README.rst b/product_category_tax/README.rst new file mode 100644 index 00000000000..56b210ea292 --- /dev/null +++ b/product_category_tax/README.rst @@ -0,0 +1,82 @@ +====================== +Product Category Taxes +====================== + +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png + :target: https://odoo-community.org/page/development-status + :alt: Beta +.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 +.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Faccount--financial--tools-lightgray.png?logo=github + :target: https://github.com/OCA/account-financial-tools/tree/15.0/product_category_tax + :alt: OCA/account-financial-tools +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/account-financial-tools-15-0/account-financial-tools-15-0-product_category_tax + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png + :target: https://runbot.odoo-community.org/runbot/92/15.0 + :alt: Try me on Runbot + +|badge1| |badge2| |badge3| |badge4| |badge5| + +Edit taxes directly in the product category. + +**Table of contents** + +.. contents:: + :local: + +Usage +===== + +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" + +Bug Tracker +=========== + +Bugs are tracked on `GitHub Issues `_. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us smashing it by providing a detailed and welcomed +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +~~~~~~~ + +* ForgeFlow S.L. + +Contributors +~~~~~~~~~~~~ + +* Aaron Henriquez +* Denis Roussel + +Maintainers +~~~~~~~~~~~ + +This module is maintained by the OCA. + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +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. + +This module is part of the `OCA/account-financial-tools `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/product_category_tax/__init__.py b/product_category_tax/__init__.py new file mode 100644 index 00000000000..0650744f6bc --- /dev/null +++ b/product_category_tax/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/product_category_tax/__manifest__.py b/product_category_tax/__manifest__.py new file mode 100644 index 00000000000..c8f94393aa6 --- /dev/null +++ b/product_category_tax/__manifest__.py @@ -0,0 +1,13 @@ +# Copyright 2020 ForgeFlow S.L. (https://www.forgeflow.com) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +{ + "name": "Product Category Taxes", + "summary": "Configure taxes in the product category", + "version": "16.0.1.0.0", + "license": "AGPL-3", + "author": "ForgeFlow S.L., Odoo Community Association (OCA)", + "website": "https://github.com/OCA/account-financial-tools", + "depends": ["account", "product_category_product_link"], + "data": ["views/product_category.xml", "views/product_template.xml"], +} diff --git a/product_category_tax/i18n/product_category_tax.pot b/product_category_tax/i18n/product_category_tax.pot new file mode 100644 index 00000000000..3163681b979 --- /dev/null +++ b/product_category_tax/i18n/product_category_tax.pot @@ -0,0 +1,70 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * product_category_tax +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 15.0\n" +"Report-Msgid-Bugs-To: \n" +"Last-Translator: \n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: product_category_tax +#: model_terms:ir.ui.view,arch_db:product_category_tax.product_category_form_view +msgid "-> Apply to Products" +msgstr "" + +#. module: product_category_tax +#: model:ir.model.fields,field_description:product_category_tax.field_product_category__taxes_id +msgid "Customer Taxes" +msgstr "" + +#. module: product_category_tax +#: model:ir.model.fields,help:product_category_tax.field_product_category__supplier_taxes_id +msgid "Default taxes used when buying the product." +msgstr "" + +#. module: product_category_tax +#: model:ir.model.fields,help:product_category_tax.field_product_category__taxes_id +msgid "Default taxes used when selling the product." +msgstr "" + +#. module: product_category_tax +#: model:ir.model,name:product_category_tax.model_product_product +msgid "Product" +msgstr "" + +#. module: product_category_tax +#: model:ir.model,name:product_category_tax.model_product_category +msgid "Product Category" +msgstr "" + +#. module: product_category_tax +#: model:ir.model,name:product_category_tax.model_product_template +msgid "Product Template" +msgstr "" + +#. module: product_category_tax +#: model_terms:ir.ui.view,arch_db:product_category_tax.product_category_form_view +msgid "Taxes" +msgstr "" + +#. module: product_category_tax +#: model:ir.model.fields,field_description:product_category_tax.field_product_product__taxes_updeatable_from_category +#: model:ir.model.fields,field_description:product_category_tax.field_product_template__taxes_updeatable_from_category +msgid "Taxes Updeatable From Category" +msgstr "" + +#. module: product_category_tax +#: model_terms:ir.ui.view,arch_db:product_category_tax.product_category_form_view +msgid "This will apply to all products in the category" +msgstr "" + +#. module: product_category_tax +#: model:ir.model.fields,field_description:product_category_tax.field_product_category__supplier_taxes_id +msgid "Vendor Taxes" +msgstr "" diff --git a/product_category_tax/models/__init__.py b/product_category_tax/models/__init__.py new file mode 100644 index 00000000000..ccf4778b03f --- /dev/null +++ b/product_category_tax/models/__init__.py @@ -0,0 +1,3 @@ +from . import product_category +from . import product_product +from . import product_template diff --git a/product_category_tax/models/product_category.py b/product_category_tax/models/product_category.py new file mode 100644 index 00000000000..c1459e960f2 --- /dev/null +++ b/product_category_tax/models/product_category.py @@ -0,0 +1,35 @@ +# Copyright 2020 ForgeFlow S.L. (https://www.forgeflow.com) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from odoo import fields, models + + +class ProductCategory(models.Model): + _inherit = "product.category" + + taxes_id = fields.Many2many( + "account.tax", + "product_category_taxes_rel", + "categ_id", + "tax_id", + help="Default taxes used when selling the product.", + string="Customer Taxes", + domain=[("type_tax_use", "=", "sale")], + default=lambda self: self.env.company.account_sale_tax_id, + ) + supplier_taxes_id = fields.Many2many( + "account.tax", + "product_category_supplier_taxes_rel", + "categ_id", + "tax_id", + string="Vendor Taxes", + help="Default taxes used when buying the product.", + domain=[("type_tax_use", "=", "purchase")], + default=lambda self: self.env.company.account_purchase_tax_id, + ) + + def update_product_taxes(self): + 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_product.py b/product_category_tax/models/product_product.py new file mode 100644 index 00000000000..16c41a503dd --- /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)] diff --git a/product_category_tax/models/product_template.py b/product_category_tax/models/product_template.py new file mode 100644 index 00000000000..e8e83853068 --- /dev/null +++ b/product_category_tax/models/product_template.py @@ -0,0 +1,20 @@ +# Copyright 2020 ForgeFlow S.L. (https://www.forgeflow.com) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +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: + 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)] diff --git a/product_category_tax/readme/CONFIGURATION.rst b/product_category_tax/readme/CONFIGURATION.rst new file mode 100644 index 00000000000..2b1382c66be --- /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/CONTRIBUTORS.rst b/product_category_tax/readme/CONTRIBUTORS.rst new file mode 100644 index 00000000000..b1f19cd8bbc --- /dev/null +++ b/product_category_tax/readme/CONTRIBUTORS.rst @@ -0,0 +1,2 @@ +* Aaron Henriquez +* Denis Roussel diff --git a/product_category_tax/readme/DESCRIPTION.rst b/product_category_tax/readme/DESCRIPTION.rst new file mode 100644 index 00000000000..ce5e630fe90 --- /dev/null +++ b/product_category_tax/readme/DESCRIPTION.rst @@ -0,0 +1 @@ +Edit taxes directly in the product category. diff --git a/product_category_tax/readme/USAGE.rst b/product_category_tax/readme/USAGE.rst new file mode 100644 index 00000000000..47d8f208b16 --- /dev/null +++ b/product_category_tax/readme/USAGE.rst @@ -0,0 +1,4 @@ +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" diff --git a/product_category_tax/static/description/icon.png b/product_category_tax/static/description/icon.png new file mode 100644 index 00000000000..3a0328b516c Binary files /dev/null and b/product_category_tax/static/description/icon.png differ diff --git a/product_category_tax/static/description/index.html b/product_category_tax/static/description/index.html new file mode 100644 index 00000000000..7b27f306e1f --- /dev/null +++ b/product_category_tax/static/description/index.html @@ -0,0 +1,429 @@ + + + + + + +Product Category Taxes + + + +
+

Product Category Taxes

+ + +

Beta License: AGPL-3 OCA/account-financial-tools Translate me on Weblate Try me on Runbot

+

Edit taxes directly in the product category.

+

Table of contents

+ +
+

Usage

+

In case all the products within the category will use the same tax setup:

+
    +
  1. Select the taxes in the product category form
  2. +
  3. Click on “Apply to Products”
  4. +
+
+
+

Bug Tracker

+

Bugs are tracked on GitHub Issues. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us smashing it by providing a detailed and welcomed +feedback.

+

Do not contact contributors directly about support or help with technical issues.

+
+
+

Credits

+
+

Authors

+
    +
  • ForgeFlow S.L.
  • +
+
+
+

Contributors

+ +
+
+

Maintainers

+

This module is maintained by the OCA.

+Odoo Community Association +

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.

+

This module is part of the OCA/account-financial-tools project on GitHub.

+

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

+
+
+
+ + diff --git a/product_category_tax/tests/__init__.py b/product_category_tax/tests/__init__.py new file mode 100644 index 00000000000..40bfb799b11 --- /dev/null +++ b/product_category_tax/tests/__init__.py @@ -0,0 +1 @@ +from . import test_product_category_tax diff --git a/product_category_tax/tests/test_product_category_tax.py b/product_category_tax/tests/test_product_category_tax.py new file mode 100644 index 00000000000..03e2e576860 --- /dev/null +++ b/product_category_tax/tests/test_product_category_tax.py @@ -0,0 +1,110 @@ +# Copyright 2020 ForgeFlow S.L. (https://www.forgeflow.com) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from odoo.tests.common import TransactionCase + + +class ProductCategoryTax(TransactionCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.categ_obj = cls.env["product.category"] + cls.product_obj = cls.env["product.product"] + cls.tax_model = cls.env["account.tax"] + + cls.uom_kg = cls.env.ref("uom.product_uom_kgm") + + # Create product and related records: + cls.tax_sale = cls.tax_model.create( + { + "name": "Include tax", + "type_tax_use": "sale", + "amount": 21.00, + "price_include": True, + } + ) + cls.tax_purchase = cls.tax_model.create( + { + "name": "Some tax", + "type_tax_use": "purchase", + "amount": 21.00, + "price_include": True, + } + ) + cls.tax_purchase2 = cls.tax_model.create( + { + "name": "Abusive tax", + "type_tax_use": "purchase", + "amount": 50.00, + "price_include": True, + } + ) + + def test_01_copy_taxes(self): + """Default taxes taken from the category""" + 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_test = self.product_obj.create( + {"name": "TEST 01", "categ_id": test_categ.id, "list_price": 155.0} + ) + self.product_test.product_tmpl_id.onchange_categ_id() + self.assertEqual(self.product_test.supplier_taxes_id, self.tax_purchase) + + def test_02_update_taxes(self): + """Default update""" + self.product_test = self.product_obj.create( + { + "name": "TEST 02", + "default_code": "TESTcode2", + "list_price": 155.0, + "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.assertEqual(self.product_test.supplier_taxes_id, self.tax_purchase2) + self.product_test.categ_id = test_categ.id + test_categ.update_product_taxes() + self.assertEqual(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.assertEqual(self.product_test3.supplier_taxes_id, self.tax_purchase) + self.assertNotEqual(self.product_test4.supplier_taxes_id, self.tax_purchase) diff --git a/product_category_tax/views/product_category.xml b/product_category_tax/views/product_category.xml new file mode 100644 index 00000000000..9909468894b --- /dev/null +++ b/product_category_tax/views/product_category.xml @@ -0,0 +1,27 @@ + + + + product.category.form.view.taxes + product.category + + + + +