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

[15.0][MIG] fieldservice_portal: Migration to 15.0 #1289

Open
wants to merge 4 commits into
base: 15.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
93 changes: 93 additions & 0 deletions fieldservice_portal/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
======================
Field Service - Portal
======================

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:bfddb8307746f6f3179ded15fd2c7b9a6622c6e21d24ae73c9aece10a7f455f6
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
:target: https://odoo-community.org/page/development-status
:alt: Beta
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Ffield--service-lightgray.png?logo=github
:target: https://github.com/OCA/field-service/tree/15.0/fieldservice_portal
:alt: OCA/field-service
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/field-service-15-0/field-service-15-0-fieldservice_portal
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
:target: https://runboat.odoo-community.org/builds?repo=OCA/field-service&target_branch=15.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|

Bridge module between fieldservice and portal that allows portal users
to monitor work orders related to their locations.

**Table of contents**

.. contents::
:local:

Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/OCA/field-service/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
`feedback <https://github.com/OCA/field-service/issues/new?body=module:%20fieldservice_portal%0Aversion:%2015.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

Do not contact contributors directly about support or help with technical issues.

Credits
=======

Authors
~~~~~~~

* PyTech SRL

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

* `PyTech SRL <https://www.pytech.it>`_:

* Alessio Renda <alessio.renda@pytech.it>

