From f83237d3c68e71eec5ddbce0d072419cedb2d523 Mon Sep 17 00:00:00 2001 From: "Xavier BOL (xbo)" Date: Fri, 27 Nov 2020 17:25:22 +0100 Subject: [PATCH] [IMP] sale_timesheet: remove the context key added This context key has been added in the 14.0 for a fix in helpdesk to create a sale order form a ticket. But, now we remove the 'create sale order' button in the ticket to add sale order line field in the ticket, this field allows to link the timesheet in this sale order line selected in this field. Thus, this commit removes the context key used 'ticket_timesheet_ids' since this key will never be given again in this wizard. task-2424382 --- .../wizard/project_create_sale_order.py | 39 +++---------------- 1 file changed, 6 insertions(+), 33 deletions(-) diff --git a/addons/sale_timesheet/wizard/project_create_sale_order.py b/addons/sale_timesheet/wizard/project_create_sale_order.py index 8c3271128c5..7fbee90b055 100644 --- a/addons/sale_timesheet/wizard/project_create_sale_order.py +++ b/addons/sale_timesheet/wizard/project_create_sale_order.py @@ -193,7 +193,6 @@ class ProjectCreateSalesOrder(models.TransientModel): def _make_billable_at_project_rate(self, sale_order): self.ensure_one() task_left = self.project_id.tasks.filtered(lambda task: not task.sale_line_id) - ticket_timesheet_ids = self.env.context.get('ticket_timesheet_ids', []) for wizard_line in self.line_ids: task_ids = self.project_id.tasks.filtered(lambda task: not task.sale_line_id and task.timesheet_product_id == wizard_line.product_id) task_left -= task_ids @@ -213,17 +212,6 @@ class ProjectCreateSalesOrder(models.TransientModel): 'product_uom_qty': 0.0, }) - if ticket_timesheet_ids and not self.project_id.sale_line_id and not task_ids: - # With pricing = "project rate" in project. When the user wants to create a sale order from a ticket in helpdesk - # The project cannot contain any tasks. Thus, we need to give the first sale_order_line created to link - # the timesheet to this first sale order line. - # link the project to the SO line - self.project_id.write({ - 'sale_order_id': sale_order.id, - 'sale_line_id': sale_order_line.id, - 'partner_id': self.partner_id.id, - }) - # link the tasks to the SO line task_ids.write({ 'sale_line_id': sale_order_line.id, @@ -233,9 +221,6 @@ class ProjectCreateSalesOrder(models.TransientModel): # assign SOL to timesheets search_domain = [('task_id', 'in', task_ids.ids), ('so_line', '=', False)] - if ticket_timesheet_ids: - search_domain = [('id', 'in', ticket_timesheet_ids), ('so_line', '=', False)] - self.env['account.analytic.line'].search(search_domain).write({ 'so_line': sale_order_line.id }) @@ -243,18 +228,11 @@ class ProjectCreateSalesOrder(models.TransientModel): 'product_uom_qty': sale_order_line.qty_delivered }) - if ticket_timesheet_ids and self.project_id.sale_line_id and not self.project_id.tasks and len(self.line_ids) > 1: - # Then, we need to give to the project the last sale order line created - self.project_id.write({ - 'sale_line_id': sale_order_line.id - }) - else: # Otherwise, we are in the normal behaviour - # link the project to the SO line - self.project_id.write({ - 'sale_order_id': sale_order.id, - 'sale_line_id': sale_order_line.id, # we take the last sale_order_line created - 'partner_id': self.partner_id.id, - }) + self.project_id.write({ + 'sale_order_id': sale_order.id, + 'sale_line_id': sale_order_line.id, # we take the last sale_order_line created + 'partner_id': self.partner_id.id, + }) if task_left: task_left.sale_line_id = False @@ -319,12 +297,7 @@ class ProjectCreateSalesOrder(models.TransientModel): tasks = self.project_id.tasks.filtered(lambda t: not t.non_allow_billable) # assign SOL to timesheets for map_entry in map_entries: - search_domain = [('employee_id', '=', map_entry.employee_id.id), ('so_line', '=', False)] - ticket_timesheet_ids = self.env.context.get('ticket_timesheet_ids', []) - if ticket_timesheet_ids: - search_domain.append(('id', 'in', ticket_timesheet_ids)) - else: - search_domain.append(('task_id', 'in', tasks.ids)) + search_domain = [('employee_id', '=', map_entry.employee_id.id), ('so_line', '=', False), ('task_id', 'in', self.project_id.tasks.ids)] self.env['account.analytic.line'].search(search_domain).write({ 'so_line': map_entry.sale_line_id.id })