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 53b631b
Show file tree
Hide file tree
Showing 9 changed files with 201 additions and 30 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,
}
19 changes: 10 additions & 9 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)

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

View check run for this annotation

Codecov / codecov/patch

fieldservice_portal/controllers/fsm_order_portal.py#L15

Added line #L15 was not covered by tests
if "fsm_order_count" in counters:
fsm_order_count = (

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

View check run for this annotation

Codecov / codecov/patch

fieldservice_portal/controllers/fsm_order_portal.py#L17

Added line #L17 was not covered by tests
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

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

View check run for this annotation

Codecov / codecov/patch

fieldservice_portal/controllers/fsm_order_portal.py#L24-L25

Added lines #L24 - L25 were not covered by tests

def _fsm_order_check_access(self, order_id):
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.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
150 changes: 150 additions & 0 deletions fieldservice_portal/tests/test_portal.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
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/workorders",
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/workorders",
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/workorder/" + 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 workorder which is not
# assigned to Portal User to check access error
login = "portal"
self.authenticate(login, login)
self.url_open(
"/my/workorder/" + 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 workorder url
# with query parameters
login = "portal"
self.authenticate(login, login)
response = self.url_open(
"/my/workorder/" + 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_workorder_present(self):
# Trying to filter workorders based on filter
login = "portal"
self.authenticate(login, login)
response = self.url_open(
"/my/workorders?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 workorders based on filter, group and sort
login = "portal"
self.authenticate(login, login)
response = self.url_open(
"/my/workorders?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)
16 changes: 8 additions & 8 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 @@ -46,22 +46,22 @@
<tr>
<td>
<a t-attf-href="/my/workorder/#{order.id}">
<t t-esc="order.name" />
<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
13 changes: 7 additions & 6 deletions fieldservice_portal/views/portal_template.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,23 @@
<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-call="portal.portal_docs_entry">
<t t-set="title">FSM Orders</t>
<t t-set="url" t-value="'/my/workorders'" />
<t t-set="count" t-value="fsm_order_count" />
<t t-set="placeholder_count" t-value="'fsm_order_count'" />
</t>
</xpath>
</template>
Expand Down

0 comments on commit 53b631b

Please sign in to comment.