diff --git a/product_category_tax/README.rst b/product_category_tax/README.rst new file mode 100644 index 000000000..e7d0b50ec --- /dev/null +++ b/product_category_tax/README.rst @@ -0,0 +1,81 @@ +====================== +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/13.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-13-0/account-financial-tools-13-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/13.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 + +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 000000000..0650744f6 --- /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 000000000..0f0b9259b --- /dev/null +++ b/product_category_tax/__manifest__.py @@ -0,0 +1,13 @@ +# Copyright 2020 ForgeFlow S.L. (https://www.forgeflow.com) +# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html). + +{ + "name": "Product Category Taxes", + "summary": "Configure taxes in the product category", + "version": "13.0.1.1.0", + "license": "AGPL-3", + "author": "ForgeFlow S.L., Odoo Community Association (OCA)", + "website": "https://github.com/OCA/account-financial-tools", + "depends": ["account"], + "data": ["views/product_category.xml", "views/product_template.xml"], +} diff --git a/product_category_tax/models/__init__.py b/product_category_tax/models/__init__.py new file mode 100644 index 000000000..f154bb528 --- /dev/null +++ b/product_category_tax/models/__init__.py @@ -0,0 +1,2 @@ +from . import product_category +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 000000000..23f269912 --- /dev/null +++ b/product_category_tax/models/product_category.py @@ -0,0 +1,38 @@ +# 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 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, + ) + product_template_ids = fields.One2many( + "product.template", "categ_id", string="Products Templates" + ) + + 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_template.py b/product_category_tax/models/product_template.py new file mode 100644 index 000000000..bd4c3f8e7 --- /dev/null +++ b/product_category_tax/models/product_template.py @@ -0,0 +1,20 @@ +# 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, 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 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/CONTRIBUTORS.rst b/product_category_tax/readme/CONTRIBUTORS.rst new file mode 100644 index 000000000..2e524967e --- /dev/null +++ b/product_category_tax/readme/CONTRIBUTORS.rst @@ -0,0 +1 @@ +* Aaron Henriquez diff --git a/product_category_tax/readme/DESCRIPTION.rst b/product_category_tax/readme/DESCRIPTION.rst new file mode 100644 index 000000000..ce5e630fe --- /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 000000000..47d8f208b --- /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 000000000..3a0328b51 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 000000000..06199707f --- /dev/null +++ b/product_category_tax/static/description/index.html @@ -0,0 +1,428 @@ + + + + + + +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 000000000..40bfb799b --- /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 000000000..bc1d0b393 --- /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 LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html). + +import odoo.tests.common as common + + +class ProductCategoryTax(common.SavepointCase): + @classmethod + def setUpClass(cls): + super(ProductCategoryTax, cls).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.assertEquals(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.assertEquals(self.product_test.supplier_taxes_id, self.tax_purchase2) + 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_category.xml b/product_category_tax/views/product_category.xml new file mode 100644 index 000000000..990946889 --- /dev/null +++ b/product_category_tax/views/product_category.xml @@ -0,0 +1,27 @@ + + + + product.category.form.view.taxes + product.category + + + + +