Skip to content

Commit

Permalink
[MIG] fieldservice_mobile: Migration to 15.0
Browse files Browse the repository at this point in the history
  • Loading branch information
marionumza committed Aug 4, 2024
1 parent 894c2ec commit 28ee31d
Show file tree
Hide file tree
Showing 16 changed files with 379 additions and 0 deletions.
38 changes: 38 additions & 0 deletions fieldservice_mobile/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
.. image:: https://img.shields.io/badge/licence-LGPL--3-blue.svg
:target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html
:alt: License: LGPL-3

====================
Field Service Mobile
====================

This module is manage FSM mobile stages based on configuration.

Configuration
=============

To configure this module, you need to:

* Go to Field Service > Configuration > Stages.
* Check Display in Mobile for display stage in FSM Mobile.
* Check Display in Odoo for display stage in Odoo FSM Order.
* Select a server action based on Stages.

* Manage domain on Automated Actions based on Stage sequence.

For Example:- If the Started stage sequence is 6.

* Go to Settings > Automated Actions > FSM Order Started Stage Update > Apply on > [["stage_id.sequence","=",6]]

Credits
=======

* Open Source Integrators <https://opensourceintegrators.com>
* Serpent Consulting Services Pvt. Ltd. <[email protected]>

Contributors
~~~~~~~~~~~~

* Wolfgang Hall <[email protected]>
* Sandip Mangukiya <[email protected]>
* Serpent Consulting Services Pvt. Ltd. <[email protected]>
3 changes: 3 additions & 0 deletions fieldservice_mobile/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from . import models
24 changes: 24 additions & 0 deletions fieldservice_mobile/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Copyright (C) 2020 Open Source Integrators
# Copyright (C) 2020 Serpent Consulting Services Pvt. Ltd.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

{
"name": "Field Service Mobile",
"summary": "Field Service Mobile backend support.",
"license": "AGPL-3",
"version": "12.0.1.1.0",
"category": "Field Service",
"author": "Open Source Integrators",
"website": "https://github.com/ursais/osi-addons",
"depends": ["fieldservice_stage_server_action", "stock"],
"data": [
"security/ir_rule.xml",
"security/ir.model.access.csv",
"data/base_automation.xml",
"views/res_config_settings.xml",
"views/fsm_stage_view.xml",
"views/fsm_order_view.xml",
],
"development_status": "Beta",
"maintainers": ["wolfhall"],
}
89 changes: 89 additions & 0 deletions fieldservice_mobile/data/base_automation.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
<odoo>

<record id="fsm_order_started_stage_update" model="base.automation">
<field name="name">FSM Order Started Stage Update</field>
<field name="model_id" ref="fieldservice.model_fsm_order"/>
<field name="trigger">on_write</field>
<field name="active" eval="True"/>
<field name="filter_domain">[["stage_id.sequence","=",6]]</field>
<field name="state">code</field>
<field name="code">for rec in records:
stage_rec = env['fsm.stage.history'].search([('order_id', '=', rec.id)], order='id desc', limit=1)
call_it = False
if not stage_rec:
call_it = True
if stage_rec.stage_id != rec.stage_id:
call_it = True
if call_it and rec.stage_id.action_id:
rec.write(
{'date_start': datetime.datetime.now(),
'fsm_stage_history_ids': [(0, 0, {'start_datetime': datetime.datetime.now(), 'stage_id': rec.stage_id.id, 'duration': 0.0, 'total_duration': 0.0
})]})</field>
</record>

<record id="fsm_order_break_stage_update" model="base.automation">
<field name="name">FSM Order Break Stage Update</field>
<field name="model_id" ref="fieldservice.model_fsm_order"/>
<field name="trigger">on_write</field>
<field name="active" eval="True"/>
<field name="filter_domain">[["stage_id.sequence","=",7]]</field>
<field name="state">code</field>
<field name="code">for rec in records:
stage_rec = env['fsm.stage.history'].search([('order_id', '=', rec.id)], order='id desc', limit=1)
call_it = False
if not stage_rec:
call_it = True
if stage_rec.stage_id != rec.stage_id:
call_it = True
if call_it and rec.stage_id.action_id:
delta = datetime.datetime.now() - stage_rec.start_datetime
duration = round((delta.total_seconds() / 3600), 2)
rec.write(
{'fsm_stage_history_ids': [(0, 0, {'start_datetime': datetime.datetime.now(), 'stage_id': rec.stage_id.id, 'duration': duration, 'total_duration': round((duration + stage_rec.total_duration), 2)
})]})</field>
</record>

