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 24, 2024
1 parent 09eef27 commit 4926016
Show file tree
Hide file tree
Showing 7 changed files with 153 additions and 16 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
2 changes: 1 addition & 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 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
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
136 changes: 136 additions & 0 deletions fieldservice_portal/tests/test_portal.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
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)
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
2 changes: 1 addition & 1 deletion fieldservice_portal/views/portal_template.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<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>
Expand Down

0 comments on commit 4926016

Please sign in to comment.