Skip to content

Commit

Permalink
[FIX] project: company of duplicated task
Browse files Browse the repository at this point in the history
When copying a task, we need its company to be the
one in its new project.

Task-1999686

closes odoo#37108

Signed-off-by: Jérome Maes (jem) <jem@openerp.com>
  • Loading branch information
jem-odoo committed Sep 27, 2019
1 parent a1268c1 commit 05b5084
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
8 changes: 5 additions & 3 deletions addons/project/models/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,30 +249,32 @@ def _compute_rating_request_deadline(self):
project.rating_request_deadline = fields.datetime.now() + timedelta(days=periods.get(project.rating_status_period, 0))

@api.model
def _map_tasks_default_valeus(self, task):
def _map_tasks_default_valeus(self, task, project):
""" get the default value for the copied task on project duplication """
return {
'stage_id': task.stage_id.id,
'name': task.name,
'company_id': project.company_id.id,
}

def map_tasks(self, new_project_id):
""" copy and map tasks from old to new project """
project = self.browse(new_project_id)
tasks = self.env['project.task']
# We want to copy archived task, but do not propagate an active_test context key
task_ids = self.env['project.task'].with_context(active_test=False).search([('project_id', '=', self.id)], order='parent_id').ids
old_to_new_tasks = {}
for task in self.env['project.task'].browse(task_ids):
# preserve task name and stage, normally altered during copy
defaults = self._map_tasks_default_valeus(task)
defaults = self._map_tasks_default_valeus(task, project)
if task.parent_id:
# set the parent to the duplicated task
defaults['parent_id'] = old_to_new_tasks.get(task.parent_id.id, False)
new_task = task.copy(defaults)
old_to_new_tasks[task.id] = new_task.id
tasks += new_task

return self.browse(new_project_id).write({'tasks': [(6, 0, tasks.ids)]})
return project.write({'tasks': [(6, 0, tasks.ids)]})

@api.returns('self', lambda value: value.id)
def copy(self, default=None):
Expand Down
4 changes: 2 additions & 2 deletions addons/sale_timesheet/models/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@ def action_make_billable(self):
}

@api.model
def _map_tasks_default_valeus(self, task):
defaults = super(Project, self)._map_tasks_default_valeus(task)
def _map_tasks_default_valeus(self, task, project):
defaults = super(Project, self)._map_tasks_default_valeus(task, project)
defaults['sale_line_id'] = False
return defaults

Expand Down
1 change: 0 additions & 1 deletion addons/sale_timesheet/models/sale_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ def _action_confirm(self):
""" On SO confirmation, some lines should generate a task or a project. """
result = super(SaleOrder, self)._action_confirm()
self.mapped('order_line').sudo().with_context(
default_company_id=self.company_id.id,
force_company=self.company_id.id,
)._timesheet_service_generation()
return result
Expand Down

0 comments on commit 05b5084

Please sign in to comment.