<record id="fsm_order_resume_stage_update" model="base.automation">
<field name="name">FSM Order Resume Stage Update</field>
<field name="model_id" ref="fieldservice.model_fsm_order"/>
<field name="trigger">on_write</field>
<field name="active" eval="True"/>
<field name="filter_domain">[["stage_id.sequence","=", 8]]</field>
<field name="state">code</field>
<field name="code">for rec in records:
stage_rec = env['fsm.stage.history'].search([('order_id', '=', rec.id)], order='id desc', limit=1)
call_it = False
if not stage_rec:
call_it = True
if stage_rec.stage_id != rec.stage_id:
call_it = True
if call_it and rec.stage_id.action_id:
rec.write(
{'fsm_stage_history_ids': [(0, 0, {'start_datetime': datetime.datetime.now(), 'stage_id': rec.stage_id.id, 'duration': 0.0, 'total_duration': round((rec.duration + stage_rec.total_duration), 2)
})]})</field>
</record>

<record id="fsm_order_completed_stage_update" model="base.automation">
<field name="name">FSM Order Completed Stage Update</field>
<field name="model_id" ref="fieldservice.model_fsm_order"/>
<field name="trigger">on_write</field>
<field name="active" eval="True"/>
<field name="filter_domain">[["stage_id.sequence","=",9]]</field>
<field name="state">code</field>
<field name="code">for rec in records:
stage_rec = env['fsm.stage.history'].search([('order_id', '=', rec.id)], order='id desc', limit=1)
call_it = False
if not stage_rec:
call_it = True
if stage_rec.stage_id != rec.stage_id:
call_it = True
if call_it and rec.stage_id.action_id:
delta = datetime.datetime.now() - stage_rec.start_datetime
duration = round((delta.total_seconds() / 3600), 2)
rec.write(
{'date_end': datetime.datetime.now(),
'fsm_stage_history_ids': [(0, 0, {'start_datetime': datetime.datetime.now(), 'stage_id': rec.stage_id.id, 'duration': duration, 'total_duration': round((duration + stage_rec.total_duration), 2)
})]})</field>
</record>

</odoo>
7 changes: 7 additions & 0 deletions fieldservice_mobile/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from . import fsm_stage
from . import fsm_order
from . import fsm_stage_history
from . import res_config_settings
from . import res_users
43 changes: 43 additions & 0 deletions fieldservice_mobile/models/fsm_order.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Copyright (C) 2020 Open Source Integrators
# Copyright (C) 2020 Serpent Consulting Services Pvt. Ltd.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import api, fields, models


class FSMOrder(models.Model):
_inherit = "fsm.order"

@api.depends("date_start", "date_end")
def _compute_duration(self):
res = super()._compute_duration()
for rec in self:
if rec.fsm_stage_history_ids and rec.date_end:
stage_rec = self.env["fsm.stage.history"].search(

Check warning on line 16 in fieldservice_mobile/models/fsm_order.py

View check run for this annotation

Codecov / codecov/patch

fieldservice_mobile/models/fsm_order.py#L16

Added line #L16 was not covered by tests
[("order_id", "=", rec.id)], order="id desc", limit=1
)
rec.duration = stage_rec.total_duration

Check warning on line 19 in fieldservice_mobile/models/fsm_order.py

View check run for this annotation

Codecov / codecov/patch

fieldservice_mobile/models/fsm_order.py#L19

Added line #L19 was not covered by tests
elif not rec.date_end:
rec.duration = 0.0
return res

duration = fields.Float(
string="Actual duration",
compute=_compute_duration,
help="Actual duration in hours",
store=True,
)
fsm_stage_history_ids = fields.One2many(
"fsm.stage.history", "order_id", string="Stage History"
)

