From 2b802cd5108950d975488cafa3d00de1afb2cbe9 Mon Sep 17 00:00:00 2001 From: Simon Lejeune Date: Thu, 22 Aug 2019 09:32:46 +0000 Subject: [PATCH] [REF] maintenance: multi company Ensure proper domains are applied and enforced on relation fields thanks to the `check_company` attributes. task-1985992 --- addons/maintenance/models/maintenance.py | 12 ++++++++---- addons/maintenance/views/maintenance_views.xml | 10 ++++++---- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/addons/maintenance/models/maintenance.py b/addons/maintenance/models/maintenance.py index 2ab6df51909..e2346644294 100644 --- a/addons/maintenance/models/maintenance.py +++ b/addons/maintenance/models/maintenance.py @@ -93,6 +93,7 @@ class MaintenanceEquipment(models.Model): _name = 'maintenance.equipment' _inherit = ['mail.thread', 'mail.activity.mixin'] _description = 'Maintenance Equipment' + _check_company_auto = True def _track_subtype(self, init_values): self.ensure_one() @@ -127,7 +128,7 @@ class MaintenanceEquipment(models.Model): owner_user_id = fields.Many2one('res.users', string='Owner', tracking=True) category_id = fields.Many2one('maintenance.equipment.category', string='Equipment Category', tracking=True, group_expand='_read_group_category_ids') - partner_id = fields.Many2one('res.partner', string='Vendor') + partner_id = fields.Many2one('res.partner', string='Vendor', check_company=True) partner_ref = fields.Char('Vendor Reference') location = fields.Char('Location') model = fields.Char('Model') @@ -258,6 +259,7 @@ class MaintenanceRequest(models.Model): _inherit = ['mail.thread.cc', 'mail.activity.mixin'] _description = 'Maintenance Request' _order = "id desc" + _check_company_auto = True @api.returns('self') def _default_stage(self): @@ -288,7 +290,7 @@ class MaintenanceRequest(models.Model): owner_user_id = fields.Many2one('res.users', string='Created by User', default=lambda s: s.env.uid) category_id = fields.Many2one('maintenance.equipment.category', related='equipment_id.category_id', string='Category', store=True, readonly=True) equipment_id = fields.Many2one('maintenance.equipment', string='Equipment', - ondelete='restrict', index=True) + ondelete='restrict', index=True, check_company=True) user_id = fields.Many2one('res.users', string='Technician', tracking=True) stage_id = fields.Many2one('maintenance.stage', string='Stage', ondelete='restrict', tracking=True, group_expand='_read_group_stage_ids', default=_default_stage) @@ -301,7 +303,7 @@ class MaintenanceRequest(models.Model): archive = fields.Boolean(default=False, help="Set archive to true to hide the maintenance request without deleting it.") maintenance_type = fields.Selection([('corrective', 'Corrective'), ('preventive', 'Preventive')], string='Maintenance Type', default="corrective") schedule_date = fields.Datetime('Scheduled Date', help="Date the maintenance team plans the maintenance. It should not differ much from the Request Date. ") - maintenance_team_id = fields.Many2one('maintenance.team', string='Team', required=True, default=_get_default_team_id) + maintenance_team_id = fields.Many2one('maintenance.team', string='Team', required=True, default=_get_default_team_id, check_company=True) duration = fields.Float(help="Duration in hours.") done = fields.Boolean(related='stage_id.done') @@ -400,7 +402,9 @@ class MaintenanceTeam(models.Model): active = fields.Boolean(default=True) company_id = fields.Many2one('res.company', string='Company', default=lambda self: self.env.company) - member_ids = fields.Many2many('res.users', 'maintenance_team_users_rel', string="Team Members") + member_ids = fields.Many2many( + 'res.users', 'maintenance_team_users_rel', string="Team Members", + domain="[('company_ids', 'in', company_id)]") color = fields.Integer("Color Index", default=0) request_ids = fields.One2many('maintenance.request', 'maintenance_team_id', copy=False) equipment_ids = fields.One2many('maintenance.equipment', 'maintenance_team_id', copy=False) diff --git a/addons/maintenance/views/maintenance_views.xml b/addons/maintenance/views/maintenance_views.xml index 865dfb58f1f..923b32cc4d8 100644 --- a/addons/maintenance/views/maintenance_views.xml +++ b/addons/maintenance/views/maintenance_views.xml @@ -74,8 +74,8 @@ - - + + @@ -94,6 +94,7 @@ + @@ -338,6 +339,7 @@ @@ -350,12 +352,12 @@ - + - +