Skip to content

Commit

Permalink
[MIG] fieldservice_portal: Migation to 16.0
Browse files Browse the repository at this point in the history
  • Loading branch information
anusriNPS committed Oct 25, 2024
1 parent 09eef27 commit df8b7ad
Show file tree
Hide file tree
Showing 9 changed files with 229 additions and 37 deletions.
6 changes: 3 additions & 3 deletions fieldservice_portal/README.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
============================
Field Service - Order Portal
============================
======================
Field Service - Portal
======================

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Expand Down
7 changes: 6 additions & 1 deletion fieldservice_portal/__manifest__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "Field Service - Order Portal",
"name": "Field Service - Portal",
"version": "16.0.1.0.0",
"summary": """
Bridge module between fieldservice and portal.
Expand All @@ -23,6 +23,11 @@
"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,
}
27 changes: 14 additions & 13 deletions fieldservice_portal/controllers/fsm_order_portal.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,17 @@


class CustomerPortal(CustomerPortal):
def _prepare_portal_layout_values(self):
values = super()._prepare_portal_layout_values()
fsm_order_count = (
request.env["fsm.order"].search_count([])
if request.env["fsm.order"].check_access_rights(
"read", raise_exception=False
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
)
else 0
)
values["fsm_order_count"] = fsm_order_count
values["fsm_order_count"] = fsm_order_count
return values

def _fsm_order_check_access(self, order_id):
Expand Down Expand Up @@ -49,7 +50,7 @@ def fsm_order_get_page_view_values(self, order, **kwargs):
return values

@http.route(
["/my/workorders", "/my/workorders/page/<int:page>"],
["/my/fsm_orders", "/my/fsm_orders/page/<int:page>"],
type="http",
auth="user",
website=True,
Expand Down Expand Up @@ -154,7 +155,7 @@ def portal_my_fsm_orders(
fsm_order_count = FsmOrder.search_count(domain)
# pager
pager = portal_pager(
url="/my/workorders",
url="/my/fsm_orders",
url_args={},
total=fsm_order_count,
page=page,
Expand Down Expand Up @@ -182,7 +183,7 @@ def portal_my_fsm_orders(
"grouped_orders": grouped_orders,
"page_name": "fsm_order",
"pager": pager,
"default_url": "/my/workorders",
"default_url": "/my/fsm_orders",
"searchbar_sortings": searchbar_sortings,
"searchbar_groupby": searchbar_groupby,
"searchbar_inputs": searchbar_inputs,
Expand All @@ -196,7 +197,7 @@ def portal_my_fsm_orders(
return request.render("fieldservice_portal.portal_my_fsm_orders", values)

@http.route(
["/my/workorder/<int:order_id>"],
["/my/fsm_order/<int:order_id>"],
type="http",
website=True,
)
Expand Down
6 changes: 3 additions & 3 deletions fieldservice_portal/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="generator" content="Docutils: https://docutils.sourceforge.io/" />
<title>Field Service - Order Portal</title>
<title>Field Service - Portal</title>
<style type="text/css">

/*
Expand Down Expand Up @@ -360,8 +360,8 @@
</style>
</head>
<body>
<div class="document" id="field-service-order-portal">
<h1 class="title">Field Service - Order Portal</h1>
<div class="document" id="field-service-portal">
<h1 class="title">Field Service - Portal</h1>

<!-- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
Expand Down
13 changes: 13 additions & 0 deletions fieldservice_portal/static/src/js/fsm_order_portal.esm.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/** @odoo-module */

import "portal.portal"; // Force dependencies
import publicWidget from "web.public.widget";

publicWidget.registry.PortalHomeCounters.include({
/**
* @override
*/
_getCountersAlwaysDisplayed() {
return this._super(...arguments).concat(["fsm_order_count"]);
},
});
1 change: 1 addition & 0 deletions fieldservice_portal/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import test_portal
171 changes: 171 additions & 0 deletions fieldservice_portal/tests/test_portal.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
import json

from odoo.exceptions import AccessError
from odoo.http import Request
from odoo.tests.common import HttpCase, TransactionCase, tagged


@tagged("post_install", "-at_install")
class TestUsersHttp(HttpCase, TransactionCase):
def test_fsm_order_portal(self):
# Accessing work order of the portal user through route APIs available
login = "portal"
self.authenticate(login, login)
response = self.url_open(
"/my/fsm_orders",
data={
"validation": login,
"password": login,
"csrf_token": Request.csrf_token(self),
},
)

# Check successful response from API
self.assertEqual(response.status_code, 200)

login = "demo"
self.authenticate(login, login)
response = self.url_open(
"/my/fsm_orders",
data={
"validation": login,
"password": login,
"csrf_token": Request.csrf_token(self),
},
)

# Check Forbidden response from API
self.assertEqual(response.status_code, 403)

def test_fsm_order_access(self):
order_id = self.env["fsm.order"].search([])[0].id
login = "portal"
self.authenticate(login, login)
response = self.url_open(
"/my/fsm_order/" + str(order_id),
data={
"validation": login,
"password": login,
"csrf_token": Request.csrf_token(self),
},
)
self.assertEqual(response.status_code, 200)

def test_fsm_order_access_denied(self):
# create a Res Partner to be converted to FSM Location/Person
test_loc_partner = self.env["res.partner"].create(
{"name": "Test Loc Partner", "phone": "ABC", "email": "tlp@email.com"}
)
# create FSM Location and assign it to different user other than Portal User
test_location = self.env["fsm.location"].create(
{
"name": "Test Location No Portal User",
"phone": "123",
"email": "tp@email.com",
"customer_id": test_loc_partner.id,
"partner_id": test_loc_partner.id,
"owner_id": test_loc_partner.id,
}
)
order = self.env["fsm.order"].create(
{
"location_id": test_location.id,
}
)

# Trying to access fsm_order which is not
# assigned to Portal User to check access error
login = "portal"
self.authenticate(login, login)
self.url_open(
"/my/fsm_order/" + str(order.id),
data={
"validation": login,
"password": login,
"csrf_token": Request.csrf_token(self),
},
)
self.assertRaises(
AccessError, msg="Access Denied by record rules for operation: read"
)

def test_fsm_order_kw_usage(self):
order_id = self.env["fsm.order"].search([])[0].id
# Trying to access fsm_order url
# with query parameters
login = "portal"
self.authenticate(login, login)
response = self.url_open(
"/my/fsm_order/" + str(order_id) + "?success='success'",
data={
"validation": login,
"password": login,
"csrf_token": Request.csrf_token(self),
},
)
self.assertEqual(response.status_code, 200)

def test_fsm_no_fsm_order_present(self):
# Trying to filter fsm_orders based on filter
login = "portal"
self.authenticate(login, login)
response = self.url_open(
"/my/fsm_orders?groupby=none&filterby=Completed&page=1&search_in=&search=",
data={
"validation": login,
"password": login,
"csrf_token": Request.csrf_token(self),
},
)
self.assertEqual(response.status_code, 200)
self.assertNotIn("<tbody>", response.text)
self.assertIn("<p>There are no Work Orders in your account.</p>", response.text)

def test_fsm_order_filter_usage(self):
# Trying to filter fsm_orders based on filter, group and sort
login = "portal"
self.authenticate(login, login)
response = self.url_open(
"/my/fsm_orders?groupby=stage_id&filterby=New&sortby=location",
data={
"validation": login,
"password": login,
"csrf_token": Request.csrf_token(self),
},
)
self.assertEqual(response.status_code, 200)
self.assertIn("<tbody>", response.text)
self.assertIn("Demo Order", response.text)

def test_fsm_orders_portal_home(self):
login = "portal"
self.authenticate(login, login)
response = self.url_open(
"/my/home",
data={
"validation": login,
"password": login,
"csrf_token": Request.csrf_token(self),
},
)
self.assertEqual(response.status_code, 200)
self.assertIn("FSM Orders", response.text)

def test_fsm_orders_count(self):
login = "portal"
self.authenticate(login, login)
response = self.url_open(
"/my/counters",
data=json.dumps(
{
"validation": login,
"password": login,
"csrf_token": Request.csrf_token(self),
"params": {
"counters": "fsm_order_count",
},
}
).encode(),
headers={"Content-Type": "application/json"},
).json()
self.assertEqual(response["result"]["fsm_order_count"], 1)
18 changes: 9 additions & 9 deletions fieldservice_portal/views/fsm_order_template.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<em class="font-weight-normal text-muted">
Work Orders for
<t
t-esc="searchbar_groupby[groupby]['label']"
t-out="searchbar_groupby[groupby]['label']"
/>:
</em>
<span
Expand All @@ -45,23 +45,23 @@
<t t-foreach="orders" t-as="order">
<tr>
<td>
<a t-attf-href="/my/workorder/#{order.id}">
<t t-esc="order.name" />
<a t-attf-href="/my/fsm_order/#{order.id}">
<t t-out="order.name" />
</a>
</td>
<td>
<t t-esc="order.description" />
<t t-out="order.description" />
</td>
<td>
<t
t-esc="order.sudo().location_id.display_name"
t-out="order.sudo().location_id.display_name"
/>
</td>
<td>
<t t-esc="order.type.name" />
<t t-out="order.type.name" />
</td>
<td>
<t t-esc="order.stage_id.name" />
<t t-out="order.stage_id.name" />
</td>
</tr>
</t>
Expand Down Expand Up @@ -106,7 +106,7 @@
</div>
<div class="col-md-6">
<strong>Stage:</strong>
<t t-esc="order.stage_id.name" />
<t t-out="order.stage_id.name" />
<br />
<strong>Work Type:</strong>
<t t-if="order.type">
Expand All @@ -129,7 +129,7 @@
<div class="row mt8">
<div class="col-md-12">
<h4 class="page-header">Description</h4>
<t t-raw="order.description" />
<t t-out="order.description" />
<br />
</div>
</div>
Expand Down
17 changes: 9 additions & 8 deletions fieldservice_portal/views/portal_template.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,28 @@
>
<a
t-if="fsm_order"
t-attf-href="/my/workorders?{{ keep_query() }}"
t-attf-href="/my/fsm_orders?{{ keep_query() }}"
>Work Orders</a>
<t t-else="">Work Orders</t>
</li>
<li t-if="fsm_order" class="breadcrumb-item active">
<t t-esc="fsm_order.name" />
<t t-out="fsm_order.name" />
</li>
</xpath>
</template>

<template
id="portal_my_home"
id="portal_my_home_fsm_order"
name="Portal My Home : fsm order entries"
inherit_id="portal.portal_my_home"
priority="45"
customize_show="True"
priority="50"
>
<xpath expr="//div[hasclass('o_portal_docs')]" position="inside">
<t t-if="fsm_order_count" t-call="portal.portal_docs_entry">
<t t-set="title">Work Orders</t>
<t t-set="url" t-value="'/my/workorders'" />
<t t-set="count" t-value="fsm_order_count" />
<t t-call="portal.portal_docs_entry">
<t t-set="title">FSM Orders</t>
<t t-set="url" t-value="'/my/fsm_orders'" />
<t t-set="placeholder_count" t-value="'fsm_order_count'" />
</t>
</xpath>
</template>
Expand Down

0 comments on commit df8b7ad

Please sign in to comment.