From e246bf1448fa56522d372449c76255cb591a0354 Mon Sep 17 00:00:00 2001 From: MAHAMADASIF ANSARI Date: Tue, 5 Apr 2022 10:29:47 +0000 Subject: [PATCH 1/2] [IMP] base: allow to specify decimal points with `format_decimalized_number` Currently, we can format the number into decimal points with help of the `format_decimalized_number` option of `ir.qweb.field.integer` class. However, sometimes we need to decide how many decimal points we need to display, which is not possible with current implementation. This commit improves the above option and now allows to pass the number of decimal points, with a new option `precision_digits`, which defaults to one decimal point. task-2792149 Part-of: odoo/odoo#87996 --- odoo/addons/base/models/ir_qweb_fields.py | 3 ++- odoo/addons/base/tests/test_qweb_field.py | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/odoo/addons/base/models/ir_qweb_fields.py b/odoo/addons/base/models/ir_qweb_fields.py index 5bf43e581ad..cdc8fd1cc78 100644 --- a/odoo/addons/base/models/ir_qweb_fields.py +++ b/odoo/addons/base/models/ir_qweb_fields.py @@ -142,13 +142,14 @@ class IntegerConverter(models.AbstractModel): options = super(IntegerConverter, self).get_available_options() options.update( format_decimalized_number=dict(type='boolean', string=_('Decimalized number')), + precision_digits=dict(type='integer', string=_('Precision Digits')), ) return options @api.model def value_to_html(self, value, options): if options.get('format_decimalized_number'): - return tools.format_decimalized_number(value) + return tools.format_decimalized_number(value, options.get('precision_digits', 1)) return pycompat.to_text(self.user_lang().format('%d', value, grouping=True).replace(r'-', '-\N{ZERO WIDTH NO-BREAK SPACE}')) diff --git a/odoo/addons/base/tests/test_qweb_field.py b/odoo/addons/base/tests/test_qweb_field.py index 2320c474c56..4fb7823dcff 100644 --- a/odoo/addons/base/tests/test_qweb_field.py +++ b/odoo/addons/base/tests/test_qweb_field.py @@ -42,3 +42,17 @@ class TestQwebFieldTime(common.TransactionCase): # Only values inferior to 24 can be used with self.assertRaises(ValueError): self.value_to_html(24) + + +class TestQwebFieldInteger(common.TransactionCase): + def value_to_html(self, value, options=None): + options = options or {} + return self.env['ir.qweb.field.integer'].value_to_html(value, options) + + def test_integer_value_to_html(self): + self.assertEqual(self.value_to_html(1000), "1,000") + self.assertEqual(self.value_to_html(1000000, {'format_decimalized_number': True}), "1M") + self.assertEqual( + self.value_to_html(125125, {'format_decimalized_number': True, 'precision_digits': 3}), + "125.125k" + ) From 1e2d8cf44a5587c7a2f0934bc1760b3a0e16bdf0 Mon Sep 17 00:00:00 2001 From: MAHAMADASIF ANSARI Date: Mon, 2 May 2022 04:25:39 +0000 Subject: [PATCH 2/2] [IMP] base: website_profile: improve the rank layout Currently if a user is having huge number of karma/xp (for example 10000), when viewing the website profile, these numbers overlap the design of a next rank layout card. This commit formats the karma/xp into decimal number (allowing up to two decimal points so that the information is meaningful) and thus reducing the space being occupied by large numbers. task-2792149 Part-of: odoo/odoo#87996 --- addons/website_profile/views/website_profile.xml | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/addons/website_profile/views/website_profile.xml b/addons/website_profile/views/website_profile.xml index b4aa9625c46..78673e78e5d 100644 --- a/addons/website_profile/views/website_profile.xml +++ b/addons/website_profile/views/website_profile.xml @@ -339,9 +339,15 @@ - / - - + / + + xp