Skip to content
Snippets Groups Projects
Commit d6ad2222 authored by Nans Lefebvre's avatar Nans Lefebvre
Browse files

[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: default avatarNans Lefebvre (len) <len@odoo.com>
parent fccf4f3c
No related branches found
No related tags found
No related merge requests found
......@@ -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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment