[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) <xmo@odoo.com>
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
<field name="employee_id"/>
|
||||
</xpath>
|
||||
<xpath expr="//filter[@name='my_maintenances']" position="replace">
|
||||
<filter string="My Maintenances" name="my_maintenances" domain="['|', ('employee_id.user_id', '=', uid), ('department_id.manager_id.user_id', '=', uid)]"/>
|
||||
<filter string="My Maintenances" name="my_maintenances" domain="[('employee_id.user_id', '=', uid)]"/>
|
||||
</xpath>
|
||||
<xpath expr="//filter[@name='created_by']" position="replace">
|
||||
<filter string='Created By' name='created_by' domain="[]" context="{'group_by': 'employee_id'}"/>
|
||||
@@ -38,7 +38,6 @@
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//span[@name='owner_user_id']" position="replace">
|
||||
<span t-if="record.employee_id.raw_value"><field name="employee_id"/><br/></span>
|
||||
<span t-if="record.department_id.raw_value"><field name="department_id"/><br/></span>
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
Reference in New Issue
Block a user