Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[16.0] Forward Ports from 14.0 #1135

Merged
merged 8 commits into from
Nov 17, 2023
51 changes: 30 additions & 21 deletions fieldservice/models/fsm_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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()

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 5 additions & 1 deletion fieldservice/models/fsm_person_calendar_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
16 changes: 16 additions & 0 deletions fieldservice/models/res_company.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
20 changes: 20 additions & 0 deletions fieldservice/models/res_config_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
24 changes: 12 additions & 12 deletions fieldservice/security/ir.model.access.csv
Original file line number Diff line number Diff line change
@@ -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
17 changes: 17 additions & 0 deletions fieldservice/security/ir_rule.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,23 @@
name="domain_force"
>['|',('company_id','=',False),('company_id', 'in', company_ids)]</field>
</record>

<record id="fsm_order_own_rule" model="ir.rule">
<field name="name">FSM Orders Entry (only own)</field>
<field name="model_id" ref="model_fsm_order" />
<field
name="domain_force"
>['|',('person_id.user_ids','=',user.id),('person_id','=',False)]</field>
<field name="groups" eval="[(4, ref('fieldservice.group_fsm_user_own'))]" />
</record>

<record id="fsm_order_user" model="ir.rule">
<field name="name">FSM Orders Entry</field>
<field name="model_id" ref="model_fsm_order" />
<field name="domain_force">[(1, '=', 1)]</field>
<field name="groups" eval="[(4, ref('fieldservice.group_fsm_user'))]" />
</record>

<record id="fsm_template_comp_rule" model="ir.rule">
<field name="name">FSM Templates Entry</field>
<field name="model_id" ref="model_fsm_template" />
Expand Down
11 changes: 10 additions & 1 deletion fieldservice/security/res_groups.xml
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
<odoo>
<!-- FSM groups -->
<record id="group_fsm_user_own" model="res.groups">
<field name="name">User (only own documents)</field>
<field name="category_id" ref="fsm" />
<field name="implied_ids" eval="[(4, ref('base.group_user'))]" />
</record>

<record id="group_fsm_user" model="res.groups">
<field name="name">User</field>
<field name="category_id" ref="fsm" />
<field name="implied_ids" eval="[(4, ref('base.group_user'))]" />
<field
name="implied_ids"
eval="[(4, ref('fieldservice.group_fsm_user_own'))]"
/>
</record>
<record id="group_fsm_dispatcher" model="res.groups">
<field name="name">Dispatcher</field>
Expand Down
12 changes: 9 additions & 3 deletions fieldservice/views/fsm_location.xml
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,11 @@
<group id="main-left">
<field name="id" invisible="1" />
<field name="fsm_parent_id" domain="[('id', '!=', id)]" />
<field
name="partner_id"
groups="base.group_no_one"
readonly="1"
/>
<field name="owner_id" />
<field
name="contact_id"
Expand Down Expand Up @@ -162,7 +167,7 @@
<field name="notes" nolabel="1" colspan="2" widget="html" />
</group>
<notebook>
<page string="Directions">
<page string="Directions" name="directions">
<field
name="direction"
nolabel="1"
Expand All @@ -172,6 +177,7 @@
</page>
<page
string="Territory"
name="territory"
groups="fieldservice.group_fsm_territory"
>
<group id="territory">
Expand All @@ -189,7 +195,7 @@
</group>
</group>
</page>
<page string="Preferred Workers">
<page string="Preferred Workers" name="preferred_workers">
<field name="person_ids" nolabel="1">
<tree editable="bottom">
<field name="sequence" widget="handle" />
Expand All @@ -199,7 +205,7 @@
</tree>
</field>
</page>
<page string="Others" id="others-page">
<page string="Others" id="others-page" name="others">
<group id="others">
<group id="others-left" />
<group id="others-right" />
Expand Down
9 changes: 5 additions & 4 deletions fieldservice/views/fsm_order.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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))]}"
/>
<button
Expand Down Expand Up @@ -317,7 +317,7 @@
</div>
<div class="oe_kanban_bottom_right">
<img
t-att-src="kanban_image('person', 'image_small', record.person_id.name)"
t-att-src="kanban_image('fsm.person', 'image_128', record.person_id.raw_value)"
t-att-title="record.person_id.name"
t-att-alt="record.person_id.name"
width="24"
Expand Down Expand Up @@ -460,15 +460,16 @@
color="stage_id"
>
<field name="name" />
<field name="stage_id" />
<field name="stage_id" filters="1" />
<field name="location_id" />
<field name="phone" />
<field
name="person_id"
write_model="fsm.person.calendar.filter"
write_field="fsm_person_id"
avatar_field="image_small"
avatar_field="image_128"
/>
<field name="team_id" filters="1" />
<field name="person_phone" />
<field name="city" />
<field name="state_name" />
Expand Down
5 changes: 5 additions & 0 deletions fieldservice/views/fsm_person.xml
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,11 @@
</h1>
<group>
<group>
<field
name="partner_id"
groups="base.group_no_one"
readonly="1"
/>
<field
name="category_ids"
widget="many2many_tags"
Expand Down
2 changes: 1 addition & 1 deletion fieldservice/views/menu.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
id="root"
name="Field Service"
sequence="10"
groups="group_fsm_user"
groups="group_fsm_user_own"
web_icon="fieldservice,static/description/icon.png"
/>
<menuitem id="dashboard" name="Dashboard" sequence="10" parent="root" />
Expand Down
60 changes: 60 additions & 0 deletions fieldservice/views/res_config_settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,66 @@
</div>
<h2>Orders</h2>
<div class="row mt16 o_settings_container" id="orders">
<div class="col-xs-12 col-md-6 o_setting_box">
<div class="o_setting_left_pane" />
<div class="o_setting_right_pane">
<span class="o_form_label">
Priority-based rules
</span>
<div
class="text-muted"
>Automatically calculate the "Latest Request Date" based on an order's priority</div>
<div class="content-group" modifiers="{}">
<div class="row mt16" modifiers="{}">
<label
string="Priority 0"
for="fsm_order_request_late_lowest"
class="col-lg-3 o_light_label"
/>
<field
name="fsm_order_request_late_lowest"
/><span class="ml-2">hours</span>
</div>
<div class="row mt16" modifiers="{}">
<label
string="Priority 1"
for="fsm_order_request_late_low"
class="col-lg-3 o_light_label"
/>
<field name="fsm_order_request_late_low" /><span
class="ml-2"
>hours</span>
</div>
</div>
</div>
</div>
<div class="col-xs-12 col-md-6 o_setting_box">
<div class="o_setting_left_pane" />
<div class="o_setting_right_pane">
<div class="content-group" modifiers="{}">
<div class="row mt16" modifiers="{}">
<label
string="Priority 2"
for="fsm_order_request_late_medium"
class="col-lg-3 o_light_label"
/>
<field
name="fsm_order_request_late_medium"
/><span class="ml-2">hours</span>
</div>
<div class="row mt16" modifiers="{}">
<label
string="Priority 3"
for="fsm_order_request_late_high"
class="col-lg-3 o_light_label"
/>
<field
name="fsm_order_request_late_high"
/><span class="ml-2">hours</span>
</div>
</div>
</div>
</div>
<div
class="col-xs-12 col-md-6 o_setting_box"
attrs="{'invisible': [('group_fsm_equipment', '=', False)]}"
Expand Down
Loading
Loading