[IMP]pms: Added precheckin option in portal

This commit is contained in:
braisab
2021-04-23 19:15:23 +02:00
parent d5a4868f27
commit c0e690d24a
6 changed files with 190 additions and 0 deletions

View File

@@ -83,6 +83,7 @@
"views/traveller_report_template.xml",
"wizards/wizard_split_join_swap_reservation.xml",
"views/pms_automated_mails_views.xml",
"views/precheckin_portal_templates.xml",
"wizards/wizard_massive_changes.xml",
"wizards/wizard_advanced_filters.xml",
],

View File

@@ -214,3 +214,71 @@ class PortalReservation(CustomerPortal):
reservation_sudo, access_token, **kw
)
return request.render("pms.portal_my_reservation_detail", values)
class PortalPrecheckin(CustomerPortal):
def _prepare_home_portal_values(self, counters):
partner = request.env.user.partner_id
values = super()._prepare_home_portal_values(counters)
Reservation = request.env["pms.reservation"].search([("partner_id", "=", partner.id)])
if "checkin_count" in counters:
checkin_partner_count = len(Reservation.checkin_partner_ids)
values["checkin_count"] = checkin_partner_count if Reservation.check_access_rights("read", raise_exception=False) else 0
return values
def _precheckin_get_page_view_values(self, precheckin, access_token, **kwargs):
values = {"precheckin": precheckin, "token": access_token}
return self._get_page_view_values(
precheckin,
access_token,
values,
"my_precheckins_history",
False,
**kwargs
)
@http.route(
["/my/precheckins", "/my/precheckins/page/<int:page>"],
type="http",
auth="user",
website=True,
)
def portal_my_precheckin(
self, page=1, date_begin=None, date_end=None, sortby=None, filterby=None, **kw
):
partner = request.env.user.partner_id
values = self._prepare_portal_layout_values()
Reservation = request.env["pms.reservation"]
values["reservations"] = Reservation.search(
[
("partner_id", "child_of", partner.id),
]
)
domain = [
("partner_id", "child_of", partner.id),
]
if date_begin and date_end:
domain += [
("create_date", ">", date_begin),
("create_date", "<=", date_end),
]
reservations = Reservation.search(domain)
checkin_count = len(reservations.checkin_partner_ids)
pager = portal_pager(
url="/my/precheckins",
url_args={"date_begin": date_begin, "date_end": date_end},
total=checkin_count,
page=page,
step=self._items_per_page,
)
request.session["my_precheckins_history"] = reservations.ids[:100]
values.update(
{
"date": date_begin,
"page_name": "precheckins",
"pager": pager,
"default_url": "/my/precheckins",
}
)
return request.render("pms.portal_my_precheckin", values)

View File

@@ -459,6 +459,27 @@ class PmsCheckinPartner(models.Model):
else:
record.partner_incongruences = False
def _compute_access_url(self):
super(PmsCheckinPartner, self)._compute_access_url()
for checkin in self:
checkin.access_url = "/my/precheckin/%s" % (checkin.id)
@api.model
def _checkin_mandatory_fields(self, depends=False):
# api.depends need "reservation_id.state" in the lambda function
if depends:
return ["reservation_id.state", "name"]
return ["name"]
@api.model
def _checkin_partner_fields(self):
# api.depends need "reservation_id.state" in the lambda function
checkin_fields = self._checkin_mandatory_fields()
checkin_fields.extend(["mobile", "email"])
return checkin_fields
# Constraints and onchanges
@api.constrains("departure", "arrival")
def _check_departure(self):
for record in self:

View File

