From c8ff1c689943428a0a88d0d307394e440ca113b1 Mon Sep 17 00:00:00 2001 From: "Jurgen (jugj)" Date: Mon, 13 Feb 2023 11:13:12 +0000 Subject: [PATCH] [IMP] Time-off : Add 5 precision digits to added_value in hr_leave_accrual_plan_level.py task - 3147639 Adding precision digits and displaying the number without unnecessary trailing zeros using JS closes odoo/odoo#115944 X-original-commit: b6c715cc5b39e28b4f40803a5f161845f5b407ab Signed-off-by: Kevin Baptiste --- .../models/hr_leave_accrual_plan_level.py | 2 +- .../src/js/float_without_trailing_zeros.js | 17 +++++++++++++++++ .../views/hr_leave_accrual_views.xml | 4 ++-- 3 files changed, 20 insertions(+), 3 deletions(-) create mode 100644 addons/hr_holidays/static/src/js/float_without_trailing_zeros.js diff --git a/addons/hr_holidays/models/hr_leave_accrual_plan_level.py b/addons/hr_holidays/models/hr_leave_accrual_plan_level.py index bba3f10ad42..f31bcc0b1fa 100644 --- a/addons/hr_holidays/models/hr_leave_accrual_plan_level.py +++ b/addons/hr_holidays/models/hr_leave_accrual_plan_level.py @@ -42,7 +42,7 @@ class AccrualPlanLevel(models.Model): # Accrue of added_value = fields.Float( - "Rate", required=True, + "Rate", digits=(16, 5), required=True, help="The number of hours/days that will be incremented in the specified Time Off Type for every period") added_value_type = fields.Selection( [('days', 'Days'), diff --git a/addons/hr_holidays/static/src/js/float_without_trailing_zeros.js b/addons/hr_holidays/static/src/js/float_without_trailing_zeros.js new file mode 100644 index 00000000000..a2228d60bcd --- /dev/null +++ b/addons/hr_holidays/static/src/js/float_without_trailing_zeros.js @@ -0,0 +1,17 @@ +/** @odoo-module **/ +import FieldRegistry from 'web.field_registry'; +import basic_fields from 'web.basic_fields'; + +var FieldFloat = basic_fields.FieldFloat; + +var FloatWithoutTrailingZeros = FieldFloat.extend({ + _renderReadonly: function () { + var value = this._formatValue(this.value); + var parsed_value = parseFloat(value); + value = parsed_value.toString().replace(/\.0+$/, ''); + this.$el.text(value); + } +}); + +FieldRegistry.add('float_without_trailing_zeros', FloatWithoutTrailingZeros); + diff --git a/addons/hr_holidays/views/hr_leave_accrual_views.xml b/addons/hr_holidays/views/hr_leave_accrual_views.xml index 6dede3372fa..a690ec84bc4 100644 --- a/addons/hr_holidays/views/hr_leave_accrual_views.xml +++ b/addons/hr_holidays/views/hr_leave_accrual_views.xml @@ -157,7 +157,7 @@
- Adds + Adds (based on worked time)
@@ -179,7 +179,7 @@
- Limit of + Limit of
At the end of the year, unused accruals will be postponedlost