summaryrefslogtreecommitdiff
path: root/addons/maintenance
diff options
context:
space:
mode:
authorsvs-odoo <svs@odoo.com>2019-09-16 10:42:18 +0000
committersvs-odoo <svs@odoo.com>2019-09-17 08:30:13 +0000
commitaed58b4b9ae4f9d62ac7fcda46115b0ac44e2eba (patch)
tree220ae33074acf4c4e78d6a8ea6439f9ec1f05b30 /addons/maintenance
parent7b8178693e8fcd0b4104b6922bbb2312bf7cdd47 (diff)
[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.
Diffstat (limited to 'addons/maintenance')
-rw-r--r--addons/maintenance/models/maintenance.py14
-rw-r--r--addons/maintenance/views/maintenance_views.xml2
2 files changed, 14 insertions, 2 deletions
diff --git a/addons/maintenance/models/maintenance.py b/addons/maintenance/models/maintenance.py
index e2346644294..4b5fa62bcfa 100644
--- a/addons/maintenance/models/maintenance.py
+++ b/addons/maintenance/models/maintenance.py
@@ -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:
diff --git a/addons/maintenance/views/maintenance_views.xml b/addons/maintenance/views/maintenance_views.xml
index 45254bcbacd..e91c6673927 100644
--- a/addons/maintenance/views/maintenance_views.xml
+++ b/addons/maintenance/views/maintenance_views.xml
@@ -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 ......."/>