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

[FIX] analytic, hr_timesheet: recompute order

When creating a timesheet, several fields need to be recomputed:
- `currency_id`
- `group_id`
- `department_id`
- `is_timesheet`
- `validated`

When `validated` is computed before the other fields, the recomputation
will lead to an `AccessError` because of the rule
`hr_timesheet.timesheet_line_rule_user`.

Since the test `test_timesheet_validation_user` expects an
`AccessError`, the test succeeds. However, from time to time,
`validated` is computed last => the `AccessError` is not raised.

Actually, a `ValidationError` should be raised in this case (from the
`create` override in `timesheet_grid`).
parent 1fa8f679
Branches
Tags
No related merge requests found
......@@ -171,8 +171,8 @@ class AccountAnalyticLine(models.Model):
user_id = fields.Many2one('res.users', string='User', default=_default_user)
tag_ids = fields.Many2many('account.analytic.tag', 'account_analytic_line_tag_rel', 'line_id', 'tag_id', string='Tags', copy=True)
company_id = fields.Many2one('res.company', string='Company', required=True, readonly=True, default=lambda self: self.env.user.company_id)
currency_id = fields.Many2one(related="company_id.currency_id", string="Currency", readonly=True, store=True)
group_id = fields.Many2one('account.analytic.group', related='account_id.group_id', store=True, readonly=True)
currency_id = fields.Many2one(related="company_id.currency_id", string="Currency", readonly=True, store=True, compute_sudo=True)
group_id = fields.Many2one('account.analytic.group', related='account_id.group_id', store=True, readonly=True, compute_sudo=True)
@api.multi
@api.constrains('company_id', 'account_id')
......
......@@ -18,7 +18,7 @@ class AccountAnalyticLine(models.Model):
project_id = fields.Many2one('project.project', 'Project', domain=[('allow_timesheets', '=', True)])
employee_id = fields.Many2one('hr.employee', "Employee")
department_id = fields.Many2one('hr.department', "Department", compute='_compute_department_id', store=True)
department_id = fields.Many2one('hr.department', "Department", compute='_compute_department_id', store=True, compute_sudo=True)
@api.onchange('project_id')
def onchange_project_id(self):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment