From d3798b40581e074f0511a76531d10e4899e4ddff Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Tue, 26 Nov 2019 07:54:52 +0000 Subject: [PATCH] [FIX] hr_maintenance: remove dynamic domain * converts dynamic domain from onchange_department_or_employee_id to a static domain on the field * remove the department_id field (and all uses of it), it looks to never be set and not really be settable: the field is hidden in the form, doesn't have a default value, does not have anything to compute it, ... * remove the onchange itself as it has very little value: it auto-selects an equipment if there exists a single equipment assigned to the selected employee or to no employee Even if we removed the "equipment not assigned to any user" bit (under the assumption that people would mostly request maintenance for their own equipment, and that this would usefully trigger more often) it's unlikely for dedicated users of hr_maintenance to assign only one equipment per employee. So the onchange would rarely do any useful work, and what work it saves is trivial: if there's only one equipment the employee could ask about for maintenance it's really trivial to do that. Task 2115472 closes odoo/odoo#40963 Signed-off-by: Xavier Morel (xmo) --- addons/hr_maintenance/models/equipment.py | 20 ++----------------- .../views/maintenance_views.xml | 3 +-- 2 files changed, 3 insertions(+), 20 deletions(-) diff --git a/addons/hr_maintenance/models/equipment.py b/addons/hr_maintenance/models/equipment.py index 9f11a500790..78e2f7f58e7 100644 --- a/addons/hr_maintenance/models/equipment.py +++ b/addons/hr_maintenance/models/equipment.py @@ -75,33 +75,17 @@ class MaintenanceRequest(models.Model): return self.env['hr.employee'].search([('user_id', '=', self.env.uid)], limit=1) employee_id = fields.Many2one('hr.employee', string='Employee', default=_default_employee_get) - department_id = fields.Many2one('hr.department', string='Department') owner_user_id = fields.Many2one(compute='_compute_owner', store=True) + equipment_id = fields.Many2one(domain="['|', ('employee_id', '=', employee_id), ('employee_id', '=', False)]") - @api.depends('employee_id', 'department_id') + @api.depends('employee_id') def _compute_owner(self): for r in self: if r.equipment_id.equipment_assign_to == 'employee': r.owner_user_id = r.employee_id.user_id.id - elif r.equipment_id.equipment_assign_to == 'department': - r.owner_user_id = r.department_id.manager_id.user_id.id else: r.owner_user_id = False - @api.onchange('employee_id', 'department_id') - def onchange_department_or_employee_id(self): - domain = [] - if self.department_id: - domain = [('department_id', '=', self.department_id.id)] - if self.employee_id and self.department_id: - domain = ['|'] + domain - if self.employee_id: - domain = domain + ['|', ('employee_id', '=', self.employee_id.id), ('employee_id', '=', None)] - equipment = self.env['maintenance.equipment'].search(domain, limit=2) - if len(equipment) == 1: - self.equipment_id = equipment - return {'domain': {'equipment_id': domain}} - @api.model def create(self, vals): result = super(MaintenanceRequest, self).create(vals) diff --git a/addons/hr_maintenance/views/maintenance_views.xml b/addons/hr_maintenance/views/maintenance_views.xml index 569bf8ead05..d56faf86871 100644 --- a/addons/hr_maintenance/views/maintenance_views.xml +++ b/addons/hr_maintenance/views/maintenance_views.xml @@ -11,7 +11,7 @@ - + @@ -38,7 +38,6 @@
-