[FIX] hr_timesheet: Removing task on a timesheet line
Steps to reproduce the bug: - A product is configured as a service + invoicing policy as "Timesheet on task" + Create a task in an existing project. - Create a SO with this product and confirm it. - Go to the task, and create a timesheet on it, the delivered quantity on the SO is correctly updated. - Now, go to the Timesheets app and remove the task from the analytic line. Bug: The Delivered quantity on the Sale Order was not updated. PS: The case where so_line is in the values is already taken into account by the overwrite of function write in addons/sale/models/analytic.py But as task implies so line (as explained in addons/sale_timesheet/models/account.py in function _timesheet_preprocess), the delivered qty of a so line must be recomputed when its task is modified. opw:1864313
This commit is contained in:
@@ -27,12 +27,16 @@ 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']
|
||||
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.with_context(sale_analytic_force_recompute=True)._analytic_compute_delivered_quantity()
|
||||
return result
|
||||
|
||||
@api.model
|
||||
|
||||
Reference in New Issue
Block a user