@api.model
def create_fsm_attachment(self, name, datas, res_model, res_id):
if res_model == "fsm.order":
attachment = self.env["ir.attachment"].sudo().create({

Check warning on line 37 in fieldservice_mobile/models/fsm_order.py

View check run for this annotation

Codecov / codecov/patch

fieldservice_mobile/models/fsm_order.py#L37

Added line #L37 was not covered by tests
"name": name,
"datas": datas,
"res_model": res_model,
"res_id": res_id,
})
return attachment.id

Check warning on line 43 in fieldservice_mobile/models/fsm_order.py

View check run for this annotation

Codecov / codecov/patch

fieldservice_mobile/models/fsm_order.py#L43

Added line #L43 was not covered by tests
12 changes: 12 additions & 0 deletions fieldservice_mobile/models/fsm_stage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Copyright (C) 2020 Open Source Integrators
# Copyright (C) 2020 Serpent Consulting Services Pvt. Ltd.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import fields, models


class FSMStage(models.Model):
_inherit = "fsm.stage"

is_display_in_mobile = fields.Boolean("Display in Mobile", default=False)
is_display_in_odoo = fields.Boolean("Display in Odoo", default=True)
16 changes: 16 additions & 0 deletions fieldservice_mobile/models/fsm_stage_history.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Copyright (C) 2020 Open Source Integrators
# Copyright (C) 2020 Serpent Consulting Services Pvt. Ltd.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import fields, models


class FsmStageHistory(models.Model):
_name = "fsm.stage.history"
_description = "FSM Stage History"

order_id = fields.Many2one("fsm.order", string="FSM Order")
start_datetime = fields.Datetime("Start Date&time")
stage_id = fields.Many2one("fsm.stage", string="Stage")
duration = fields.Float(string="Duration",)
total_duration = fields.Float(string="Total Duration",)
18 changes: 18 additions & 0 deletions fieldservice_mobile/models/res_config_settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Copyright (C) 2020 Open Source Integrators
# Copyright (C) 2020 Serpent Consulting Services Pvt. Ltd.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import fields, models


class ResConfigSettings(models.TransientModel):
_inherit = "res.config.settings"

fsm_allow_portal_view_move_qty = fields.Boolean(
string="Allow portal user to view stock move quantities",
config_parameter="fieldservice_mobile.fsm_allow_portal_view_move_qty",
)
fsm_allow_portal_update_move_qty = fields.Boolean(
string="Allow portal user update of stock move quantities",
config_parameter="fieldservice_mobile.fsm_allow_portal_update_move_qty",
)
26 changes: 26 additions & 0 deletions fieldservice_mobile/models/res_users.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Copyright (C) 2020 Open Source Integrators
# Copyright (C) 2020 Serpent Consulting Services Pvt. Ltd.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import api, models


class Users(models.Model):
_inherit = "res.users"

@api.model
def get_portal_config_values(self, config_parameters=[]):
params_dict = {}

Check warning on line 13 in fieldservice_mobile/models/res_users.py

View check run for this annotation

Codecov / codecov/patch

fieldservice_mobile/models/res_users.py#L13

Added line #L13 was not covered by tests
for config_param in config_parameters:
if config_param in [
"fieldservice_mobile.fsm_allow_portal_view_move_qty",
"fieldservice_mobile.fsm_allow_portal_update_move_qty",
"fieldservice_mobile.fsm_allow_portal_validate_move_qty",
"fieldservice_sale_order_line.fsm_allow_portal_view_sol_qty",
"fieldservice_sale_order_line.fsm_allow_portal_update_sol_qty",
]:
params = self.env["ir.config_parameter"].sudo()
params_dict.update({

Check warning on line 23 in fieldservice_mobile/models/res_users.py

View check run for this annotation

Codecov / codecov/patch

fieldservice_mobile/models/res_users.py#L22-L23

Added lines #L22 - L23 were not covered by tests
config_param: bool(params.get_param(config_param))
})
return params_dict

Check warning on line 26 in fieldservice_mobile/models/res_users.py

View check run for this annotation

Codecov / codecov/patch

fieldservice_mobile/models/res_users.py#L26

