[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) <xbo@odoo.com>
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user