Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion account_ecotax/models/ecotax_line_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# @author Mourad EL HADJ MIMOUNE <[email protected]>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from odoo import api, fields, models
from odoo import _, api, fields, models


class EcotaxLineMixin(models.AbstractModel):
Expand Down Expand Up @@ -63,3 +63,27 @@
if ecotaxline.currency_id:
total = ecotaxline.currency_id.round(total)
ecotaxline.amount_total = total

@api.depends("classification_id.name", "currency_id", "amount_total")
def _compute_display_name(self):
"""Define ``display_name`` for ecotax lines

Records are displayed as "<classification name> (<total amount formatted>)".

If the line has no classification, "Undefined" is used as classification name.
The total amount is formatted according to the currency; if a line has no
currency, the "Ecotax" decimal precision is used to format the amount.
"""

def _default_amt_format(amt: float):

Check warning on line 78 in account_ecotax/models/ecotax_line_mixin.py

View check run for this annotation

Codecov / codecov/patch

account_ecotax/models/ecotax_line_mixin.py#L78

Added line #L78 was not covered by tests
# ``precision_get()`` calls are cached
dp = self.env["decimal.precision"].precision_get("Ecotax")
return f"%.{dp}f" % amt

Check warning on line 81 in account_ecotax/models/ecotax_line_mixin.py

View check run for this annotation

Codecov / codecov/patch

account_ecotax/models/ecotax_line_mixin.py#L80-L81

Added lines #L80 - L81 were not covered by tests

groups = self.grouped(lambda x: (x.classification_id, x.currency_id))

Check warning on line 83 in account_ecotax/models/ecotax_line_mixin.py

View check run for this annotation

Codecov / codecov/patch

account_ecotax/models/ecotax_line_mixin.py#L83

Added line #L83 was not covered by tests
for (ecotax, currency), lines in groups.items():
ecotax_name = ecotax.name if ecotax else _("Undefined")
amt_format = currency.format if currency else _default_amt_format

Check warning on line 86 in account_ecotax/models/ecotax_line_mixin.py

View check run for this annotation

Codecov / codecov/patch

account_ecotax/models/ecotax_line_mixin.py#L85-L86

Added lines #L85 - L86 were not covered by tests
for line in lines:
amount = line.amount_total or 0.00
line.display_name = f"{ecotax_name} ({amt_format(amount)})"

Check warning on line 89 in account_ecotax/models/ecotax_line_mixin.py

View check run for this annotation

Codecov / codecov/patch

account_ecotax/models/ecotax_line_mixin.py#L88-L89

Added lines #L88 - L89 were not covered by tests