Skip to content

Commit

Permalink
[14.0][FIX] project_milestone : Wrong assignment of tasks to mileston…
Browse files Browse the repository at this point in the history
…es when duplicating a project #1283

[14.0][FIX] project_milestone : Wrong assignment of tasks to milestones when duplicating a project #1283

[14.0][FIX] project_milestone : Wrong assignment of tasks to milestones when duplicating a project #1283

[14.0][FIX] project_milestone : Wrong assignment of tasks to milestones when duplicating a project #1283

[14.0][FIX] project_milestone : Wrong assignment of tasks to milestones when duplicating a project #1283

Update test_project_milestone.py

Update test_project_milestone.py
  • Loading branch information
abenzbiria committed Aug 30, 2024
1 parent af8d36a commit 0ee5327
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
22 changes: 22 additions & 0 deletions project_milestone/models/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,25 @@ class Project(models.Model):
def _onchange_use_milestones(self):
if not self.use_milestones and self.milestones_required:
self.milestones_required = False

@api.returns("self", lambda value: value.id)
def copy(self, default=None):
project = super(Project, self).copy(default)
project._link_tasks_to_milestones()
return project

def _link_tasks_to_milestones(self):
for task in self.with_context(active_test=False).task_ids.filtered(
"milestone_id"
):
task.milestone_id = self._find_equivalent_milestone(task.milestone_id)

def _find_equivalent_milestone(self, milestone):
return next(
(
m
for m in self.with_context(active_test=False).milestone_ids
if m.name == milestone.name
),
None,
)
9 changes: 9 additions & 0 deletions project_milestone/tests/test_project_milestone.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,12 @@ def test_sub_task(self):
with Form(Task) as task:
task.project_id = self.test_project
task.name = "SubTask"

def test_copy_project(self):
project = self.test_project.copy({})
tasks = project.with_context(active_test=False).task_ids
milestone = project.milestone_ids.filtered(
lambda milestone: "2" not in milestone.name
)
self.assertEqual(tasks[0].milestone_id, milestone)
self.assertEqual(tasks[1].milestone_id, milestone)

0 comments on commit 0ee5327

Please sign in to comment.