[IMP] base: support decimalized in integer qweb formatting

Purpose of this commit is to allow decimalized formatting of numbers when
rendering integer fields in qweb. This is done through an option and will
be used notably in elearning.

Task-2607416

Part-of: odoo/odoo#74171
This commit is contained in:
Thibault Delavallée
2022-02-28 11:07:39 +00:00
parent 2a3d8dd1c2
commit e50bc749f6
+11 -1
View File
@@ -10,7 +10,7 @@ from markupsafe import Markup as M, escape
from PIL import Image
from lxml import etree, html
from odoo import api, fields, models, _, _lt
from odoo import api, fields, models, _, _lt, tools
from odoo.tools import posix_to_ldml, float_utils, format_date, format_duration, pycompat
from odoo.tools.mail import safe_attrs
from odoo.tools.misc import get_lang, babel_locale_parse
@@ -136,8 +136,18 @@ class IntegerConverter(models.AbstractModel):
_description = 'Qweb Field Integer'
_inherit = 'ir.qweb.field'
@api.model
def get_available_options(self):
options = super(IntegerConverter, self).get_available_options()
options.update(
format_decimalized_number=dict(type='boolean', string=_('Decimalized number')),
)
return options
@api.model
def value_to_html(self, value, options):
if options.get('format_decimalized_number'):
return tools.format_decimalized_number(value)
return pycompat.to_text(self.user_lang().format('%d', value, grouping=True).replace(r'-', '-\N{ZERO WIDTH NO-BREAK SPACE}'))