From d6ad22227cc7b3f36ac9914cce4f8a1f0a0f36a2 Mon Sep 17 00:00:00 2001 From: Nans Lefebvre Date: Fri, 19 Apr 2019 07:56:15 +0000 Subject: [PATCH] [FIX] sale_timesheet: update delivered quantities when changing the sale_line_id Create a SO with two lines (sol_1, sol_2) selling a given service. On the corresponding Project/Task, set the partner so that the sale_line_id can be chosen to one of the lines. Add an AAL with x hours, save. This updates the delivered quantity (x) on sol_1. Edit, change the sale_line_id to the second one: it updates the delivered quantity on sol_2 (to x) but not on sol_1. Has a result, the delivered quantity has been doubled. The issue is that the quantities are only recomputed on the SOL that we write; instead they should be recomputed on the old one and the new one. We base ourselves on 371a92fb which solved a similar bug to add the recompute on both lines. opw 1959509 11.0-opw1959509-sltmsht-len closes odoo/odoo#32820 Signed-off-by: Nans Lefebvre (len) --- addons/sale_timesheet/models/account.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/addons/sale_timesheet/models/account.py b/addons/sale_timesheet/models/account.py index 8a5fbdcaad4..bfd4257091e 100644 --- a/addons/sale_timesheet/models/account.py +++ b/addons/sale_timesheet/models/account.py @@ -27,15 +27,14 @@ class AccountAnalyticLine(models.Model): @api.multi def write(self, values): # prevent to update invoiced timesheets if one line is of type delivery - sale_order_lines = self.env['sale.order.line'] + sale_order_lines = self.sudo().mapped('so_line') or self.env['sale.order.line'] if self.sudo().filtered(lambda aal: aal.so_line.product_id.invoice_policy == "delivery") and self.filtered(lambda timesheet: timesheet.timesheet_invoice_id): if any([field_name in values for field_name in ['unit_amount', 'employee_id', 'task_id', 'timesheet_revenue', 'so_line', 'amount', 'date']]): raise UserError(_('You can not modify already invoiced timesheets (linked to a Sales order items invoiced on Time and material).')) - if 'task_id' in values and not values.get('so_line'): - sale_order_lines = self.sudo().mapped('so_line') result = super(AccountAnalyticLine, self).write(values) # applied only for timesheet self.filtered(lambda t: t.project_id)._timesheet_postprocess(values) + sale_order_lines |= self.sudo().mapped('so_line') sale_order_lines.with_context(sale_analytic_force_recompute=True)._analytic_compute_delivered_quantity() return result