[FIX] sale_timesheet: extract the check on write in a function

On write, a check is done that raises
'You can not modify already invoiced timesheets …'.
We put that check in a function so that this behaviour can be extended.
(restricted by an override, or relaxed by not calling the super)

opw 1974968
closes #33057

closes odoo/odoo#33092

Signed-off-by: Nans Lefebvre (len) <len@odoo.com>
This commit is contained in:
Cas Vissers
2019-05-02 06:13:00 +00:00
committed by Nans Lefebvre
parent 2efcefb504
commit 3f8a5e466d
+6 -2
View File
@@ -57,11 +57,15 @@ class AccountAnalyticLine(models.Model):
@api.multi
def write(self, values):
# prevent to update invoiced timesheets if one line is of type delivery
self._check_can_write(values)
result = super(AccountAnalyticLine, self).write(values)
return result
@api.multi
def _check_can_write(self, values):
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', 'project_id', 'task_id', 'so_line', 'amount', 'date']]):
raise UserError(_('You can not modify already invoiced timesheets (linked to a Sales order items invoiced on Time and material).'))
result = super(AccountAnalyticLine, self).write(values)
return result
@api.model
def _timesheet_preprocess(self, values):