[FIX] sale_timesheet: UOM
Revert commitsda2140b726,e65c8826efand06cd145a79. 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
This commit is contained in:
committed by
Nicolas Martinelli
parent
09a81894b1
commit
bbeb126cf8
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user