From e65c8826ef9969ee0c0416c8f5165525ee3f0809 Mon Sep 17 00:00:00 2001 From: "Lucas Perais (lpe)" Date: Wed, 29 Aug 2018 15:53:54 +0200 Subject: [PATCH] [FIX] sale_timesheet: timesheet cost with company on analytic account FIXUP da2140b The above commmit was half-right in the business logic, but overlooked that if a user is not in the company of the project, it will crash. This use case worked before that commit While agreeing that a little more clear access right is needed like for example be able to get the project_time_mode_id on the companies that are in user.company_ids, the aim of this present commit is to avoid regression OPW 1878204 closes #26539 --- addons/sale_timesheet/models/account.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/addons/sale_timesheet/models/account.py b/addons/sale_timesheet/models/account.py index 258d4d70aef..121c1940000 100644 --- a/addons/sale_timesheet/models/account.py +++ b/addons/sale_timesheet/models/account.py @@ -38,10 +38,10 @@ 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() - project = values.get('project_id') and self.env['project.project'].browse([values['project_id']]) or self.project_id 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 cost = emp and emp.timesheet_cost or 0.0 - uom = project.company_id.project_time_mode_id + uom = account.company_id.sudo().project_time_mode_id # Nominal employee cost = 1 * company project UoM (project_time_mode_id) return { 'amount': -unit_amount * cost,