[IMP] maintenance: onchange on company_id

On a maintenance request, when the `company_id` is changed, reset the
`maintenance_team_id` if it doesn't fit the company anymore.
This commit is contained in:
svs-odoo
2019-09-17 08:30:13 +00:00
parent 7b8178693e
commit aed58b4b9a
2 changed files with 14 additions and 2 deletions
+13 -1
View File
@@ -145,7 +145,7 @@ class MaintenanceEquipment(models.Model):
maintenance_open_count = fields.Integer(compute='_compute_maintenance_count', string="Current Maintenance", store=True)
period = fields.Integer('Days between each preventive maintenance')
next_action_date = fields.Date(compute='_compute_next_maintenance', string='Date of the next preventive maintenance', store=True)
maintenance_team_id = fields.Many2one('maintenance.team', string='Maintenance Team')
maintenance_team_id = fields.Many2one('maintenance.team', string='Maintenance Team', check_company=True)
maintenance_duration = fields.Float(help="Maintenance Duration in hours.")
@api.depends('effective_date', 'period', 'maintenance_ids.request_date', 'maintenance_ids.close_date')
@@ -197,6 +197,12 @@ class MaintenanceEquipment(models.Model):
equipment.maintenance_count = len(equipment.maintenance_ids)
equipment.maintenance_open_count = len(equipment.maintenance_ids.filtered(lambda x: not x.stage_id.done))
@api.onchange('company_id')
def _onchange_company_id(self):
if self.company_id and self.maintenance_team_id:
if self.maintenance_team_id.company_id and not self.maintenance_team_id.company_id.id == self.company_id.id:
self.maintenance_team_id = False
@api.onchange('category_id')
def _onchange_category_id(self):
self.technician_user_id = self.category_id.technician_user_id
@@ -316,6 +322,12 @@ class MaintenanceRequest(models.Model):
# self.write({'active': True, 'stage_id': first_stage_obj.id})
self.write({'archive': False, 'stage_id': first_stage_obj.id})
@api.onchange('company_id')
def _onchange_company_id(self):
if self.company_id and self.maintenance_team_id:
if self.maintenance_team_id.company_id and not self.maintenance_team_id.company_id.id == self.company_id.id:
self.maintenance_team_id = False
@api.onchange('equipment_id')
def onchange_equipment_id(self):
if self.equipment_id:
@@ -94,7 +94,7 @@
</div>
<field name="priority" widget="priority"/>
<field name="email_cc" string="Email cc" groups="base.group_no_one"/>
<field name="company_id" groups="base.group_multi_company"/>
<field name="company_id" options="{'no_create': True}" groups="base.group_multi_company"/>
</group>
</group>
<field name='description' placeholder="Internal Note ......."/>