Skip to content

Commit

Permalink
[IMP] fieldservice: implement check_company on related fields
Browse files Browse the repository at this point in the history
  • Loading branch information
ivantodorovich committed Dec 3, 2024
1 parent 9775935 commit 38c2f44
Show file tree
Hide file tree
Showing 12 changed files with 87 additions and 7 deletions.
32 changes: 27 additions & 5 deletions fieldservice/models/fsm_equipment.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,42 @@ class FSMEquipment(models.Model):
_description = "Field Service Equipment"
_inherit = ["mail.thread", "mail.activity.mixin", "fsm.model.mixin"]
_stage_type = "equipment"
_check_company_auto = True

name = fields.Char(required=True)
person_id = fields.Many2one("fsm.person", string="Assigned Operator")
person_id = fields.Many2one(
"fsm.person",
string="Assigned Operator",
check_company=True,
)
location_id = fields.Many2one("fsm.location", string="Assigned Location")
notes = fields.Text()
territory_id = fields.Many2one("res.territory", string="Territory")
branch_id = fields.Many2one("res.branch", string="Branch")
district_id = fields.Many2one("res.district", string="District")
region_id = fields.Many2one("res.region", string="Region")
current_location_id = fields.Many2one("fsm.location", string="Current Location")
managed_by_id = fields.Many2one("res.partner", string="Managed By")
owned_by_id = fields.Many2one("res.partner", string="Owned By")
parent_id = fields.Many2one("fsm.equipment", string="Parent")
child_ids = fields.One2many("fsm.equipment", "parent_id", string="Children")
managed_by_id = fields.Many2one(
"res.partner",
string="Managed By",
check_company=True,
)
owned_by_id = fields.Many2one(
"res.partner",
string="Owned By",
check_company=True,
)
parent_id = fields.Many2one(
"fsm.equipment",
string="Parent",
check_company=True,
)
child_ids = fields.One2many(
"fsm.equipment",
"parent_id",
string="Children",
check_company=True,
)
color = fields.Integer("Color Index")
company_id = fields.Many2one(
"res.company",
Expand Down
10 changes: 9 additions & 1 deletion fieldservice/models/fsm_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class FSMOrder(models.Model):
_name = "fsm.order"
_description = "Field Service Order"
_inherit = ["mail.thread", "mail.activity.mixin"]
_check_company_auto = True

def _default_stage_id(self):
stage = self.env["fsm.stage"].search(
Expand Down Expand Up @@ -71,6 +72,7 @@ def _track_subtype(self, init_values):
tracking=True,
index=True,
copy=False,
check_company=True,
group_expand="_read_group_stage_ids",
default=lambda self: self._default_stage_id(),
)
Expand All @@ -90,6 +92,7 @@ def _track_subtype(self, init_values):
"tag_id",
string="Tags",
help="Classify and analyze your orders",
check_company=True,
)
color = fields.Integer("Color Index", default=0)
team_id = fields.Many2one(
Expand All @@ -99,6 +102,7 @@ def _track_subtype(self, init_values):
index=True,
required=True,
tracking=True,
check_company=True,
)

# Request
Expand Down Expand Up @@ -153,7 +157,11 @@ def _calc_request_late(self, vals):
request_late = fields.Datetime(string="Latest Request Date")
description = fields.Text()

person_ids = fields.Many2many("fsm.person", string="Field Service Workers")
person_ids = fields.Many2many(
"fsm.person",
string="Field Service Workers",
check_company=True,
)

@api.onchange("location_id")
def _onchange_location_id_customer(self):
Expand Down
2 changes: 2 additions & 0 deletions fieldservice/models/fsm_stage.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class FSMStage(models.Model):
_name = "fsm.stage"
_description = "Field Service Stage"
_order = "sequence, name, id"
_check_company_auto = True

def _default_team_ids(self):
default_team_id = self.env.context.get("default_team_id")
Expand Down Expand Up @@ -63,6 +64,7 @@ def _default_team_ids(self):
"team_id",
string="Teams",
default=lambda self: self._default_team_ids(),
check_company=True,
)

def get_color_information(self):
Expand Down
3 changes: 2 additions & 1 deletion fieldservice/models/fsm_tag.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@
class FSMTag(models.Model):
_name = "fsm.tag"
_description = "Field Service Tag"
_check_company_auto = True

