Skip to content
Snippets Groups Projects
Commit bbeb126c authored by Nicolas Martinelli's avatar Nicolas Martinelli Committed by Nicolas Martinelli
Browse files

[FIX] sale_timesheet: UOM

Revert commits da2140b7, e65c8826 and 06cd145a. 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
parent 09a81894
Branches
Tags
No related merge requests found
......@@ -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,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment