Skip to content

Commit

Permalink
[REF] Split account_ecotax_sale into account_ecotax_sale and account_…
Browse files Browse the repository at this point in the history
…ecotax_sale_tax
  • Loading branch information
florian-dacosta committed Nov 25, 2024
1 parent 75b16d2 commit 47cde9a
Show file tree
Hide file tree
Showing 22 changed files with 745 additions and 316 deletions.
15 changes: 14 additions & 1 deletion account_ecotax_sale/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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**

Expand Down Expand Up @@ -57,6 +57,8 @@ Contributors
~~~~~~~~~~~~

* Mourad EL HADJ MIMOUNE <[email protected]>
* Florian DA COSTA <[email protected]>


Maintainers
~~~~~~~~~~~
Expand All @@ -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 <https://odoo-community.org/page/maintainer-role>`__:

|maintainer-mourad-ehm| |maintainer-florian-dacosta|

This module is part of the `OCA/account-fiscal-rule <https://github.com/OCA/account-fiscal-rule/tree/16.0/account_ecotax_sale>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
1 change: 1 addition & 0 deletions account_ecotax_sale/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
56 changes: 12 additions & 44 deletions account_ecotax_sale/models/sale_order_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 = {
Expand Down
2 changes: 2 additions & 0 deletions account_ecotax_sale/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
* Mourad EL HADJ MIMOUNE <[email protected]>
* Florian DA COSTA <[email protected]>

2 changes: 1 addition & 1 deletion account_ecotax_sale/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -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.
5 changes: 4 additions & 1 deletion account_ecotax_sale/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ <h1 class="title">sale Ecotax Management</h1>
!! source digest: sha256:731b0e3366890dbeca7db020b75324a2d458308b74991b4ce1d16937c9591178
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/account-fiscal-rule/tree/16.0/account_ecotax_sale"><img alt="OCA/account-fiscal-rule" src="https://img.shields.io/badge/github-OCA%2Faccount--fiscal--rule-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/account-fiscal-rule-16-0/account-fiscal-rule-16-0-account_ecotax_sale"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/account-fiscal-rule&amp;target_branch=16.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p>This module is an extension of the module <em>l10n_fr_ecotax</em> for sale orders. Please refer to the README of the module <em>l10n_fr_ecotax</em> for more info about ecotax management.</p>
<p>This module is an extension of the module <em>l10n_fr_ecotax</em> for sale orders. Please refer to the README of the module <em>account_ecotax</em> for more info about ecotax management.</p>
<p><strong>Table of contents</strong></p>
<div class="contents local topic" id="contents">
<ul class="simple">
Expand Down Expand Up @@ -403,6 +403,7 @@ <h2><a class="toc-backref" href="#toc-entry-3">Authors</a></h2>
<h2><a class="toc-backref" href="#toc-entry-4">Contributors</a></h2>
<ul class="simple">
<li>Mourad EL HADJ MIMOUNE &lt;<a class="reference external" href="mailto:mourad.elhadj.mimoune&#64;akretion.com">mourad.elhadj.mimoune&#64;akretion.com</a>&gt;</li>
<li>Florian DA COSTA &lt;<a class="reference external" href="mailto:florian.dacosta&#64;akretion.com">florian.dacosta&#64;akretion.com</a>&gt;</li>
</ul>
</div>
<div class="section" id="maintainers">
Expand All @@ -414,6 +415,8 @@ <h2><a class="toc-backref" href="#toc-entry-5">Maintainers</a></h2>
<p>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.</p>
<p>Current <a class="reference external" href="https://odoo-community.org/page/maintainer-role">maintainers</a>:</p>
<p><a class="reference external image-reference" href="https://github.com/mourad-ehm"><img alt="mourad-ehm" src="https://github.com/mourad-ehm.png?size=40px" /></a> <a class="reference external image-reference" href="https://github.com/florian-dacosta"><img alt="florian-dacosta" src="https://github.com/florian-dacosta.png?size=40px" /></a></p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/account-fiscal-rule/tree/16.0/account_ecotax_sale">OCA/account-fiscal-rule</a> project on GitHub.</p>
<p>You are welcome to contribute. To learn how please visit <a class="reference external" href="https://odoo-community.org/page/Contribute">https://odoo-community.org/page/Contribute</a>.</p>
</div>
Expand Down
Loading

0 comments on commit 47cde9a

Please sign in to comment.