From b4193cd35b6c36f7da93ec36db0d4b9df1c9d5f2 Mon Sep 17 00:00:00 2001 From: Nicolas Martinelli Date: Fri, 14 Apr 2017 15:03:51 +0200 Subject: [PATCH] [FIX] sale: set timesheet line to zero - Create a SO with a product that is a service and will be invoiced based in delivery quantities and will be tracked on timesheets and contract. - Confirm - Use a simple user that only has for rights: "Employee" - Create a timesheet as the employee for the contract created by the sale - Log some time - Save it - Check the SO: ok the number of hours should be "to be invoiced" - Edit the timesheet and set one day to 0 hours => Access Error In case of a zero value, the timesheet widget sends an unlink command for the corresponding entry. In this case, the `sudo` is not set at the appropropriate moment since the context key `force_so_lines` will resue lines which are not defined in the `sudo` environment. opw-728453 --- addons/sale/sale_analytic.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/addons/sale/sale_analytic.py b/addons/sale/sale_analytic.py index 0f07cff230f..14f4cd9be90 100644 --- a/addons/sale/sale_analytic.py +++ b/addons/sale/sale_analytic.py @@ -150,7 +150,7 @@ class AccountAnalyticLine(models.Model): @api.multi def unlink(self): - so_lines = self.mapped('so_line') + so_lines = self.sudo().mapped('so_line') res = super(AccountAnalyticLine, self).unlink() - so_lines.with_context(force_so_lines=so_lines).sudo()._compute_analytic() + so_lines.with_context(force_so_lines=so_lines)._compute_analytic() return res