From 67c8a60affea6077e5c386b6bf93d02f30201b47 Mon Sep 17 00:00:00 2001 From: jem-odoo Date: Fri, 3 Aug 2018 16:54:47 +0200 Subject: [PATCH] [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 --- addons/sale_timesheet/models/project.py | 29 +++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/addons/sale_timesheet/models/project.py b/addons/sale_timesheet/models/project.py index b8a1f0fc50f..0d06a4d069d 100644 --- a/addons/sale_timesheet/models/project.py +++ b/addons/sale_timesheet/models/project.py @@ -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()