[FIX] sale_timesheet: sale order line of subtasks
We want to set the sale line of the parent when changing the subtasks parent but not force changing it when modifying the SO line of the parent task, and we have to reset (empty) so line on subtasks when changing the customer of a task to avoid no seeing the current SO line in its domain (dropdown) since the customer has changed. Task #34703
This commit is contained in:
@@ -109,6 +109,13 @@ class ProjectTask(models.Model):
|
||||
self.partner_id = self.sale_line_id.order_partner_id
|
||||
return result
|
||||
|
||||
@api.onchange('partner_id')
|
||||
def _onchange_partner_id(self):
|
||||
result = super(ProjectTask, self)._onchange_partner_id()
|
||||
if self.sale_line_id.order_partner_id != self.partner_id:
|
||||
self.sale_line_id = False
|
||||
return result
|
||||
|
||||
@api.multi
|
||||
@api.constrains('sale_line_id')
|
||||
def _check_sale_line_type(self):
|
||||
@@ -152,6 +159,28 @@ class ProjectTask(models.Model):
|
||||
raise ValidationError(_('You have to unlink the task from the sale order item in order to delete it.'))
|
||||
return super(ProjectTask, self).unlink()
|
||||
|
||||
# ---------------------------------------------------
|
||||
# Subtasks
|
||||
# ---------------------------------------------------
|
||||
|
||||
@api.model
|
||||
def _subtask_implied_fields(self):
|
||||
result = super(ProjectTask, self)._subtask_implied_fields()
|
||||
return result + ['sale_line_id']
|
||||
|
||||
def _subtask_write_values(self, values):
|
||||
result = super(ProjectTask, self)._subtask_write_values(values)
|
||||
# changing the partner on a task will reset the sale line of its subtasks
|
||||
if 'partner_id' in result:
|
||||
result['sale_line_id'] = False
|
||||
elif 'sale_line_id' in result:
|
||||
result.pop('sale_line_id')
|
||||
return result
|
||||
|
||||
# ---------------------------------------------------
|
||||
# Actions
|
||||
# ---------------------------------------------------
|
||||
|
||||
@api.multi
|
||||
def action_view_so(self):
|
||||
self.ensure_one()
|
||||
|
||||
Reference in New Issue
Block a user