diff --git a/account_ecotax_sale_tax/README.rst b/account_ecotax_sale_tax/README.rst new file mode 100644 index 000000000..d48b2dcf6 --- /dev/null +++ b/account_ecotax_sale_tax/README.rst @@ -0,0 +1,90 @@ +================================= +sale Ecotax Management (as a tax) +================================= + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:1bb5569058cef23c079b4a18bfe9e0ab55d3dff17a0eadb2ff8953f5850d14dd + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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--fiscal--rule-lightgray.png?logo=github + :target: https://github.com/OCA/account-fiscal-rule/tree/17.0/account_ecotax_sale_tax + :alt: OCA/account-fiscal-rule +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/account-fiscal-rule-17-0/account-fiscal-rule-17-0-account_ecotax_sale_tax + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png + :target: https://runboat.odoo-community.org/builds?repo=OCA/account-fiscal-rule&target_branch=17.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module is an extension of the module *l10n_fr_ecotax* for sale +orders. Please refer to the README of the module *l10n_fr_ecotax* for +more info about ecotax management. + +**Table of contents** + +.. contents:: + :local: + +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 to smash it by providing a detailed and welcomed +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +------- + +* Akretion + +Contributors +------------ + +- Mourad EL HADJ MIMOUNE +- Florian DA COSTA + +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. + +.. |maintainer-mourad-ehm| image:: https://github.com/mourad-ehm.png?size=40px + :target: https://github.com/mourad-ehm + :alt: mourad-ehm +.. |maintainer-florian-dacosta| image:: https://github.com/florian-dacosta.png?size=40px + :target: https://github.com/florian-dacosta + :alt: florian-dacosta + +Current `maintainers `__: + +|maintainer-mourad-ehm| |maintainer-florian-dacosta| + +This module is part of the `OCA/account-fiscal-rule `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/account_ecotax_sale_tax/__init__.py b/account_ecotax_sale_tax/__init__.py new file mode 100644 index 000000000..0650744f6 --- /dev/null +++ b/account_ecotax_sale_tax/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/account_ecotax_sale_tax/__manifest__.py b/account_ecotax_sale_tax/__manifest__.py new file mode 100644 index 000000000..f0faf28bb --- /dev/null +++ b/account_ecotax_sale_tax/__manifest__.py @@ -0,0 +1,17 @@ +# © 2014-2023 Akretion (http://www.akretion.com) +# @author Mourad EL HADJ MIMOUNE +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +{ + "name": "sale Ecotax Management (as a tax)", + "summary": "Sale Ecotaxe managed as a tax", + "version": "17.0.2.0.1", + "author": "Akretion,Odoo Community Association (OCA)", + "maintainers": ["mourad-ehm", "florian-dacosta"], + "website": "https://github.com/OCA/account-fiscal-rule", + "category": "Localization/Account Taxes", + "license": "AGPL-3", + "depends": ["account_ecotax_sale", "account_ecotax_tax"], + "data": ["views/sale_view.xml"], + "installable": True, + "auto_install": True, +} diff --git a/account_ecotax_sale_tax/i18n/account_ecotax_sale_tax.pot b/account_ecotax_sale_tax/i18n/account_ecotax_sale_tax.pot new file mode 100644 index 000000000..148ae347a --- /dev/null +++ b/account_ecotax_sale_tax/i18n/account_ecotax_sale_tax.pot @@ -0,0 +1,29 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * account_ecotax_sale_tax +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.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: account_ecotax_sale_tax +#: model:ir.model.fields,field_description:account_ecotax_sale_tax.field_sale_order_line__subtotal_ecotax +msgid "Ecotax" +msgstr "" + +#. module: account_ecotax_sale_tax +#: model:ir.model.fields,field_description:account_ecotax_sale_tax.field_sale_order_line__ecotax_amount_unit +msgid "Ecotax Unit" +msgstr "" + +#. module: account_ecotax_sale_tax +#: model:ir.model,name:account_ecotax_sale_tax.model_sale_order_line +msgid "Sales Order Line" +msgstr "" diff --git a/account_ecotax_sale_tax/i18n/it.po b/account_ecotax_sale_tax/i18n/it.po new file mode 100644 index 000000000..245b312d5 --- /dev/null +++ b/account_ecotax_sale_tax/i18n/it.po @@ -0,0 +1,32 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * account_ecotax_sale_tax +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2025-03-18 19:06+0000\n" +"Last-Translator: mymage \n" +"Language-Team: none\n" +"Language: it\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=n != 1;\n" +"X-Generator: Weblate 5.10.2\n" + +#. module: account_ecotax_sale_tax +#: model:ir.model.fields,field_description:account_ecotax_sale_tax.field_sale_order_line__subtotal_ecotax +msgid "Ecotax" +msgstr "Imposta ecologica" + +#. module: account_ecotax_sale_tax +#: model:ir.model.fields,field_description:account_ecotax_sale_tax.field_sale_order_line__ecotax_amount_unit +msgid "Ecotax Unit" +msgstr "Unità imposta ecologica" + +#. module: account_ecotax_sale_tax +#: model:ir.model,name:account_ecotax_sale_tax.model_sale_order_line +msgid "Sales Order Line" +msgstr "Riga ordine di vendita" diff --git a/account_ecotax_sale_tax/models/__init__.py b/account_ecotax_sale_tax/models/__init__.py new file mode 100644 index 000000000..8eb9d1d40 --- /dev/null +++ b/account_ecotax_sale_tax/models/__init__.py @@ -0,0 +1 @@ +from . import sale_order_line diff --git a/account_ecotax_sale_tax/models/sale_order_line.py b/account_ecotax_sale_tax/models/sale_order_line.py new file mode 100644 index 000000000..78606fb2d --- /dev/null +++ b/account_ecotax_sale_tax/models/sale_order_line.py @@ -0,0 +1,85 @@ +# © 2015 -2023 Akretion (http://www.akretion.com) +# @author Mourad EL HADJ MIMOUNE +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from odoo import api, fields, models + + +class SaleOrderLine(models.Model): + _inherit = "sale.order.line" + + subtotal_ecotax = fields.Float(compute="_compute_ecotax_tax") + ecotax_amount_unit = fields.Float( + compute="_compute_ecotax_tax", + ) + + def _get_ecotax_amounts(self): + self.ensure_one() + # do not call super as we completly change the way to compute it + ecotax_ids = self.tax_id.filtered(lambda tax: tax.is_ecotax) + if (self.display_type and self.display_type != "product") or not ecotax_ids: + return 0.0, 0.0 + amount_currency = self.price_unit * (1 - self.discount / 100) + quantity = self.product_uom_qty + compute_all_currency = ecotax_ids.compute_all( + amount_currency, + currency=self.currency_id, + quantity=quantity, + product=self.product_id, + partner=self.order_id.partner_shipping_id, + ) + subtotal_ecotax = 0.0 + for tax in compute_all_currency["taxes"]: + subtotal_ecotax += tax["amount"] + + unit = quantity and subtotal_ecotax / quantity or subtotal_ecotax + return unit, subtotal_ecotax + + @api.depends( + "tax_id", + "product_uom_qty", + "product_id", + ) + def _compute_ecotax_tax(self): + return self._compute_ecotax() + + def _get_new_vals_list(self): + if not self.subtotal_ecotax: + return [] + return super()._get_new_vals_list() + + # ensure lines are re-generated in case ecotax_amount_unit of invoice line change + # without changing the product + @api.depends("ecotax_amount_unit", "subtotal_ecotax") + def _compute_ecotax_line_ids(self): + return super()._compute_ecotax_line_ids() + + @api.depends("product_id", "company_id") + def _compute_tax_id(self): + res = super()._compute_tax_id() + for line in self: + line.tax_id |= line._get_computed_ecotaxes() + return res + + def _get_computed_ecotaxes(self): + self.ensure_one() + sale_ecotaxes = self.product_id.all_ecotax_line_product_ids.mapped( + "classification_id" + ).mapped("sale_ecotax_ids") + ecotax_ids = sale_ecotaxes.filtered( + lambda tax: tax.company_id == self.order_id.company_id + ) + + if ecotax_ids and self.order_id.fiscal_position_id: + ecotax_ids = self.order_id.fiscal_position_id.map_tax(ecotax_ids) + return ecotax_ids + + def _prepare_invoice_line(self, **optional_values): + res = super()._prepare_invoice_line(**optional_values) + # remove ecoltax_line_ids value if empty in vals so it is recomputed during + # invoice line creation. Example of use case : Ship a product not present in + # SO. So line is created with qty 0 (so with no ecotax) but in invoice it is + # added with a qty, with ecotax, so we want to recompute the ecotax report lines + if "ecotax_line_ids" in res and not res["ecotax_line_ids"]: + res.pop("ecotax_line_ids") + return res diff --git a/account_ecotax_sale_tax/pyproject.toml b/account_ecotax_sale_tax/pyproject.toml new file mode 100644 index 000000000..4231d0ccc --- /dev/null +++ b/account_ecotax_sale_tax/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/account_ecotax_sale_tax/readme/CONTRIBUTORS.md b/account_ecotax_sale_tax/readme/CONTRIBUTORS.md new file mode 100644 index 000000000..18d13881d --- /dev/null +++ b/account_ecotax_sale_tax/readme/CONTRIBUTORS.md @@ -0,0 +1,2 @@ +- Mourad EL HADJ MIMOUNE \<\> +- Florian DA COSTA \<\> diff --git a/account_ecotax_sale_tax/readme/DESCRIPTION.md b/account_ecotax_sale_tax/readme/DESCRIPTION.md new file mode 100644 index 000000000..6f53d1678 --- /dev/null +++ b/account_ecotax_sale_tax/readme/DESCRIPTION.md @@ -0,0 +1,3 @@ +This module is an extension of the module *l10n_fr_ecotax* for sale +orders. Please refer to the README of the module *l10n_fr_ecotax* for +more info about ecotax management. diff --git a/account_ecotax_sale_tax/static/description/icon.png b/account_ecotax_sale_tax/static/description/icon.png new file mode 100644 index 000000000..3a0328b51 Binary files /dev/null and b/account_ecotax_sale_tax/static/description/icon.png differ diff --git a/account_ecotax_sale_tax/static/description/index.html b/account_ecotax_sale_tax/static/description/index.html new file mode 100644 index 000000000..2c46d9a99 --- /dev/null +++ b/account_ecotax_sale_tax/static/description/index.html @@ -0,0 +1,428 @@ + + + + + +sale Ecotax Management (as a tax) + + + +
+

