[IMP] web: Optional start date in daterange fields

Before this commit, the date/datetime/daterange fields only allowed for
an optional end date field. This meant that the primary date was always
the start date.

This commit allows the field to do the opposite: with the primary date
being the end date, and having a `start_date_field` option for an
optional start date.

closes odoo/odoo#120695

Signed-off-by: Michaël Mattiello <mcm@odoo.com>
This commit is contained in:
Julien Mougenot
2023-05-11 09:36:24 +02:00
parent 3952fbd15f
commit 805197daf9
4 changed files with 153 additions and 34 deletions
+4 -3
View File
@@ -233,15 +233,16 @@ class Form:
field_info['type'] = node.get('widget')
elif node.get('widget') == 'daterange':
options = ast.literal_eval(node.get('options', '{}'))
daterange_field_names[options.get('end_date_field')] = field_name
related_field = options.get('start_date_field') or options.get('end_date_field')
daterange_field_names[related_field] = field_name
# determine subview to use for edition
if level and field_info['type'] == 'one2many':
field_info['invisible'] = field_modifiers.get('invisible') == [TRUE_LEAF]
field_info['edition_view'] = self._get_one2many_edition_view(field_info, node, level)
for end_field, start_field in daterange_field_names.items():
modifiers[end_field]['invisible'] = modifiers[start_field].get('invisible', False)
for related_field, start_field in daterange_field_names.items():
modifiers[related_field]['invisible'] = modifiers[start_field].get('invisible', False)
view['onchange'] = model._onchange_spec({'arch': etree.tostring(tree)})