From da2140b72678ba8ef7bc5e5f3094e75e753a18f4 Mon Sep 17 00:00:00 2001 From: "Lucas Perais (lpe)" Date: Thu, 9 Aug 2018 11:29:27 +0200 Subject: [PATCH] [FIX] sale_timesheet: choose the project's company to determine cost Companies: B child of A User: Demo in B not in A Admin in A Create a product with Admin: track service = timesheet on project invoicing policy = delivered quantities Create a SO with Demo and validate, a project is created Now, make the demo user timzsheet on it Before this commit, there was an access error on company, that was because the the company that was choosen to determine the cost, was the one on the employee, which could be in another company than the user and moreover than the project After this commit, we take the company of the project OPW 1871440 closes #26271 --- 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 a56ded4dc55..258d4d70aef 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() - user = self.env['res.users'].browse([user_id]) + 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) cost = emp and emp.timesheet_cost or 0.0 - uom = (emp or user).company_id.project_time_mode_id + uom = project.company_id.project_time_mode_id # Nominal employee cost = 1 * company project UoM (project_time_mode_id) return { 'amount': -unit_amount * cost,