Added line #L26 was not covered by tests
5 changes: 5 additions & 0 deletions fieldservice_mobile/security/ir.model.access.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
access_fsm_stage_history_fsm_user,fsm.stage.history.user,model_fsm_stage_history,fieldservice.group_fsm_user,1,1,1,0
access_fsm_stage_history_fsm_manager,fsm.stage.history.manager,model_fsm_stage_history,fieldservice.group_fsm_manager,1,1,1,1
access_fsm_stage_history_portal,fsm.stage.history.portal,model_fsm_stage_history,base.group_portal,1,1,1,0
stock.access_stock_move_line_portal,stock.move.line portal,stock.model_stock_move_line,base.group_portal,1,0,1,0
14 changes: 14 additions & 0 deletions fieldservice_mobile/security/ir_rule.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<odoo noupdate="1">

<record id="portal_partner_comp_rule" model="ir.rule">
<field name="name">Portal Partner multi-company</field>
<field name="model_id" ref="base.model_res_partner"/>
<field name="global" eval="True"/>
<field name="domain_force">['|',('company_id','=',False),('company_id','child_of',[user.company_id.id])]</field>
<field name="groups" eval="[(4, ref('base.group_portal'))]"/>
<field name="perm_create" eval="False"/>
<field name="perm_write" eval="False"/>
<field name="perm_unlink" eval="False"/>
</record>

</odoo>
Binary file added fieldservice_mobile/static/description/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
31 changes: 31 additions & 0 deletions fieldservice_mobile/views/fsm_order_view.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<odoo>

<record id="view_fsm_order_view_form_inherit_mobile" model="ir.ui.view">
<field name="name">view.fsm.order.inherit.mobile</field>
<field name="model">fsm.order</field>
<field name="inherit_id" ref="fieldservice.fsm_order_form"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='stage_id']" position="attributes">
<attribute name="domain">[('stage_type', '=', 'order'),
('team_ids', 'in', (team_id, False)),
('is_display_in_odoo', '=', True)]</attribute>
</xpath>
<field name="duration" position="attributes">
<attribute name="widget">float_time</attribute>
</field>
<xpath expr="//notebook/page[@name='execution_page']/group" position="after">
<group string="Stages History">
<field name="fsm_stage_history_ids" nolabel="1" readonly="1">
<tree editable="bottom">
<field name="start_datetime" required="1"/>
<field name="stage_id" required="1"/>
<field name="duration" widget="float_time"/>
<field name="total_duration" widget="float_time"/>
</tree>
</field>
</group>
</xpath>
</field>
</record>

</odoo>
15 changes: 15 additions & 0 deletions fieldservice_mobile/views/fsm_stage_view.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<odoo>

<record id="fsm_stage_form_view_inherit_mobile" model="ir.ui.view">
<field name="name">fsm.stage.form.inherit.mobile</field>
<field name="model">fsm.stage</field>
<field name="inherit_id" ref="fieldservice.fsm_stage_form_view"/>
<field name="arch" type="xml">
<field name="is_default" position="after">
<field name="is_display_in_mobile"/>
<field name="is_display_in_odoo"/>
</field>
</field>
</record>

</odoo>
38 changes: 38 additions & 0 deletions fieldservice_mobile/views/res_config_settings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<odoo>

<record id="res_config_settings_view_form_mobile" model="ir.ui.view">
<field name="name">res.config.settings.view.form.fsm.mobile</field>
<field name="model">res.config.settings</field>
<field name="priority" eval="40"/>
<field name="inherit_id" ref="fieldservice.res_config_settings_view_form"/>
<field name="arch" type="xml">
<div id="orders" position="inside">
<div class="col-xs-12 col-md-6 o_setting_box">
<div class="o_setting_left_pane">
<field name="fsm_allow_portal_view_move_qty"/>
</div>
<div class="o_setting_right_pane">
<label for="fsm_allow_portal_view_move_qty"
string="Allow portal user to view stock move quantities"/>
<div class="text-muted">
Allow portal user to view stock move quantities
</div>
</div>
</div>
<div class="col-xs-12 col-md-6 o_setting_box">
<div class="o_setting_left_pane">
<field name="fsm_allow_portal_update_move_qty"/>
</div>
<div class="o_setting_right_pane">
<label for="fsm_allow_portal_update_move_qty"
string="Allow portal user update of stock move quantities"/>
<div class="text-muted">
Allow portal user update of stock move quantities
</div>
</div>
</div>
</div>
</field>
</record>

</odoo>

0 comments on commit 28ee31d

Please sign in to comment.