[FIX] project: Calculate the right task next occurrences dates

Steps to reproduce:

  - Install "Field Service" module
  - Go to settings and activate "Recurring Tasks"
  - Go to Field Service -> All tasks and create new one
  - Set for Planned Date : 10/01/2021 14:00 -> 10/02/2021 14:30
  - Check Recurrent and go to Recurrence tab
  - Select repeat every 1 weeks
  - Select Monday

Issue:

  Wrong date for next occurrences (first occurrence is 09/06 instead
  of 10/04).

Cause:

  Calculation based on today date.

Solution:

  Calculate next occurrences based on planned_start_date if set.

opw-2628777

closes odoo/odoo#76092

X-original-commit: 86060f9426eef6516db6dda7829ae17050f0fcc3
Related: odoo/enterprise#20659
Signed-off-by: LTU-Odoo <IT-Ideas@users.noreply.github.com>
Signed-off-by: bon-odoo <nboulif@users.noreply.github.com>
This commit is contained in:
Nasreddin Boulif (bon)
2021-09-07 15:50:28 +00:00
parent 3ee10159db
commit dfc853aaad
+4 -1
View File
@@ -1218,6 +1218,9 @@ class Task(models.Model):
return [fn(n) for day, fn in DAYS.items() if self[day]]
return [DAYS.get(self.repeat_weekday)(n)]
def _get_recurrence_start_date(self):
return fields.Date.today()
@api.depends(
'recurring_task', 'repeat_interval', 'repeat_unit', 'repeat_type', 'repeat_until',
'repeat_number', 'repeat_on_month', 'repeat_on_year', 'mon', 'tue', 'wed', 'thu', 'fri',
@@ -1225,7 +1228,7 @@ class Task(models.Model):
def _compute_recurrence_message(self):
self.recurrence_message = False
for task in self.filtered(lambda t: t.recurring_task and t._is_recurrence_valid()):
date = fields.Date.today()
date = self._get_recurrence_start_date()
recurrence_left = task.recurrence_id.recurrence_left if task.recurrence_id else task.repeat_number
number_occurrences = min(5, recurrence_left if task.repeat_type == 'after' else 5)
delta = task.repeat_interval if task.repeat_unit == 'day' else 1