diff --git a/account_ecotax_sale/README.rst b/account_ecotax_sale/README.rst index a93a83302..fcd771554 100644 --- a/account_ecotax_sale/README.rst +++ b/account_ecotax_sale/README.rst @@ -28,7 +28,7 @@ sale Ecotax Management |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. +This module is an extension of the module *l10n_fr_ecotax* for sale orders. Please refer to the README of the module *account_ecotax* for more info about ecotax management. **Table of contents** @@ -57,6 +57,8 @@ Contributors ~~~~~~~~~~~~ * Mourad EL HADJ MIMOUNE +* Florian DA COSTA + Maintainers ~~~~~~~~~~~ @@ -71,6 +73,17 @@ 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/__manifest__.py b/account_ecotax_sale/__manifest__.py index ddaaaf2e0..dde2d6d54 100644 --- a/account_ecotax_sale/__manifest__.py +++ b/account_ecotax_sale/__manifest__.py @@ -5,6 +5,7 @@ "name": "sale Ecotax Management", "summary": "Sale Ecotaxe", "version": "16.0.2.0.0", + "maintainers": ["mourad-ehm", "florian-dacosta"], "author": "Akretion,Odoo Community Association (OCA)", "website": "https://github.com/OCA/account-fiscal-rule", "category": "Localization/Account Taxes", diff --git a/account_ecotax_sale/models/sale_order_line.py b/account_ecotax_sale/models/sale_order_line.py index bfb1379ac..f75ca6c68 100644 --- a/account_ecotax_sale/models/sale_order_line.py +++ b/account_ecotax_sale/models/sale_order_line.py @@ -25,58 +25,28 @@ class SaleOrderLine(models.Model): compute="_compute_ecotax", ) + def _get_ecotax_amounts(self): + self.ensure_one() + unit = sum(self.ecotax_line_ids.mapped("amount_unit")) + subtotal_ecotax = sum(self.ecotax_line_ids.mapped("amount_total")) + return unit, subtotal_ecotax + @api.depends( "currency_id", - "tax_id", - "product_uom_qty", - "product_id", + "ecotax_line_ids.amount_unit", + "ecotax_line_ids.amount_total", ) def _compute_ecotax(self): for line in self: - ecotax_ids = line.tax_id.filtered(lambda tax: tax.is_ecotax) - if (line.display_type and line.display_type != "product") or not ecotax_ids: - continue - amount_currency = line.price_unit * (1 - line.discount / 100) - quantity = line.product_uom_qty - compute_all_currency = ecotax_ids.compute_all( - amount_currency, - currency=line.currency_id, - quantity=quantity, - product=line.product_id, - partner=line.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 - line.ecotax_amount_unit = unit - line.subtotal_ecotax = subtotal_ecotax - - @api.depends("product_id", "company_id") - def _compute_tax_id(self): - super()._compute_tax_id() - for line in self: - line.tax_id |= line._get_computed_ecotaxes() - - 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 + amount_unit, subtotal = line._get_ecotax_amounts() + line.subtotal_ecotax = subtotal + line.ecotax_amount_unit = amount_unit @api.onchange("product_id") def _onchange_product_ecotax_line(self): """Unlink and recreate ecotax_lines when modifying the product_id.""" + self.ecotax_line_ids.unlink() if self.product_id: - self.ecotax_line_ids = [(5,)] # Remove all ecotax classification ecotax_cls_vals = [] for ecotaxline_prod in self.product_id.all_ecotax_line_product_ids: classif_id = ecotaxline_prod.classification_id.id @@ -92,8 +62,6 @@ def _onchange_product_ecotax_line(self): ) ) self.ecotax_line_ids = ecotax_cls_vals - else: - self.ecotax_line_ids = [(5,)] def edit_ecotax_lines(self): view = { diff --git a/account_ecotax_sale/readme/CONTRIBUTORS.rst b/account_ecotax_sale/readme/CONTRIBUTORS.rst index f55657f6b..934f6e19b 100644 --- a/account_ecotax_sale/readme/CONTRIBUTORS.rst +++ b/account_ecotax_sale/readme/CONTRIBUTORS.rst @@ -1 +1,3 @@ * Mourad EL HADJ MIMOUNE +* Florian DA COSTA + diff --git a/account_ecotax_sale/readme/DESCRIPTION.rst b/account_ecotax_sale/readme/DESCRIPTION.rst index ad5cc0194..72cb84d5e 100644 --- a/account_ecotax_sale/readme/DESCRIPTION.rst +++ b/account_ecotax_sale/readme/DESCRIPTION.rst @@ -1 +1 @@ -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. +This module is an extension of the module *l10n_fr_ecotax* for sale orders. Please refer to the README of the module *account_ecotax* for more info about ecotax management. diff --git a/account_ecotax_sale/static/description/index.html b/account_ecotax_sale/static/description/index.html index 1f0e60246..5093f8750 100644 --- a/account_ecotax_sale/static/description/index.html +++ b/account_ecotax_sale/static/description/index.html @@ -370,7 +370,7 @@

sale Ecotax Management

!! source digest: sha256:731b0e3366890dbeca7db020b75324a2d458308b74991b4ce1d16937c9591178 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->

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.

+

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

Table of contents

@@ -414,6 +415,8 @@

Maintainers

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/tests/test_sale_ecotax.py b/account_ecotax_sale/tests/test_sale_ecotax.py index a23acaf09..21079e469 100644 --- a/account_ecotax_sale/tests/test_sale_ecotax.py +++ b/account_ecotax_sale/tests/test_sale_ecotax.py @@ -2,314 +2,117 @@ # @author Mourad EL HADJ MIMOUNE # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). -from odoo.tests.common import tagged from odoo import Command +from odoo.tests.common import Form -from odoo.addons.account.tests.common import AccountTestInvoicingCommon +from odoo.addons.account_ecotax.tests.test_ecotax import TestInvoiceEcotaxCommon -@tagged("-at_install", "post_install") -class TestsaleEcotax(AccountTestInvoicingCommon): +class TestsaleEcotaxCommon(TestInvoiceEcotaxCommon): @classmethod - def setUpClass(cls, chart_template_ref="l10n_fr.l10n_fr_pcg_chart_template"): - super(TestsaleEcotax, cls).setUpClass(chart_template_ref) - # ACCOUNTING STUFF - # 1- Tax account - cls.invoice_tax_account = cls.env["account.account"].create( + def setUpClass(cls): + super().setUpClass() + cls.product_a = cls.env["product.product"].create( { - "code": "47590", - "name": "Invoice Tax Account", - "account_type": "liability_current", - "company_id": cls.env.user.company_id.id, + "name": "product_a", + "uom_id": cls.env.ref("uom.product_uom_unit").id, + "weight": 100, + "list_price": 200, + "taxes_id": [Command.set(cls.invoice_tax.ids)], } ) - cls.invoice_ecotax_account = cls.env["account.account"].create( + cls.product_b = cls.env["product.product"].create( { - "code": "707120", - "name": "Ecotax Account", - "account_type": "income", - "company_id": cls.env.user.company_id.id, + "name": "product_b", + "uom_id": cls.env.ref("uom.product_uom_unit").id, + "list_price": 200, + "weight": 400, + "taxes_id": [Command.set(cls.invoice_tax.ids)], } ) - # 2- Invoice tax with included price to avoid unwanted amounts in tests - cls.invoice_tax = cls.env["account.tax"].create( - { - "name": "Tax 10%", - "price_include": False, - "type_tax_use": "sale", - "company_id": cls.env.user.company_id.id, - "amount": 10, - "tax_exigibility": "on_invoice", - "invoice_repartition_line_ids": [ - ( - 0, - 0, - { - "factor_percent": 100, - "repartition_type": "base", - }, - ), - ( - 0, - 0, - { - "factor_percent": 100, - "repartition_type": "tax", - "account_id": cls.invoice_tax_account.id, - }, - ), - ], - "refund_repartition_line_ids": [ - ( - 0, - 0, - { - "factor_percent": 100, - "repartition_type": "base", - }, - ), - ( - 0, - 0, - { - "factor_percent": 100, - "repartition_type": "tax", - "account_id": cls.invoice_tax_account.id, - }, - ), - ], - } - ) - # 3 Ecotaxes tax - cls.invoice_fixed_ecotax = cls.env["account.tax"].create( - { - "name": "Fixed Ecotax", - "type_tax_use": "sale", - "company_id": cls.env.user.company_id.id, - "price_include": False, - "amount_type": "code", - "include_base_amount": True, - "sequence": 0, - "is_ecotax": True, - "python_compute": "result = (quantity and" - " product.fixed_ecotax * quantity or 0.0)", - "tax_exigibility": "on_invoice", - "invoice_repartition_line_ids": [ - ( - 0, - 0, - { - "factor_percent": 100, - "repartition_type": "base", - }, - ), - ( - 0, - 0, - { - "factor_percent": 100, - "repartition_type": "tax", - "account_id": cls.invoice_ecotax_account.id, - }, - ), - ], - "refund_repartition_line_ids": [ - ( - 0, - 0, - { - "factor_percent": 100, - "repartition_type": "base", - }, - ), - ( - 0, - 0, - { - "factor_percent": 100, - "repartition_type": "tax", - "account_id": cls.invoice_ecotax_account.id, - }, - ), - ], - } - ) - cls.invoice_weight_based_ecotax = cls.env["account.tax"].create( - { - "name": "Weight Based Ecotax", - "type_tax_use": "sale", - "company_id": cls.env.user.company_id.id, - "amount_type": "code", - "include_base_amount": True, - "price_include": False, - "sequence": 0, - "is_ecotax": True, - "python_compute": "result = (quantity and" - " product.weight_based_ecotax * quantity or 0.0)", - "tax_exigibility": "on_invoice", - "invoice_repartition_line_ids": [ - ( - 0, - 0, - { - "factor_percent": 100, - "repartition_type": "base", - }, - ), - ( - 0, - 0, - { - "factor_percent": 100, - "repartition_type": "tax", - "account_id": cls.invoice_ecotax_account.id, - }, - ), - ], - "refund_repartition_line_ids": [ - ( - 0, - 0, - { - "factor_percent": 100, - "repartition_type": "base", - }, - ), - ( - 0, - 0, - { - "factor_percent": 100, - "repartition_type": "tax", - "account_id": cls.invoice_ecotax_account.id, - }, - ), - ], - } - ) - cls.ecotax_classification = cls.env["account.ecotax.classification"] - cls.ecotax_classification1 = cls.ecotax_classification.create( - { - "name": "Fixed Ecotax", - "ecotax_type": "fixed", - "default_fixed_ecotax": 2.4, - "product_status": "M", - "supplier_status": "MAN", - "sale_ecotax_ids": [(4, cls.invoice_fixed_ecotax.id)], - } - ) - cls.ecotax_classification2 = cls.ecotax_classification.create( - { - "name": "Weight based", - "ecotax_type": "weight_based", - "ecotax_coef": 0.04, - "product_status": "P", - "supplier_status": "MAN", - "sale_ecotax_ids": [(4, cls.invoice_weight_based_ecotax.id)], - } - ) - cls.product_a.weight = 100 - cls.product_a.taxes_id = [Command.set(cls.invoice_tax.ids)] + cls.product_a.ecotax_line_product_ids = [ ( 0, 0, { - "classification_id": cls.ecotax_classification1.id, + # 2.4 + "classification_id": cls.ecotax_fixed.id, }, ) ] - cls.product_b.weight = 400 - cls.product_b.taxes_id = [Command.set(cls.invoice_tax.ids)] cls.product_b.ecotax_line_product_ids = [ ( 0, 0, { - "classification_id": cls.ecotax_classification2.id, + "classification_id": cls.ecotax_weight.id, }, ) ] - def create_sale_partner(self, partner_id, product_id, sale_amount=0.00): - order = self.env["sale.order"].create( - { - "partner_id": partner_id.id, - "order_line": [ - ( - 0, - 0, - { - "product_id": product_id.id, - "product_uom_qty": 1, - "price_unit": sale_amount, - }, - ) - ], - } - ) - order.order_line._compute_tax_id() - order.order_line._compute_ecotax() - return order + def create_sale_partner(self, partner_id, products_and_qty): + sale_form = Form(self.env["sale.order"]) + sale_form.partner_id = partner_id - def test_02_classification_weight_based_ecotax(self): - """Tests multiple lines with weight based ecotaxs""" - # in order to test the correct assignment of fixed ecotax + for product, qty in products_and_qty: + with sale_form.order_line.new() as line_form: + line_form.product_id = product + line_form.product_uom_qty = qty + + sale = sale_form.save() + + return sale + + 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( - sale_amount=200.00, partner_id=partner12, product_id=self.product_b + partner_id=partner12, products_and_qty=[(self.product_b, 1.0)] ) - # I assign a product with fixed ecotaxte to sale line - self.sale_line1 = self.sale.order_line[0] - # make sure to have 1 tax and fix tax rate - self.sale_line1.tax_id = self.sale_line1.tax_id[0] - self.sale_line1.tax_id.amount = 20 - self.sale_line1._onchange_product_ecotax_line() - self.sale_line1._compute_ecotax() - self.sale_line1._compute_amount() - self.sale._compute_amounts() self.assertEqual(self.product_b.ecotax_amount, 16) - self.sale_line1.product_uom_qty = 3 - self.sale_line1._compute_tax_id() - self.sale_line1._compute_ecotax() - self.assertEqual(self.sale_line1.ecotax_amount_unit, 16) - self.assertEqual(self.sale_line1.subtotal_ecotax, 48) - self.assertEqual(self.sale.amount_total, 777.6) + 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, 600) self.assertEqual(self.sale.amount_ecotax, 48) - def test_03_classification_ecotax(self): + def _test_02_classification_ecotax(self): """Tests multiple lines with mixed ecotaxs""" - # in order to test the correct assignment of fixed ecotax + # 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( - sale_amount=100.00, partner_id=partner12, product_id=self.product_a - ) - # add line to SO - self.env["sale.order.line"].create( - { - "product_id": self.product_b.id, - "product_uom_qty": 2, - "price_unit": 100, - "order_id": self.sale.id, - }, + 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 - self.sale_line1 = self.sale.order_line[0] + sale_line1 = self.sale.order_line[0] # make sure to have 1 tax and fix tax rate - self.sale_line2 = self.sale.order_line[1] + sale_line2 = self.sale.order_line[1] # make sure to have 1 tax and fix tax rate - self.sale_line1._onchange_product_ecotax_line() - self.sale_line1._compute_ecotax() - self.assertEqual(self.product_a.ecotax_amount, 2.4) - self.sale_line1.product_uom_qty = 3 - self.sale_line1._onchange_product_ecotax_line() - self.assertEqual(self.sale_line1.ecotax_amount_unit, 2.4) - self.assertAlmostEqual(self.sale_line1.subtotal_ecotax, 7.2) - self.sale_line2._onchange_product_ecotax_line() - self.sale_line1._compute_ecotax() - self.assertEqual(self.sale_line2.ecotax_amount_unit, 16) - self.assertEqual(self.sale_line2.subtotal_ecotax, 32) - self.assertEqual(self.sale.amount_untaxed, 3200.0) - self.assertEqual(self.sale.amount_ecotax, 39.2) + 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, 1000.0) + self.assertEqual(self.sale.amount_ecotax, 47.0) + + +class TestsaleEcotax(TestsaleEcotaxCommon): + def test_01_classification_weight_based_ecotax(self): + self._test_01_classification_weight_based_ecotax() + + def test_02_classification_ecotax(self): + self._test_02_classification_ecotax() diff --git a/account_ecotax_sale/views/sale_view.xml b/account_ecotax_sale/views/sale_view.xml index dfa4bd439..1775d61e1 100644 --- a/account_ecotax_sale/views/sale_view.xml +++ b/account_ecotax_sale/views/sale_view.xml @@ -132,10 +132,14 @@ - + - + diff --git a/account_ecotax_sale_tax/README.rst b/account_ecotax_sale_tax/README.rst new file mode 100644 index 000000000..0c1c81cba --- /dev/null +++ b/account_ecotax_sale_tax/README.rst @@ -0,0 +1,88 @@ +================================= +sale Ecotax Management (as a tax) +================================= + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:731b0e3366890dbeca7db020b75324a2d458308b74991b4ce1d16937c9591178 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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/16.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-16-0/account-fiscal-rule-16-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=16.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..f568e8a49 --- /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": "16.0.2.0.0", + "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/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..ed04d5e9b --- /dev/null +++ b/account_ecotax_sale_tax/models/sale_order_line.py @@ -0,0 +1,58 @@ +# © 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, models + + +class SaleOrderLine(models.Model): + _inherit = "sale.order.line" + + 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(self): + return super()._compute_ecotax() + + @api.depends("product_id", "company_id") + def _compute_tax_id(self): + super()._compute_tax_id() + for line in self: + line.tax_id |= line._get_computed_ecotaxes() + + 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 diff --git a/account_ecotax_sale_tax/readme/CONTRIBUTORS.rst b/account_ecotax_sale_tax/readme/CONTRIBUTORS.rst new file mode 100644 index 000000000..b38466d33 --- /dev/null +++ b/account_ecotax_sale_tax/readme/CONTRIBUTORS.rst @@ -0,0 +1,2 @@ +* Mourad EL HADJ MIMOUNE +* Florian DA COSTA diff --git a/account_ecotax_sale_tax/readme/DESCRIPTION.rst b/account_ecotax_sale_tax/readme/DESCRIPTION.rst new file mode 100644 index 000000000..ad5cc0194 --- /dev/null +++ b/account_ecotax_sale_tax/readme/DESCRIPTION.rst @@ -0,0 +1 @@ +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..b96ef45c4 --- /dev/null +++ b/account_ecotax_sale_tax/static/description/index.html @@ -0,0 +1,426 @@ + + + + + +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..542a514d4 --- /dev/null +++ b/account_ecotax_sale_tax/tests/test_sale_ecotax.py @@ -0,0 +1,19 @@ +# © 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.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() + + def test_01_classification_weight_based_ecotax(self): + self._test_01_classification_weight_based_ecotax() + + def test_02_classification_ecotax(self): + self._test_02_classification_ecotax() 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/setup/account_ecotax_sale_tax/odoo/addons/account_ecotax_sale_tax b/setup/account_ecotax_sale_tax/odoo/addons/account_ecotax_sale_tax new file mode 120000 index 000000000..a8cf4c763 --- /dev/null +++ b/setup/account_ecotax_sale_tax/odoo/addons/account_ecotax_sale_tax @@ -0,0 +1 @@ +../../../../account_ecotax_sale_tax \ No newline at end of file diff --git a/setup/account_ecotax_sale_tax/setup.py b/setup/account_ecotax_sale_tax/setup.py new file mode 100644 index 000000000..28c57bb64 --- /dev/null +++ b/setup/account_ecotax_sale_tax/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)