sale Ecotax Management (as a tax)

+ + +

Beta License: AGPL-3 OCA/account-fiscal-rule Translate me on Weblate Try me on Runboat

+

This module is an extension of the module l10n_fr_ecotax for sale +orders. Please refer to the README of the module l10n_fr_ecotax for +more info about ecotax management.

+

Table of contents

+ +
+

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 to smash it by providing a detailed and welcomed +feedback.

+

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

+
+
+

Credits

+
+

Authors

+
    +
  • Akretion
  • +
+
+
+

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.

+

Current maintainers:

+

mourad-ehm florian-dacosta

+

This module is part of the OCA/account-fiscal-rule project on GitHub.

+

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

+
+
+
+ + diff --git a/account_ecotax_sale_tax/tests/__init__.py b/account_ecotax_sale_tax/tests/__init__.py new file mode 100644 index 000000000..809acf6a1 --- /dev/null +++ b/account_ecotax_sale_tax/tests/__init__.py @@ -0,0 +1 @@ +from . import test_sale_ecotax diff --git a/account_ecotax_sale_tax/tests/test_sale_ecotax.py b/account_ecotax_sale_tax/tests/test_sale_ecotax.py new file mode 100644 index 000000000..3c41a45be --- /dev/null +++ b/account_ecotax_sale_tax/tests/test_sale_ecotax.py @@ -0,0 +1,64 @@ +# © 2021-2023 Akretion (http://www.akretion.com) +# @author Mourad EL HADJ MIMOUNE +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + + +from odoo import Command +from odoo.tests.common import Form + +from odoo.addons.account_ecotax_sale.tests.test_sale_ecotax import TestsaleEcotaxCommon +from odoo.addons.account_ecotax_tax.tests.test_ecotax import TestInvoiceEcotaxTaxComon + + +class TestsaleEcotaxTax(TestInvoiceEcotaxTaxComon, TestsaleEcotaxCommon): + @classmethod + def setUpClass(cls): + super().setUpClass() + # Remove default taxes to match test expectations (which expect no VAT) + cls.product_a.taxes_id = [Command.clear()] + cls.product_b.taxes_id = [Command.clear()] + + def test_01_classification_weight_based_ecotax(self): + """Tests with weight based ecotaxs""" + # in order to test the correct assignment of weight ecotax + # I create a customer sale. + partner12 = self.env.ref("base.res_partner_12") + self.sale = self.create_sale_partner( + partner_id=partner12, products_and_qty=[(self.product_b, 1.0)] + ) + self.assertEqual(self.product_b.ecotax_amount, 16) + so_form = Form(self.sale) + with so_form.order_line.edit(0) as line: + line.product_uom_qty = 3.0 + so_form.save() + self.assertEqual(self.sale.order_line.ecotax_amount_unit, 16) + self.assertEqual(self.sale.order_line.subtotal_ecotax, 48) + self.assertEqual(self.sale.amount_total, 648) + self.assertEqual(self.sale.amount_ecotax, 48) + + def test_02_classification_ecotax(self): + """Tests multiple lines with mixed ecotaxs""" + # in order to test the correct assignment of fixed ecotax and weight ecotax + # I create a customer sale. + partner12 = self.env.ref("base.res_partner_12") + self.sale = self.create_sale_partner( + partner_id=partner12, + products_and_qty=[(self.product_a, 1.0), (self.product_b, 2.0)], + ) + # I assign a product with fixed ecotaxte to sale line + sale_line1 = self.sale.order_line[0] + # make sure to have 1 tax and fix tax rate + sale_line2 = self.sale.order_line[1] + # make sure to have 1 tax and fix tax rate + self.assertEqual(self.product_a.ecotax_amount, 5.0) + so_form = Form(self.sale) + with so_form.order_line.edit(0) as line: + line.product_uom_qty = 3.0 + so_form.save() + + self.assertEqual(sale_line1.ecotax_amount_unit, 5.0) + self.assertAlmostEqual(sale_line1.subtotal_ecotax, 15.0) + self.assertEqual(sale_line2.ecotax_amount_unit, 16) + self.assertEqual(sale_line2.subtotal_ecotax, 32) + self.assertEqual(self.sale.amount_total, 1047.0) + self.assertEqual(self.sale.amount_ecotax, 47.0) diff --git a/account_ecotax_sale_tax/views/sale_view.xml b/account_ecotax_sale_tax/views/sale_view.xml new file mode 100644 index 000000000..063e95cd1 --- /dev/null +++ b/account_ecotax_sale_tax/views/sale_view.xml @@ -0,0 +1,14 @@ + + + + + sale.order.line + + + + 1 + + + + + diff --git a/test-requirements.txt b/test-requirements.txt new file mode 100644 index 000000000..84f72222d --- /dev/null +++ b/test-requirements.txt @@ -0,0 +1 @@ +odoo-addon-account_ecotax_tax @ git+https://github.com/OCA/account-fiscal-rule.git@refs/pull/561/head#subdirectory=account_ecotax_tax