@@ -62,3 +62,4 @@ user_access_pms_folio_portal,user_access_pms_folio_portal,model_pms_folio,base.g
user_access_pms_reservation_portal,user_access_pms_reservation_portal,model_pms_reservation,base.group_portal,1,0,0,0
user_access_pms_automated_mails,user_access_pms_automated_mails,model_pms_automated_mails,pms.group_pms_user,1,1,1,1
access_pms_several_partners_wizard,access_pms_several_partners_wizard,model_pms_several_partners_wizard,base.group_user,1,1,1,1
user_access_pms_precheckin_portal,user_access_pms_precheckin_portal,model_pms_checkin_partner,base.group_portal,1,0,0,0
1 id name model_id:id group_id:id perm_read perm_write perm_create perm_unlink
62 user_access_pms_reservation_portal user_access_pms_reservation_portal model_pms_reservation base.group_portal 1 0 0 0
63 user_access_pms_automated_mails user_access_pms_automated_mails model_pms_automated_mails pms.group_pms_user 1 1 1 1
64 access_pms_several_partners_wizard access_pms_several_partners_wizard model_pms_several_partners_wizard base.group_user 1 1 1 1
65 user_access_pms_precheckin_portal user_access_pms_precheckin_portal model_pms_checkin_partner base.group_portal 1 0 0 0

View File

@@ -237,5 +237,12 @@
<field name="groups" eval="[(4, ref('base.group_portal'))]" />
<field name="perm_read" eval="True" />
</record>
<record id="pms_precheckin_rule_portal" model="ir.rule">
<field name="name">Portal Personal Pre-checkin</field>
<field name="model_id" ref="model_pms_checkin_partner" />
<field name="domain_force">[]</field>
<field name="groups" eval="[(4, ref('base.group_portal'))]" />
<field name="perm_read" eval="True" />
</record>
</data>
</odoo>

View File

@@ -0,0 +1,92 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<template
id="portal_my_home_menu_precheckin"
name="Portal layout : precheckin menu entries"
inherit_id="portal.portal_breadcrumbs"
priority="30"
>
<xpath expr="//ol[hasclass('o_portal_submenu')]" position="inside">
<li
t-if="page_name == 'precheckin'"
t-attf-class="breadcrumb-item #{'active ' if not reservations else ''}"
>
<a t-attf-href="/my/precheckin?{{ keep_query() }}">Precheckin</a>
</li>
<li t-if="reservation" class="breadcrumb-item active">
<a t-attf-href="/my/precheckin?{{ keep_query() }}">Precheckin/</a>
<t t-esc="reservation.name" />
</li>
</xpath>
</template>
<template
id="portal_my_precheckins"
name="Precheckins"
inherit_id="portal.portal_my_home"
customize_show="True"
priority="40"
>
<xpath expr="//div[hasclass('o_portal_docs')]" position="inside">
<t t-call="portal.portal_docs_entry">
<t t-set="title">Precheckin</t>
<t t-set="url" t-value="'/my/precheckins'" />
<t t-set="placeholder_count" t-value="'checkin_count'" />
</t>
</xpath>
</template>
<template id="portal_my_precheckin" name="My PreCheckins">
<t t-call="portal.portal_layout">
<t t-set="breadcrumbs_searchbar" t-value="True" />
<t t-call="portal.portal_searchbar">
<t t-set="title">Precheckins</t>
</t>
<t t-if="not reservations">
<p>There are currently no reservations for your account.</p>
</t>
<t t-if="reservations" t-call="portal.portal_table">
<thead>
<tr class="active">
<th>PreCheckin #</th>
</tr>
</thead>
<tbody>
<t t-foreach="reservations" t-as="reservation">
<t t-set="folio" t-value="reservation.folio_id" />
<!-- Sacar folio-->
<t t-if="reservation == folio.reservation_ids[0]">
<tr class="bg-light">
<td colspan="4"><em
class="font-weight-normal text-muted"
><span />Folio: </em>
<a>
<t t-esc="folio.name" />
</a>
</td>
</tr>
</t>
<tr class="bg-light">
<td colspan="4"><em
class="font-weight-normal text-muted"
><span />Reservation: </em>
<a
t-att-href="reservation.get_portal_url()"
t-att-title="reservation.name"
>
<t t-esc="reservation.name" />
</a>
</td>
</tr>
<t t-foreach="reservation.checkin_partner_ids" t-as="checkin_partner">
<tr>
<td>
<a>Checkin</a>
</td>
</tr>
</t>
</t>
</tbody>
</t>
</t>
</template>
</odoo>