Skip to content

Commit e52f922

Browse files
committed
[REF] account_compensate_advance: name_get display info Total and Balance
1 parent 6b4dac5 commit e52f922

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

account_compensate_advance/models/account_move_line.py

+13-6
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@
22
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
33
# flake8: noqa: B950
44

5-
import locale
6-
75
from odoo import _, models
6+
from odoo.tools.misc import formatLang
87

98

109
class AccountMoveLine(models.Model):
@@ -16,19 +15,24 @@ def name_get(self):
1615
Override the name_get method to customize the display name of records based on the context.
1716
"""
1817
context = self._context or {}
19-
locale.setlocale(locale.LC_ALL, self.env.user.lang)
2018

2119
# Customize name display for 'advance_id' based on context
2220
if "advance_id_name_get" in context and context["advance_id_name_get"]:
2321
result = []
2422
balance_str = _("Balance")
2523
for rec in self:
24+
total_str = formatLang(
25+
self.env, abs(rec.price_total), currency_obj=rec.currency_id
26+
)
27+
balance_residual_str = formatLang(
28+
self.env, abs(rec.amount_residual), currency_obj=rec.currency_id
29+
)
2630
# Format name with localized date, total, and balance
2731
name = (
2832
f"{rec.name} | "
2933
f"{_('Date')}: {rec.move_id.date.strftime('%x')} | "
30-
f"{_('Total')}: {locale.format_string('%.2f', abs(rec.price_total), grouping=True)} | "
31-
f"{balance_str}: {locale.format_string('%.2f', abs(rec.amount_residual), grouping=True)}"
34+
f"{_('Total')}: {total_str} | "
35+
f"{balance_str}: {balance_residual_str}"
3236
)
3337
result.append((rec.id, name))
3438
return result
@@ -37,11 +41,14 @@ def name_get(self):
3741
if "line_id_name_get" in context and context["line_id_name_get"]:
3842
result = []
3943
for rec in self:
44+
total_str = formatLang(
45+
self.env, abs(rec.price_total), currency_obj=rec.currency_id
46+
)
4047
# Format name with localized date and total
4148
name = (
4249
f"{rec.name or rec.move_id.name} | "
4350
f"{_('Date')}: {rec.date_maturity.strftime('%x')} | "
44-
f"{_('Total')}: {locale.format_string('%.2f', abs(rec.price_total), grouping=True)}"
51+
f"{_('Total')}: {total_str}"
4552
)
4653
result.append((rec.id, name))
4754
return result

0 commit comments

Comments
 (0)