From 3f8a5e466df6a373c4065777845bf6e9f2f49beb Mon Sep 17 00:00:00 2001 From: Cas Vissers Date: Tue, 30 Apr 2019 14:44:40 +0000 Subject: [PATCH] [FIX] sale_timesheet: extract the check on write in a function MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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) --- addons/sale_timesheet/models/account.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/addons/sale_timesheet/models/account.py b/addons/sale_timesheet/models/account.py index bfdc17f7d27..81895718a96 100644 --- a/addons/sale_timesheet/models/account.py +++ b/addons/sale_timesheet/models/account.py @@ -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):