diff --git a/fieldservice/models/fsm_order.py b/fieldservice/models/fsm_order.py index 2b2f63cdb4..ca634655bd 100644 --- a/fieldservice/models/fsm_order.py +++ b/fieldservice/models/fsm_order.py @@ -74,6 +74,10 @@ def _track_subtype(self, init_values): group_expand="_read_group_stage_ids", default=lambda self: self._default_stage_id(), ) + is_closed = fields.Boolean( + "Is closed", + related="stage_id.is_closed", + ) priority = fields.Selection( fsm_stage.AVAILABLE_PRIORITIES, index=True, @@ -121,6 +125,31 @@ def _track_subtype(self, init_values): default=lambda self: self.env.company, help="Company related to this order", ) + + def _calc_request_late(self, vals): + if vals.get("request_early", False): + early = fields.Datetime.from_string(vals.get("request_early")) + else: + early = datetime.now() + + if vals.get("priority") == "0": + vals["request_late"] = early + timedelta( + hours=self.env.company.fsm_order_request_late_lowest + ) + elif vals.get("priority") == "1": + vals["request_late"] = early + timedelta( + hours=self.env.company.fsm_order_request_late_low + ) + elif vals.get("priority") == "2": + vals["request_late"] = early + timedelta( + hours=self.env.company.fsm_order_request_late_medium + ) + elif vals.get("priority") == "3": + vals["request_late"] = early + timedelta( + hours=self.env.company.fsm_order_request_late_high + ) + return vals + request_late = fields.Datetime(string="Latest Request Date") description = fields.Text() @@ -224,26 +253,7 @@ def create(self, vals_list): ) self._calc_scheduled_dates(vals) if not vals.get("request_late"): - if vals.get("priority") == "0": - if vals.get("request_early"): - vals["request_late"] = fields.Datetime.from_string( - vals.get("request_early") - ) + timedelta(days=3) - else: - vals["request_late"] = datetime.now() + timedelta(days=3) - elif vals.get("request_early") and vals.get("priority") == "1": - vals["request_late"] = fields.Datetime.from_string( - vals.get("request_early") - ) + timedelta(days=2) - elif vals.get("request_early") and vals.get("priority") == "2": - vals["request_late"] = fields.Datetime.from_string( - vals.get("request_early") - ) + timedelta(days=1) - elif vals.get("request_early") and vals.get("priority") == "3": - vals["request_late"] = fields.Datetime.from_string( - vals.get("request_early") - ) + timedelta(hours=8) - + vals = self._calc_request_late(vals) return super().create(vals_list) is_button = fields.Boolean(default=False) @@ -276,7 +286,6 @@ def _calc_scheduled_dates(self, vals): or vals.get("scheduled_date_start") or vals.get("scheduled_date_end") ): - if vals.get("scheduled_date_start") and vals.get("scheduled_date_end"): new_date_start = fields.Datetime.from_string( vals.get("scheduled_date_start", False) diff --git a/fieldservice/models/fsm_person_calendar_filter.py b/fieldservice/models/fsm_person_calendar_filter.py index c77006e9a6..4b4a3b7b92 100644 --- a/fieldservice/models/fsm_person_calendar_filter.py +++ b/fieldservice/models/fsm_person_calendar_filter.py @@ -10,7 +10,11 @@ class FSMPersonCalendarFilter(models.Model): _description = "FSM Person Calendar Filter" user_id = fields.Many2one( - "res.users", "Me", required=True, default=lambda self: self.env.user + "res.users", + "Me", + required=True, + default=lambda self: self.env.user, + ondelete="cascade", ) fsm_person_id = fields.Many2one("fsm.person", "FSM Worker", required=True) active = fields.Boolean(default=True) diff --git a/fieldservice/models/res_company.py b/fieldservice/models/res_company.py index e3b1a1558b..86b4826d0f 100644 --- a/fieldservice/models/res_company.py +++ b/fieldservice/models/res_company.py @@ -14,3 +14,19 @@ class ResCompany(models.Model): string="Auto-populate Equipments on Order based on Location" ) search_on_complete_name = fields.Boolean(string="Search Location By Hierarchy") + + fsm_order_request_late_lowest = fields.Float( + string="Hours of Buffer for Lowest Priority FS Orders", + default=72, + ) + fsm_order_request_late_low = fields.Float( + string="Hours of Buffer for Low Priority FS Orders", + default=48, + ) + fsm_order_request_late_medium = fields.Float( + string="Hours of Buffer for Medium Priority FS Orders", + default=24, + ) + fsm_order_request_late_high = fields.Float( + string="Hours of Buffer for High Priority FS Orders", default=8 + ) diff --git a/fieldservice/models/res_config_settings.py b/fieldservice/models/res_config_settings.py index 068375c074..73d2e5567e 100644 --- a/fieldservice/models/res_config_settings.py +++ b/fieldservice/models/res_config_settings.py @@ -90,6 +90,26 @@ class ResConfigSettings(models.TransientModel): related="company_id.search_on_complete_name", readonly=False, ) + fsm_order_request_late_lowest = fields.Float( + string="Hours of Buffer for Lowest Priority FS Orders", + related="company_id.fsm_order_request_late_lowest", + readonly=False, + ) + fsm_order_request_late_low = fields.Float( + string="Hours of Buffer for Low Priority FS Orders", + related="company_id.fsm_order_request_late_low", + readonly=False, + ) + fsm_order_request_late_medium = fields.Float( + string="Hours of Buffer for Medium Priority FS Orders", + related="company_id.fsm_order_request_late_medium", + readonly=False, + ) + fsm_order_request_late_high = fields.Float( + string="Hours of Buffer for High Priority FS Orders", + related="company_id.fsm_order_request_late_high", + readonly=False, + ) # Dependencies @api.onchange("group_fsm_equipment") diff --git a/fieldservice/security/ir.model.access.csv b/fieldservice/security/ir.model.access.csv index f742860b20..b1bccd9543 100644 --- a/fieldservice/security/ir.model.access.csv +++ b/fieldservice/security/ir.model.access.csv @@ -1,25 +1,25 @@ id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink -access_fsm_stage_fsm_user,fsm.stage.user,model_fsm_stage,fieldservice.group_fsm_user,1,0,0,0 +access_fsm_stage_fsm_user,fsm.stage.user,model_fsm_stage,fieldservice.group_fsm_user_own,1,0,0,0 access_fsm_stage_fsm_manager,fsm.stage.manager,model_fsm_stage,fieldservice.group_fsm_manager,1,1,1,1 -access_fsm_tag_fsm_user,fsm.tag.user,model_fsm_tag,fieldservice.group_fsm_user,1,0,0,0 +access_fsm_tag_fsm_user,fsm.tag.user,model_fsm_tag,fieldservice.group_fsm_user_own,1,0,0,0 access_fsm_tag_fsm_manager,fsm.tag.manager,model_fsm_tag,fieldservice.group_fsm_manager,1,1,1,1 -access_fsm_person_user,fsm.person.user,model_fsm_person,fieldservice.group_fsm_user,1,1,0,0 +access_fsm_person_user,fsm.person.user,model_fsm_person,fieldservice.group_fsm_user_own,1,1,0,0 access_fsm_person_manager,fsm.person.manager,model_fsm_person,fieldservice.group_fsm_manager,1,1,1,1 -access_fsm_location_user,fsm.location.user,model_fsm_location,fieldservice.group_fsm_user,1,1,0,0 +access_fsm_location_user,fsm.location.user,model_fsm_location,fieldservice.group_fsm_user_own,1,1,0,0 access_fsm_location_dispatcher,fsm.location.dispatcher,model_fsm_location,fieldservice.group_fsm_dispatcher,1,1,1,0 -access_fsm_order_user,fsm.order.user,model_fsm_order,fieldservice.group_fsm_user,1,1,0,0 +access_fsm_order_user,fsm.order.user,model_fsm_order,fieldservice.group_fsm_user_own,1,1,0,0 access_fsm_order_dispatcher,fsm.order.dispatcher,model_fsm_order,fieldservice.group_fsm_dispatcher,1,1,1,1 -access_fsm_equipment_fsm_user,fsm.equipment.user,model_fsm_equipment,fieldservice.group_fsm_user,1,0,0,0 +access_fsm_equipment_fsm_user,fsm.equipment.user,model_fsm_equipment,fieldservice.group_fsm_user_own,1,0,0,0 access_fsm_equipment_fsm_manager,fsm.equipment.manager,model_fsm_equipment,fieldservice.group_fsm_manager,1,1,1,1 -access_fsm_category_user,fsm.category.user,model_fsm_category,fieldservice.group_fsm_user,1,0,0,0 +access_fsm_category_user,fsm.category.user,model_fsm_category,fieldservice.group_fsm_user_own,1,0,0,0 access_fsm_category_manager,fsm.category.manager,model_fsm_category,fieldservice.group_fsm_manager,1,1,1,1 -access_fsm_template_user,fsm.template.user,model_fsm_template,fieldservice.group_fsm_user,1,0,0,0 +access_fsm_template_user,fsm.template.user,model_fsm_template,fieldservice.group_fsm_user_own,1,0,0,0 access_fsm_template_manager,fsm.template.manager,model_fsm_template,fieldservice.group_fsm_manager,1,1,1,1 -access_fsm_team_user,fsm.team.user,model_fsm_team,fieldservice.group_fsm_user,1,0,0,0 +access_fsm_team_user,fsm.team.user,model_fsm_team,fieldservice.group_fsm_user_own,1,0,0,0 access_fsm_team_manager,fsm.team.manager,model_fsm_team,fieldservice.group_fsm_manager,1,1,1,1 -access_fsm_location_person_user,fsm.location.person.user,model_fsm_location_person,fieldservice.group_fsm_user,1,1,0,0 +access_fsm_location_person_user,fsm.location.person.user,model_fsm_location_person,fieldservice.group_fsm_user_own,1,1,0,0 access_fsm_location_person_manager,fsm.location.person.manager,model_fsm_location_person,fieldservice.group_fsm_manager,1,1,1,1 -access_fsm_order_type_user,fsm.order.type.user,model_fsm_order_type,fieldservice.group_fsm_user,1,1,0,0 +access_fsm_order_type_user,fsm.order.type.user,model_fsm_order_type,fieldservice.group_fsm_user_own,1,1,0,0 access_fsm_order_type_manager,fsm.order.type.manager,model_fsm_order_type,fieldservice.group_fsm_manager,1,1,1,1 -access_fsm_calendar_filter,fsm.calendar.filter.user,model_fsm_person_calendar_filter,fieldservice.group_fsm_user,1,1,1,1 +access_fsm_calendar_filter,fsm.calendar.filter.user,model_fsm_person_calendar_filter,fieldservice.group_fsm_user_own,1,1,1,1 access_fsm_wizard,access_fsm_wizard,model_fsm_wizard,fieldservice.group_fsm_dispatcher,1,1,1,0 diff --git a/fieldservice/security/ir_rule.xml b/fieldservice/security/ir_rule.xml index df1ef4d3d8..5bdbf4f528 100644 --- a/fieldservice/security/ir_rule.xml +++ b/fieldservice/security/ir_rule.xml @@ -9,6 +9,23 @@ name="domain_force" >['|',('company_id','=',False),('company_id', 'in', company_ids)] + + + FSM Orders Entry (only own) + + ['|',('person_id.user_ids','=',user.id),('person_id','=',False)] + + + + + FSM Orders Entry + + [(1, '=', 1)] + + + FSM Templates Entry diff --git a/fieldservice/security/res_groups.xml b/fieldservice/security/res_groups.xml index e7b0e28dac..43325c4532 100644 --- a/fieldservice/security/res_groups.xml +++ b/fieldservice/security/res_groups.xml @@ -1,9 +1,18 @@ + + User (only own documents) + + + + User - + Dispatcher diff --git a/fieldservice/views/fsm_location.xml b/fieldservice/views/fsm_location.xml index 29bc40ba68..bd1bb2795e 100644 --- a/fieldservice/views/fsm_location.xml +++ b/fieldservice/views/fsm_location.xml @@ -102,6 +102,11 @@ + - + @@ -189,7 +195,7 @@ - + @@ -199,7 +205,7 @@ - + diff --git a/fieldservice/views/fsm_order.xml b/fieldservice/views/fsm_order.xml index 9646f12810..289caea392 100644 --- a/fieldservice/views/fsm_order.xml +++ b/fieldservice/views/fsm_order.xml @@ -14,7 +14,7 @@ string="Complete" class="oe_highlight" type="object" - groups="fieldservice.group_fsm_user" + groups="fieldservice.group_fsm_user_own" attrs="{'invisible': [('stage_id', 'in', (%(fieldservice.fsm_stage_completed)d, %(fieldservice.fsm_stage_cancelled)d))]}" />