2
2
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
3
3
# flake8: noqa: B950
4
4
5
- import locale
6
-
7
5
from odoo import _ , models
6
+ from odoo .tools .misc import formatLang
8
7
9
8
10
9
class AccountMoveLine (models .Model ):
@@ -16,19 +15,24 @@ def name_get(self):
16
15
Override the name_get method to customize the display name of records based on the context.
17
16
"""
18
17
context = self ._context or {}
19
- locale .setlocale (locale .LC_ALL , self .env .user .lang )
20
18
21
19
# Customize name display for 'advance_id' based on context
22
20
if "advance_id_name_get" in context and context ["advance_id_name_get" ]:
23
21
result = []
24
22
balance_str = _ ("Balance" )
25
23
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
+ )
26
30
# Format name with localized date, total, and balance
27
31
name = (
28
32
f"{ rec .name } | "
29
33
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 } "
32
36
)
33
37
result .append ((rec .id , name ))
34
38
return result
@@ -37,11 +41,14 @@ def name_get(self):
37
41
if "line_id_name_get" in context and context ["line_id_name_get" ]:
38
42
result = []
39
43
for rec in self :
44
+ total_str = formatLang (
45
+ self .env , abs (rec .price_total ), currency_obj = rec .currency_id
46
+ )
40
47
# Format name with localized date and total
41
48
name = (
42
49
f"{ rec .name or rec .move_id .name } | "
43
50
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 } "
45
52
)
46
53
result .append ((rec .id , name ))
47
54
return result
0 commit comments