diff options
| author | Nicolas Martinelli <nim@odoo.com> | 2018-11-02 10:32:06 +0100 |
|---|---|---|
| committer | Nicolas Martinelli <nim-odoo@users.noreply.github.com> | 2018-11-02 13:48:05 +0100 |
| commit | bbeb126cf8da2e5dae9602ed91a6232edb3bcf91 (patch) | |
| tree | e35deff3caeb7879027250a10fe1132462793ab8 | |
| parent | 09a81894b1c32ed8b6a589cea6434bf9ecba59a3 (diff) | |
[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
| -rw-r--r-- | addons/sale_timesheet/models/account.py | 8 |
1 files 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, |
