diff --git a/project_task_recurring_activity/models/recurring_activity.py b/project_task_recurring_activity/models/recurring_activity.py index 7b8b0c3328..0a3e7f523b 100644 --- a/project_task_recurring_activity/models/recurring_activity.py +++ b/project_task_recurring_activity/models/recurring_activity.py @@ -17,9 +17,21 @@ class RecurringActivity(models.Model): string="Assigned to", index=True, required=True, + compute="_compute_on_activity_type_id", + store=True, + readonly=False, + ) + summary = fields.Char( + compute="_compute_on_activity_type_id", + store=True, + readonly=False, + ) + description = fields.Html( + sanitize_style=True, + compute="_compute_on_activity_type_id", + store=True, + readonly=False, ) - summary = fields.Char() - description = fields.Html(sanitize_style=True) days_after_task_creation_date = fields.Integer() next_recurrence_date = fields.Date( string="next_date", compute="_compute_next_recurrence_date", store=True @@ -66,17 +78,14 @@ def _check_user_id(self): ) ) - @api.onchange("activity_type_id") - def _onchange_activity_type_id(self): - self.user_id = ( - self.user_id if self.user_id else self.activity_type_id.default_user_id - ) - self.description = ( - self.activity_type_id.default_note - if not self.description or self.description == "


" - else self.description - ) - self.summary = self.summary if self.summary else self.activity_type_id.summary + @api.depends("activity_type_id") + def _compute_on_activity_type_id(self): + if not self.user_id: + self.user_id = self.activity_type_id.default_user_id + if (not self.description) or self.description == "


": + self.description = self.activity_type_id.default_note + if not self.summary: + self.summary = self.activity_type_id.summary @api.model def delta_time(self, old, new): diff --git a/project_task_recurring_activity/tests/test_project_recurrence.py b/project_task_recurring_activity/tests/test_project_recurrence.py index 6d9eb09403..6096986445 100644 --- a/project_task_recurring_activity/tests/test_project_recurrence.py +++ b/project_task_recurring_activity/tests/test_project_recurrence.py @@ -220,6 +220,23 @@ def test_recurrence_cron_repeat_forever(self): self.assertEqual( len(tasks.mapped("recurring_activity_ids")), 4, "Must be equal to 4" ) + project_task = tasks[0] + activity = self.recurring_activity.search( + [("project_task_id", "=", project_task.id)] + ) + self.assertEqual(activity.user_id, self.mail_activity_a.default_user_id) + self.assertEqual(activity.summary, project_task.activity_summary) + activity.write( + { + "description": "


", + "summary": None, + "activity_type_id": self.mail_activity_b.id, + } + ) + activity._compute_on_activity_type_id() + self.assertEqual(activity.user_id, self.mail_activity_a.default_user_id) + self.assertEqual(activity.description, self.mail_activity_b.default_note) + self.assertEqual(activity.summary, self.mail_activity_b.summary) def test_create_recurring_tasks(self): """Check custom method dev"""