Skip to content

Commit

Permalink
Merge PR #1284 into 14.0
Browse files Browse the repository at this point in the history
Signed-off-by dreispt
  • Loading branch information
OCA-git-bot committed Sep 12, 2024
2 parents 4f55892 + 0ee5327 commit 999c349
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 999c349

Please sign in to comment.