- [APSL-Nagarro](https://www.apsl.tech):
- Patryk Pyczko \<<ppyczko@apsl.net>\>

Maintainers
~~~~~~~~~~~

This module is maintained by the OCA.

.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org

OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.

.. |maintainer-aleuffre| image:: https://github.com/aleuffre.png?size=40px
:target: https://github.com/aleuffre
:alt: aleuffre
.. |maintainer-renda-dev| image:: https://github.com/renda-dev.png?size=40px
:target: https://github.com/renda-dev
:alt: renda-dev

Current `maintainers <https://odoo-community.org/page/maintainer-role>`__:

|maintainer-aleuffre| |maintainer-renda-dev|

This module is part of the `OCA/field-service <https://github.com/OCA/field-service/tree/15.0/fieldservice_portal>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
1 change: 1 addition & 0 deletions fieldservice_portal/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import controllers
33 changes: 33 additions & 0 deletions fieldservice_portal/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"name": "Field Service - Portal",
"version": "15.0.1.0.0",
"summary": """
Bridge module between fieldservice and portal.
""",
"depends": [
"fieldservice",
"portal",
],
"author": "PyTech SRL, Odoo Community Association (OCA)",
"maintainers": ["aleuffre", "renda-dev"],
"website": "https://github.com/OCA/field-service",
"category": "Field Service",
"license": "AGPL-3",
"data": [
"security/ir.model.access.csv",
"security/portal_security.xml",
"views/fsm_order_template.xml",
"views/portal_template.xml",
],
"demo": [
"demo/fsm_location_demo.xml",
"demo/fsm_order_demo.xml",
],
"assets": {
"web.assets_frontend": [
"fieldservice_portal/static/src/js/fsm_order_portal.js",
],
},
"installable": True,
"application": False,
}
1 change: 1 addition & 0 deletions fieldservice_portal/controllers/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import fsm_order_portal
211 changes: 211 additions & 0 deletions fieldservice_portal/controllers/fsm_order_portal.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,211 @@
from collections import OrderedDict
from operator import itemgetter

from odoo import _, http
from odoo.exceptions import AccessError
from odoo.http import request
from odoo.osv.expression import OR
from odoo.tools import groupby as groupbyelem

from odoo.addons.portal.controllers.portal import CustomerPortal, pager as portal_pager


class CustomerPortal(CustomerPortal):
def _prepare_home_portal_values(self, counters):
values = super()._prepare_home_portal_values(counters)
if "fsm_order_count" in counters:
fsm_order_count = (
request.env["fsm.order"].search_count([])
if request.env["fsm.order"].check_access_rights(
"read", raise_exception=False
)
else 0
)
values["fsm_order_count"] = fsm_order_count
return values

def _fsm_order_check_access(self, order_id):
fsm_order = request.env["fsm.order"].browse([order_id])

try:
fsm_order.check_access_rights("read")
fsm_order.check_access_rule("read")
except AccessError:
raise
return fsm_order.sudo()

def fsm_order_get_page_view_values(self, fsm_order, **kwargs):
values = {
"page_name": "fsm_order",
"fsm_order": fsm_order,
}

if kwargs.get("error"):
values["error"] = kwargs["error"]

Check warning on line 44 in fieldservice_portal/controllers/fsm_order_portal.py

View check run for this annotation

Codecov / codecov/patch

fieldservice_portal/controllers/fsm_order_portal.py#L44

Added line #L44 was not covered by tests
if kwargs.get("warning"):
values["warning"] = kwargs["warning"]

Check warning on line 46 in fieldservice_portal/controllers/fsm_order_portal.py

View check run for this annotation

Codecov / codecov/patch

fieldservice_portal/controllers/fsm_order_portal.py#L46

Added line #L46 was not covered by tests
if kwargs.get("success"):
values["success"] = kwargs["success"]

return values

@http.route(
["/my/fsm_orders", "/my/fsm_orders/page/<int:page>"],
type="http",
auth="user",
website=True,
)
def portal_my_fsm_orders(
self,
page=1,
date_begin=None,
date_end=None,
sortby=None,
filterby=None,
groupby=None,
search=None,
search_in="all",
**kw
):
values = self._prepare_portal_layout_values()
FsmOrder = request.env["fsm.order"]
domain = []

searchbar_sortings = {
"date": {"label": _("Newest"), "order": "request_early desc"},
"name": {"label": _("Name"), "order": "name"},
"stage": {"label": _("Stage"), "order": "stage_id"},
"location": {"label": _("Location"), "order": "location_id"},
"type": {"label": _("Type"), "order": "type"},
}

searchbar_groupby = {
"none": {"input": "none", "label": _("None")},
"location_id": {"input": "location", "label": _("Location")},
"stage_id": {"input": "stage", "label": _("Stage")},
"type": {"input": "type", "label": _("Type")},
}

# search input (text)
searchbar_inputs = OrderedDict(
(
("all", {"input": "all", "label": _("Search in All")}),
("name", {"input": "name", "label": _("Search in WO Number")}),
(
"description",
{
"input": "description",
"label": _("Search in Description"),
},
),
(
"location_id.name",
{
"input": "location",
"label": _("Search in Location Numbers"),
},
),
)
)

if search and search_in:
search_domain = []

Check warning on line 112 in fieldservice_portal/controllers/fsm_order_portal.py

View check run for this annotation

Codecov / codecov/patch

fieldservice_portal/controllers/fsm_order_portal.py#L112

Added line #L112 was not covered by tests
for search_property in [
k
for (k, v) in searchbar_inputs.items()
if search_in in (v["input"], "all") and k != "all"
]:
search_domain = OR(

Check warning on line 118 in fieldservice_portal/controllers/fsm_order_portal.py

View check run for this annotation

Codecov / codecov/patch

fieldservice_portal/controllers/fsm_order_portal.py#L118

Added line #L118 was not covered by tests
[search_domain, [(search_property, "ilike", search)]]
)
domain += search_domain

Check warning on line 121 in fieldservice_portal/controllers/fsm_order_portal.py

View check run for this annotation

Codecov / codecov/patch

fieldservice_portal/controllers/fsm_order_portal.py#L121

Added line #L121 was not covered by tests

# search filters (by stage)
searchbar_filters = OrderedDict(
(
str(stage.name),
{
"label": stage.name,
"domain": [("stage_id", "=", stage.id)],
},
)
for stage in request.env["fsm.stage"].search([("stage_type", "=", "order")])
)
searchbar_filters.update(
{
"all": {"label": _("All"), "domain": []},
"open": {"label": _("Open"), "domain": [("is_closed", "=", False)]},
}
)

# default group by value
if not groupby:
groupby = "location_id"
# default sort by order
if not sortby:
sortby = "date"
order = searchbar_sortings[sortby]["order"]
# default filter by value
if not filterby:
filterby = "open"
domain += searchbar_filters[filterby]["domain"]

# count for pager
fsm_order_count = FsmOrder.search_count(domain)
# pager
pager = portal_pager(
url="/my/fsm_orders",
url_args={},
total=fsm_order_count,
page=page,
step=self._items_per_page,
)
# content according to pager and archive selected
fsm_orders = FsmOrder.search(
domain,
order=order,
limit=self._items_per_page,
offset=pager["offset"],
)

if groupby == "none":
grouped_orders = [fsm_orders] if fsm_orders else []
else:
grouped_orders = [
FsmOrder.concat(*g)
for k, g in groupbyelem(fsm_orders, itemgetter(groupby))
]

values.update(
{
"date": date_begin,
"grouped_orders": grouped_orders,
"page_name": "fsm_order",
"pager": pager,
"default_url": "/my/fsm_orders",
"searchbar_sortings": searchbar_sortings,
"searchbar_groupby": searchbar_groupby,
"searchbar_inputs": searchbar_inputs,
"search_in": search_in,
"sortby": sortby,
"groupby": groupby,
"searchbar_filters": searchbar_filters,
"filterby": filterby,
}
)
return request.render("fieldservice_portal.portal_my_fsm_orders", values)

@http.route(
["/my/fsm_order/<int:order_id>"],
type="http",
website=True,
)
def portal_my_fsm_order(self, order_id=None, **kw):
try:
order_sudo = self._fsm_order_check_access(order_id)
except AccessError:
return request.redirect("/my")
values = self.fsm_order_get_page_view_values(order_sudo, **kw)
return request.render(
"fieldservice_portal.portal_fieldservice_order_page", values
)
6 changes: 6 additions & 0 deletions fieldservice_portal/demo/fsm_location_demo.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8" ?>
<odoo>
<record id="fieldservice.test_location" model="fsm.location">
<field name="contact_id" ref="base.partner_demo_portal" />
</record>
</odoo>
8 changes: 8 additions & 0 deletions fieldservice_portal/demo/fsm_order_demo.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8" ?>
<odoo>
<record id="fsm_order_demo" model="fsm.order">
<field name="name">Demo Order</field>
<field name="description">Description for the new demo order</field>
<field name="location_id" ref="fieldservice.test_location" />
</record>
</odoo>
6 changes: 6 additions & 0 deletions fieldservice_portal/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
* `PyTech SRL <https://www.pytech.it>`_:

* Alessio Renda <alessio.renda@pytech.it>

- [APSL-Nagarro](https://www.apsl.tech):
- Patryk Pyczko \<<ppyczko@apsl.net>\>
2 changes: 2 additions & 0 deletions fieldservice_portal/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Bridge module between fieldservice and portal that allows portal users
to monitor work orders related to their locations.
5 changes: 5 additions & 0 deletions fieldservice_portal/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_order_portal,fieldservice.order.portal,fieldservice.model_fsm_order,base.group_portal,1,0,0,0
access_fsm_stage_portal,fieldservice.stage.portal,fieldservice.model_fsm_stage,base.group_portal,1,0,0,0
access_fsm_order_type_portal,fieldservice.order.type.portal,fieldservice.model_fsm_order_type,base.group_portal,1,0,0,0
access_fsm_location_portal,fieldservice.location.portal,fieldservice.model_fsm_location,base.group_portal,1,0,0,0
Loading
Loading