[FIX] project: remove onchange on date/date_end for projects

Steps
=====
- Install module project
- Open the form view of a project
- Set a planned date
- Click anywhere on the page to remove the focus from the date picker

Issue
=====
The chosen date disappeared without any explanation to the user

Cause
=====
odoo#123268 introduced some changes related
to the planned dates of projects.
1. the write method is modified to avoid the write of only a start/end
date (both date should be set or none of them)
2. a required is added on the start date field in the form view of
project
3. an onchange is added to avoid to have one of both field set and not
the other

This last change is problematic as it overrides the required behavior of
the date fields.

On top of that, https://github.com/odoo/odoo/pull/143509 changed the
behavior of the datepicker widget that only display the full range by
default if both fields are required (which is not the case here if they
are empty).

The combination of those changes have the consequence that the planned
date field is unusable in the form view of projects.

Fix
===
The onchange being only useful in form view, it is deprecated as the
required attribute is sufficient for this usecase and provide the user
warnings if he forget a field. On top of that a required attribute is
also set on the end date field.

task-3628069

closes odoo/odoo#145167

Related: odoo/enterprise#52280
Signed-off-by: Julien Mougenot (jum) <jum@odoo.com>
This commit is contained in:
Hugo Carlier (Huca)
2024-01-03 10:58:02 +00:00
parent bc98aad620
commit e9127a9fdf
2 changed files with 5 additions and 8 deletions
+2 -4
View File
@@ -378,12 +378,10 @@ class Project(models.Model):
else:
project.access_instruction_message = ''
# TODO: Remove in master
@api.onchange('date_start', 'date')
def _onchange_planned_date(self):
if not self.date and self.date_start:
self.date_start = False
elif not self.date_start and self.date:
self.date = False
return
@api.model
def _map_tasks_default_valeus(self, task, project):
@@ -87,8 +87,8 @@
<group>
<field name="active" invisible="1"/>
<field name="user_id" string="Project Manager" widget="many2one_avatar_user" readonly="not active" domain="[('share', '=', False)]" options="{'no_quick_create': True}"/>
<field name="date_start" string="Planned Date" widget="daterange" options='{"end_date_field": "date"}' required="date_start or date" />
<field name="date" invisible="1" />
<field name="date_start" string="Planned Date" widget="daterange" options='{"end_date_field": "date", "always_range": "1"}' required="date_start or date" />
<field name="date" invisible="1" required="date_start"/>
</group>
</group>
<notebook>
@@ -230,8 +230,7 @@
<field name="partner_id" optional="show" string="Customer"/>
<field name="company_id" optional="show" groups="base.group_multi_company" options="{'no_create': True, 'no_open': True}"/>
<field name="company_id" column_invisible="True"/>
<!-- XBO: required modifiers contains a falsy domain to be able to display the daterange without any button to set the date_end -->
<field name="date_start" string="Planned Date" widget="daterange" options="{'end_date_field': 'date'}" required="False" optional="hide"/>
<field name="date_start" string="Planned Date" widget="daterange" options="{'end_date_field': 'date', 'always_range': '1'}" optional="hide"/>
<field name="date" column_invisible="True" />
<field name="user_id" optional="show" string="Project Manager" widget="many2one_avatar_user" options="{'no_open':True, 'no_create': True, 'no_create_edit': True}"/>
<field name="last_update_color" column_invisible="True"/>