name = fields.Char(required=True)
parent_id = fields.Many2one("fsm.tag", string="Parent")
parent_id = fields.Many2one("fsm.tag", string="Parent", check_company=True)
color = fields.Integer("Color Index", default=10)
full_name = fields.Char(compute="_compute_full_name")
company_id = fields.Many2one(
Expand Down
3 changes: 3 additions & 0 deletions fieldservice/models/fsm_team.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class FSMTeam(models.Model):
_name = "fsm.team"
_description = "Field Service Team"
_inherit = ["mail.thread", "mail.activity.mixin"]
_check_company_auto = True

def _default_stages(self):
return self.env["fsm.stage"].search([("is_default", "=", True)])
Expand Down Expand Up @@ -60,12 +61,14 @@ def _compute_order_need_schedule_count(self):
"stage_id",
string="Stages",
default=_default_stages,
check_company=True,
)
order_ids = fields.One2many(
"fsm.order",
"team_id",
string="Orders",
domain=[("stage_id.is_closed", "=", False)],
check_company=True,
)
order_count = fields.Integer(compute="_compute_order_count", string="Orders Count")
order_need_assign_count = fields.Integer(
Expand Down
2 changes: 2 additions & 0 deletions fieldservice/models/fsm_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
class FSMTemplate(models.Model):
_name = "fsm.template"
_description = "Field Service Order Template"
_check_company_auto = True

name = fields.Char(required=True)
instructions = fields.Text()
Expand All @@ -23,4 +24,5 @@ class FSMTemplate(models.Model):
"fsm.team",
string="Team",
help="Choose a team to be set on orders of this template",
check_company=True,
)
2 changes: 2 additions & 0 deletions fieldservice/tests/test_fsm_order_template_onchange.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ def test_fsm_order_onchange_template(self):
"category_ids": [(6, 0, categories)],
"duration": 2.25,
"type_id": self.fsm_type_a.id,
"company_id": self.env.company.id,
}
)
self.fsm_template_2 = self.env["fsm.template"].create(
Expand All @@ -38,6 +39,7 @@ def test_fsm_order_onchange_template(self):
"category_ids": [(6, 0, categories)],
"duration": 2.25,
"team_id": self.fsm_team_a.id,
"company_id": self.env.company.id,
}
)
self.fso = self.Order.create(
Expand Down
10 changes: 10 additions & 0 deletions fieldservice/views/fsm_equipment.xml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@
<field name="location_id" />
<field name="current_location_id" />
<field name="company_id" groups="base.group_multi_company" />
<field
name="company_id"
column_invisible="1"
groups="!base.group_multi_company"
/>
<field name="stage_id" />
</tree>
</field>
Expand Down Expand Up @@ -113,6 +118,11 @@
options="{'no_create': True}"
groups="base.group_multi_company"
/>
<field
name="company_id"
invisible="1"
groups="!base.group_multi_company"
/>
</group>
</group>
<group id="secondary" />
Expand Down
10 changes: 10 additions & 0 deletions fieldservice/views/fsm_order.xml
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@
options="{'no_create': True}"
groups="base.group_multi_company"
/>
<field
name="company_id"
invisible="1"
groups="!base.group_multi_company"
/>
</group>
</group>
<group string="Description" name="description_grp">
Expand Down Expand Up @@ -223,6 +228,11 @@
<field name="person_id" />
<field name="stage_id" string="Stage" />
<field name="company_id" groups="base.group_multi_company" />
<field
name="company_id"
column_invisible="1"
groups="!base.group_multi_company"
/>
</tree>
</field>
</record>
Expand Down
5 changes: 5 additions & 0 deletions fieldservice/views/fsm_stage.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@
<field name="fold" />
<field name="is_closed" />
<field name="is_default" />
<field
name="company_id"
invisible="1"
groups="!base.group_multi_company"
/>
<field
name="company_id"
groups="base.group_multi_company"
Expand Down
5 changes: 5 additions & 0 deletions fieldservice/views/fsm_tag.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@
options="{'no_create': True}"
groups="base.group_multi_company"
/>
<field
name="company_id"
invisible="1"
groups="!base.group_multi_company"
/>
</group>
</group>
</sheet>
Expand Down
10 changes: 10 additions & 0 deletions fieldservice/views/fsm_template.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@
/>
<field name="team_id" groups="fieldservice.group_fsm_team" />
<field name="company_id" groups="base.group_multi_company" />
<field
name="company_id"
column_invisible="1"
groups="!base.group_multi_company"
/>
</tree>
</field>
</record>
Expand All @@ -37,6 +42,11 @@
options="{'no_create': True}"
groups="base.group_multi_company"
/>
<field
name="company_id"
invisible="1"
groups="!base.group_multi_company"
/>
</group>
<group>
<field name="type_id" />
Expand Down

0 comments on commit 38c2f44

Please sign in to comment.