From 138f584bd1e333ef1767b079b9de1cfa323ba3af Mon Sep 17 00:00:00 2001 From: PicchiSeba Date: Thu, 26 Sep 2024 09:33:59 +0200 Subject: [PATCH] [IMP]project_task_recurring_activity: change fields to computed and stored --- .../models/recurring_activity.py | 33 +++++++++++-------- .../tests/test_project_recurrence.py | 17 ++++++++++ 2 files changed, 37 insertions(+), 13 deletions(-) diff --git a/project_task_recurring_activity/models/recurring_activity.py b/project_task_recurring_activity/models/recurring_activity.py index 7b8b0c3328..e21ce0d5f9 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,12 @@ 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.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"""