From da874e053e5d90acfa0267f73ca101a730350b01 Mon Sep 17 00:00:00 2001 From: "Audric Onockx (auon)" Date: Wed, 1 Jun 2022 07:50:23 +0000 Subject: [PATCH] [IMP] project: make orders give them recurrence to the tasks they create On SO confirmation: - If all of the following conditions are met, set the end_date of the Subscription as the repeat_until date of the Task: The Product is recurrent and creates a Task, The Task Template is recurrent, The end_date field is set on the Subscription. - If all of the following conditions are met, apply the Subscription's recurrence to the Task's: The Product is recurrent and creates a Task, There is no Task Template on the Product. - If the Subscription is closed, set the recurring_task field of the related Task to false. task-2868306 closes odoo/odoo#92696 Related: odoo/enterprise#27953 Signed-off-by: Xavier Bol (xbo) --- addons/project/models/project.py | 12 ++++++------ addons/project/models/project_task_recurrence.py | 7 ++++--- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/addons/project/models/project.py b/addons/project/models/project.py index bbf961f4c2c..61a20ffec75 100644 --- a/addons/project/models/project.py +++ b/addons/project/models/project.py @@ -1513,9 +1513,6 @@ 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', @@ -1523,12 +1520,15 @@ 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 = task._get_recurrence_start_date() + delta = task.repeat_interval if task.repeat_unit == 'day' else 1 + if task.recurrence_id and task.recurrence_id.next_recurrence_date > fields.Date.today(): + date = task.recurrence_id.next_recurrence_date + else: + date = fields.Date.today() + timedelta(days=delta) 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 recurring_dates = self.env['project.task.recurrence']._get_next_recurring_dates( - date + timedelta(days=delta), + date, task.repeat_interval, task.repeat_unit, task.repeat_type, diff --git a/addons/project/models/project_task_recurrence.py b/addons/project/models/project_task_recurrence.py index 4bc8ab5c509..55ce3b571ff 100644 --- a/addons/project/models/project_task_recurrence.py +++ b/addons/project/models/project_task_recurrence.py @@ -250,9 +250,10 @@ class ProjectTaskRecurrence(models.Model): new_task = self.env['project.task'].sudo().create(create_values) recurrence._create_subtasks(task, new_task, depth=3) - def _set_next_recurrence_date(self): + def _set_next_recurrence_date(self, date_start=None): today = fields.Date.today() - tomorrow = today + relativedelta(days=1) + if not date_start: + date_start = today + relativedelta(days=1) for recurrence in self.filtered( lambda r: r.repeat_type == 'after' and r.recurrence_left >= 0 @@ -262,7 +263,7 @@ class ProjectTaskRecurrence(models.Model): if recurrence.repeat_type == 'after' and recurrence.recurrence_left == 0: recurrence.next_recurrence_date = False else: - next_date = self._get_next_recurring_dates(tomorrow, recurrence.repeat_interval, recurrence.repeat_unit, recurrence.repeat_type, recurrence.repeat_until, recurrence.repeat_on_month, recurrence.repeat_on_year, recurrence._get_weekdays(), recurrence.repeat_day, recurrence.repeat_week, recurrence.repeat_month, count=1) + next_date = self._get_next_recurring_dates(date_start, recurrence.repeat_interval, recurrence.repeat_unit, recurrence.repeat_type, recurrence.repeat_until, recurrence.repeat_on_month, recurrence.repeat_on_year, recurrence._get_weekdays(), recurrence.repeat_day, recurrence.repeat_week, recurrence.repeat_month, count=1) recurrence.next_recurrence_date = next_date[0] if next_date else False @api.model