Skip to content

Commit

Permalink
[IMP]project_task_recurring_activity: change fields to computed and s…
Browse files Browse the repository at this point in the history
…tored
  • Loading branch information
PicchiSeba committed Oct 4, 2024
1 parent a1a0961 commit 54dab64
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 13 deletions.
33 changes: 20 additions & 13 deletions project_task_recurring_activity/models/recurring_activity.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 == "<p><br></p>"
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 == "<p><br></p>":
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):
Expand Down
17 changes: 17 additions & 0 deletions project_task_recurring_activity/tests/test_project_recurrence.py
Original file line number Diff line number Diff line change
Expand Up @@ -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": "<p><br></p>",
"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"""
Expand Down

0 comments on commit 54dab64

Please sign in to comment.