[FIX] base: cannot specify 24-hour clock format and meridian
- Settings > manage languages > english > Set time format to `%H:%M:%S %p` > Save - Install Planning app > go to list view > Try modifying a time manually (without using the widget which pops up). Issue: When trying to save the new time, an error pops up: `Can't include meridiem when specifying 24-hour format`. While parsing the new date, the `luxon` library throws this error to prevent wrong hour values, such as `17 AM`. Fix: Prevent the user from inputting both `%H` and `%p` in the same time format and display a warning notification. opw-3038797 closes odoo/odoo#106926 X-original-commit: c2b8faa1c89dc16094c1ebec397e935a3b46fac4 Signed-off-by: Xavier Morel (xmo) <xmo@odoo.com> Signed-off-by: Stefan-Calin Crainiciuc (stcc) <stcc@odoo.com>
This commit is contained in:
@@ -81,6 +81,23 @@ class Lang(models.Model):
|
||||
'Please refer to the list of allowed directives, '
|
||||
'displayed when you edit a language.'))
|
||||
|
||||
@api.onchange('time_format', 'date_format')
|
||||
def _onchange_format(self):
|
||||
warning = {
|
||||
'warning': {
|
||||
'title': _("Using 24-hour clock format with AM/PM can cause issues."),
|
||||
'message': _("Changing to 12-hour clock format instead."),
|
||||
'type': 'notification'
|
||||
}
|
||||
}
|
||||
for lang in self:
|
||||
if lang.date_format and "%H" in lang.date_format and "%p" in lang.date_format:
|
||||
lang.date_format = lang.date_format.replace("%H", "%I")
|
||||
return warning
|
||||
if lang.time_format and "%H" in lang.time_format and "%p" in lang.time_format:
|
||||
lang.time_format = lang.time_format.replace("%H", "%I")
|
||||
return warning
|
||||
|
||||
@api.constrains('grouping')
|
||||
def _check_grouping(self):
|
||||
warning = _('The Separator Format should be like [,n] where 0 < n :starting from Unit digit. '
|
||||
|
||||
Reference in New Issue
Block a user