Skip to content

Commit

Permalink
[IMP] fieldservice: request_late now calculated based on settings
Browse files Browse the repository at this point in the history
  • Loading branch information
aleuffre authored and brian10048 committed Nov 13, 2023
1 parent d59436d commit 2416adb
Show file tree
Hide file tree
Showing 4 changed files with 121 additions and 1 deletion.
26 changes: 25 additions & 1 deletion fieldservice/models/fsm_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,31 @@ def _track_subtype(self, init_values):
default=lambda self: self.env.company,
help="Company related to this order",
)

def _compute_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 @@ -280,7 +305,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
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
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

0 comments on commit 2416adb

Please sign in to comment.