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 OCA#1283
  • Loading branch information
abenzbiria committed May 17, 2024
1 parent af8d36a commit 9251e0f
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
19 changes: 19 additions & 0 deletions project_milestone/models/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,22 @@ 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):
default = dict(default or {})
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, )



1 change: 1 addition & 0 deletions project_milestone/models/project_milestone.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,4 @@ def _compute_milestone_progress(self):
record.progress = (closed_tasks_count / total_tasks_count) * 100
else:
record.progress = 0.0

1 change: 1 addition & 0 deletions project_milestone/views/project.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
</field>
</record>
<!-- Form View -->

<record id="project_enhancement_milestone_view_inherit_form" model="ir.ui.view">
<field name="name">project.milestone.form</field>
<field name="model">project.project</field>
Expand Down

0 comments on commit 9251e0f

Please sign in to comment.