From bbeb126cf8da2e5dae9602ed91a6232edb3bcf91 Mon Sep 17 00:00:00 2001 From: Nicolas Martinelli Date: Fri, 2 Nov 2018 10:32:06 +0100 Subject: [PATCH] [FIX] sale_timesheet: UOM Revert commits da2140b72678b, e65c8826ef9969 and 06cd145a79f023c. They introduce an incorrect UOM. The original issue was an `AccessError` due to the fact that the employee chosen was not in the same company than the user. Therefore, instead of changing the logic of the UOM selection, we make sure to select the employee in the appropriate company first, then fall back on any company then. opw-1888299 --- addons/sale_timesheet/models/account.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/addons/sale_timesheet/models/account.py b/addons/sale_timesheet/models/account.py index 7dc2411d53e..dba9cc76d6c 100644 --- a/addons/sale_timesheet/models/account.py +++ b/addons/sale_timesheet/models/account.py @@ -38,10 +38,12 @@ class AccountAnalyticLine(models.Model): return {} unit_amount = values.get('unit_amount', 0.0) or self.unit_amount user_id = values.get('user_id') or self.user_id.id or self._default_user() - emp = self.env['hr.employee'].search([('user_id', '=', user_id)], limit=1) - account = values.get('account_id') and self.env['account.analytic.account'].browse([values['account_id']]) or self.account_id or emp.account_id + user = self.env['res.users'].browse([user_id]) + emp = self.env['hr.employee'].search([('user_id', '=', user_id), ('company_id', '=', user.company_id.id)], limit=1) + if not emp: + emp = self.env['hr.employee'].search([('user_id', '=', user_id)], limit=1).sudo() cost = emp and emp.timesheet_cost or 0.0 - uom = account.sudo().company_id.project_time_mode_id + uom = (emp or user).company_id.project_time_mode_id # Nominal employee cost = 1 * company project UoM (project_time_mode_id) return { 'amount': -unit_amount * cost,