[IMP] project: Remove a shared stage if no linked record inside this project
Purpose
=======
Projects may have share columns. If we want to delete a stage on a project there's several use case
Specification
=============
Different use cases:
- The stage is shared
- There's no task in this stage for this project: Remove the stage from this project, don't delete it
- There's a task in this stage (Active or not): Raise an error from the ondelete restrict
- The stage is not shared
- There's no task in this stage: Delete the stage (unlink)
- There's a task in this stage (Active or not): Raise an error from the ondelete restrict
This commit is contained in:
committed by
Yannick Tivisse
parent
05fc6f52d0
commit
e25d0b3891
@@ -52,6 +52,18 @@ class ProjectTaskType(models.Model):
|
||||
" * A good feedback from the customer will update the kanban state to 'ready for the new stage' (green bullet).\n"
|
||||
" * A medium or a bad feedback will set the kanban state to 'blocked' (red bullet).\n")
|
||||
|
||||
@api.multi
|
||||
def unlink(self):
|
||||
stages = self
|
||||
default_project_id = self.env.context.get('default_project_id')
|
||||
if default_project_id:
|
||||
shared_stages = self.filtered(lambda x: len(x.project_ids) > 1 and default_project_id in x.project_ids.ids)
|
||||
tasks = self.env['project.task'].with_context(active_test=False).search([('project_id', '=', default_project_id), ('stage_id', 'in', self.ids)])
|
||||
if shared_stages and not tasks:
|
||||
shared_stages.write({'project_ids': [(3, default_project_id)]})
|
||||
stages = self.filtered(lambda x: x not in shared_stages)
|
||||
return super(ProjectTaskType, stages).unlink()
|
||||
|
||||
|
||||
class Project(models.Model):
|
||||
_name = "project.project"
|
||||
|
||||
Reference in New Issue
Block a user