From 72fc3f6a1b2f62315155a3d3acbabde41fd5da57 Mon Sep 17 00:00:00 2001 From: SilvioC2C Date: Wed, 2 Jul 2025 13:06:19 +0200 Subject: [PATCH] [UPD] account_ecotax: implement ecotax.line.mixin.display_name --- account_ecotax/models/ecotax_line_mixin.py | 26 +++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/account_ecotax/models/ecotax_line_mixin.py b/account_ecotax/models/ecotax_line_mixin.py index 1e9e10696..21da01e7f 100644 --- a/account_ecotax/models/ecotax_line_mixin.py +++ b/account_ecotax/models/ecotax_line_mixin.py @@ -2,7 +2,7 @@ # @author Mourad EL HADJ MIMOUNE # 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): @@ -63,3 +63,27 @@ def _compute_ecotax(self): 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 " ()". + + 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): + # ``precision_get()`` calls are cached + dp = self.env["decimal.precision"].precision_get("Ecotax") + return f"%.{dp}f" % amt + + groups = self.grouped(lambda x: (x.classification_id, x.currency_id)) + 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 + for line in lines: + amount = line.amount_total or 0.00 + line.display_name = f"{ecotax_name} ({amt_format(amount)})"