[FIX] hr_timesheet: remove onchange domain
Fixes issues where static multi-company filtering would get squashed /
replaced by dynamic domains not having those filters.
The conditional could be replicated in two ways: one would be to use a
python-level conditional expression:
a if cond else b
this is easier for users to interpret, but harder to analyze: python
expressions are currently opaque to view analysis (and possibly
eventually to domain edition).
The alternative here is to leverage domain simplification:
(OR (= (not cond) 1) section)
if `cond` is true becomes
(OR (= 0 1) section)
and thus `section` itself, while if `cond` is false it becomes
(OR (= 1 1) section)
and thus `true` (so the section doesn't apply).
It works OK though the inversion of the condition itself is a bit
bizarre.
And in this specific case since we need both branches the negated
condition requires explicitly converting the condition to a boolean if
it might not be one: the expression compiler recognizes specifically
`(= 0 1)` and `(= 1 1)` (`(= False 1)` and `(= True 1)` also work for
Python reasons).
[REM] dynamic domain from hr_timesheet
closes odoo/odoo#40945
Signed-off-by: Xavier Morel (xmo) <xmo@odoo.com>
This commit is contained in:
@@ -20,7 +20,10 @@ class AccountAnalyticLine(models.Model):
|
||||
result['employee_id'] = self.env['hr.employee'].search([('user_id', '=', result['user_id'])], limit=1).id
|
||||
return result
|
||||
|
||||
task_id = fields.Many2one('project.task', 'Task', index=True, domain="[('company_id', '=', company_id)]")
|
||||
task_id = fields.Many2one(
|
||||
'project.task', 'Task', index=True,
|
||||
domain="[('company_id', '=', company_id), ('project_id.allow_timesheets', '=', True), ('project_id', '=?', project_id)]"
|
||||
)
|
||||
project_id = fields.Many2one('project.project', 'Project', domain=[('allow_timesheets', '=', True)])
|
||||
|
||||
employee_id = fields.Many2one('hr.employee', "Employee", check_company=True)
|
||||
@@ -33,18 +36,9 @@ class AccountAnalyticLine(models.Model):
|
||||
|
||||
@api.onchange('project_id')
|
||||
def onchange_project_id(self):
|
||||
# force domain on task when project is set
|
||||
if self.project_id:
|
||||
if self.project_id != self.task_id.project_id:
|
||||
# reset task when changing project
|
||||
self.task_id = False
|
||||
return {'domain': {
|
||||
'task_id': [('project_id', '=', self.project_id.id)]
|
||||
}}
|
||||
return {'domain': {
|
||||
'task_id': [('project_id.allow_timesheets', '=', True)]
|
||||
}}
|
||||
|
||||
if self.project_id and self.project_id != self.task_id.project_id:
|
||||
# reset task when changing project
|
||||
self.task_id = False
|
||||
|
||||
@api.onchange('task_id')
|
||||
def _onchange_task_id(self):
|
||||
|
||||
@@ -9,13 +9,13 @@ class Project(models.Model):
|
||||
_inherit = "project.project"
|
||||
|
||||
allow_timesheets = fields.Boolean("Timesheets", default=True, help="Enable timesheeting on the project.")
|
||||
|
||||
@api.onchange('partner_id')
|
||||
def _onchange_partner_id(self):
|
||||
domain = []
|
||||
if self.partner_id:
|
||||
domain = [('partner_id', '=', self.partner_id.id)]
|
||||
return {'domain': {'analytic_account_id': domain}}
|
||||
analytic_account_id = fields.Many2one(
|
||||
# note: replaces ['|', ('company_id', '=', False), ('company_id', '=', company_id)]
|
||||
domain="""[
|
||||
'|', ('company_id', '=', False), ('company_id', '=', company_id),
|
||||
('partner_id', '=?', partner_id),
|
||||
]"""
|
||||
)
|
||||
|
||||
@api.onchange('analytic_account_id')
|
||||
def _onchange_analytic_account(self):
|
||||
|
||||
Reference in New Issue
Block a user