[WIP]pms: added reservations in portal

This commit is contained in:
braisab
2021-03-05 20:05:54 +01:00
parent 94341bb877
commit 9ae89adeaf
6 changed files with 305 additions and 1 deletions

View File

@@ -68,6 +68,7 @@
"views/ir_sequence_views.xml",
"views/account_journal_views.xml",
"views/folio_portal_templates.xml",
"views/reservation_portal_templates.xml",
"wizards/wizard_reservation.xml",
"wizards/wizard_massive_changes.xml",
"wizards/wizard_advanced_filters.xml",

View File

@@ -40,7 +40,7 @@ class PortalFolio(CustomerPortal):
partner = request.env.user.partner_id
values = self._prepare_portal_layout_values()
PmsFolio = request.env["pms.folio"]
values["folios"] = PmsFolio.sudo().search(
values["folios"] = PmsFolio.search(
[
("partner_id", "child_of", partner.id),
]
@@ -108,3 +108,113 @@ class PortalFolio(CustomerPortal):
)
values = self._folio_get_page_view_values(folio_sudo, access_token, **kw)
return request.render("pms.folio_portal_template", values)
class PortalReservation(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"]
if "reservation_count" in counters:
values["reservation_count"] = (
Reservation.search_count(
[
("partner_id", "=", partner.id),
]
)
if Reservation.check_access_rights("read", raise_exception=False)
else 0
)
return values
def _reservation_get_page_view_values(self, reservation, access_token, **kwargs):
values = {"reservation": reservation, "token": access_token}
return self._get_page_view_values(
reservation,
access_token,
values,
"my_reservations_history",
False,
**kwargs
)
@http.route(
["/my/reservations", "/my/reservations/page/<int:page>"],
type="http",
auth="user",
website=True,
)
def portal_my_reservations(
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),
]
searchbar_sortings = {
"date": {"label": _("Order Date"), "reservation": "date_order desc"},
"name": {"label": _("Reference"), "reservation": "name"},
"stage": {"label": _("Stage"), "reservation": "state"},
}
if not sortby:
sortby = "date"
sort_order = searchbar_sortings[sortby]["reservation"]
if date_begin and date_end:
domain += [
("create_date", ">", date_begin),
("create_date", "<=", date_end),
]
reservation_count = Reservation.search_count(domain)
pager = portal_pager(
url="/my/reservations",
url_args={"date_begin": date_begin, "date_end": date_end, "sortby": sortby},
total=reservation_count,
page=page,
step=self._items_per_page,
)
reservations = Reservation.search(
domain, order=sort_order, limit=self._items_per_page, offset=pager["offset"]
)
request.session["my_reservations_history"] = reservations.ids[:100]
values.update(
{
"date": date_begin,
"reservations": reservations.sudo(),
"page_name": "reservations",
"pager": pager,
"default_url": "/my/reservations",
"searchbar_sortings": searchbar_sortings,
"sortby": sortby,
}
)
return request.render("pms.portal_my_reservation", values)
@http.route(
["/my/reservations/<int:reservation_id>"],
type="http",
auth="user",
website=True,
)
def portal_my_reservation_detail(self, reservation_id, access_token=None, **kw):
try:
reservation_sudo = self._document_check_access(
"pms.reservation",
reservation_id,
access_token=access_token,
)
except (AccessError, MissingError):
return request.redirect("/my")
# for attachment in reservation_sudo.attachment_ids:
# attachment.generate_access_token()
values = self._reservation_get_page_view_values(
reservation_sudo, access_token, **kw
)
return request.render("pms.portal_my_reservation_detail", values)

View File

@@ -822,6 +822,11 @@ class PmsReservation(models.Model):
else False
)
def _compute_access_url(self):
super(PmsReservation, self)._compute_access_url()
for reservation in self:
reservation.access_url = "/my/reservations/%s" % (reservation.id)
def _search_left_for_checkin(self, operator, value):
if operator not in ("=",):
raise UserError(

View File

@@ -61,3 +61,4 @@ user_access_pms_invoice_filter_days,user_access_pms_invoice_filter_days,model_pm
user_access_pms_invoice_filter_days_items,user_access_pms_invoice_filter_days_items,model_pms_invoice_filter_days_items,pms.group_pms_user,1,1,1,1
user_access_wizard_payment_folio,user_access_wizard_payment_folio,model_wizard_payment_folio,pms.group_pms_user,1,1,1,1
user_access_pms_folio_portal,user_access_pms_folio_portal,model_pms_folio,base.group_portal,1,0,0,0
user_access_pms_reservation_portal,user_access_pms_reservation_portal,model_pms_reservation,base.group_portal,1,0,0,0
1 id name model_id:id group_id:id perm_read perm_write perm_create perm_unlink
61 user_access_pms_invoice_filter_days_items user_access_pms_invoice_filter_days_items model_pms_invoice_filter_days_items pms.group_pms_user 1 1 1 1
62 user_access_wizard_payment_folio user_access_wizard_payment_folio model_wizard_payment_folio pms.group_pms_user 1 1 1 1
63 user_access_pms_folio_portal user_access_pms_folio_portal model_pms_folio base.group_portal 1 0 0 0
64 user_access_pms_reservation_portal user_access_pms_reservation_portal model_pms_reservation base.group_portal 1 0 0 0

View File

@@ -230,5 +230,12 @@
<field name="groups" eval="[(4, ref('base.group_portal'))]" />
<field name="perm_read" eval="True" />
</record>
<record id="pms_reservation_rule_portal" model="ir.rule">
<field name="name">Portal Personal Reservation</field>
<field name="model_id" ref="model_pms_reservation" />
<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,180 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<template
id="portal_my_home_menu_reservation"
name="Portal layout : reservation menu entries"
inherit_id="portal.portal_breadcrumbs"
priority="20"
>
<xpath expr="//ol[hasclass('o_portal_submenu')]" position="inside">
<li
t-if="page_name == 'reservations'"
t-attf-class="breadcrumb-item #{'active ' if not reservations else ''}"
>
<a t-attf-href="/my/reservations?{{ keep_query() }}">Reservations</a>
</li>
<li t-if="reservation" class="breadcrumb-item active">
<a t-attf-href="/my/reservations?{{ keep_query() }}">Reservations/</a>
<t t-esc="reservation.name" />
</li>
</xpath>
</template>
<template
id="portal_my_reservations"
name="Reservations"
inherit_id="portal.portal_my_home"
customize_show="True"
priority="30"
>
<xpath expr="//div[hasclass('o_portal_docs')]" position="inside">
<t t-call="portal.portal_docs_entry">
<t t-set="title">Reservations</t>
<t t-set="url" t-value="'/my/reservations'" />
<t t-set="placeholder_count" t-value="'reservation_count'" />
</t>
</xpath>
</template>
<template id="portal_my_reservation" name="My Reservations">
<t t-call="portal.portal_layout">
<t t-set="breadcrumbs_searchbar" t-value="True" />
<t t-call="portal.portal_searchbar">
<t t-set="title">Reservations</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>Reservation #</th>
<th>Checkin</th>
<th>Checkout</th>
<th class="text-right">Total</th>
</tr>
</thead>
<tbody>
<t t-foreach="reservations" t-as="reservation">
<tr>
<td>
<a
t-att-href="reservation.get_portal_url()"
t-att-title="reservation.name"
>
<t t-esc="reservation.name" />
</a>
</td>
<td><span t-field="reservation.checkin" /></td>
<td><span t-field="reservation.checkout" /></td>
<!-- <td class="text-right"><span-->
<!-- t-field="reservation.price_room_services_set"-->
<!-- /></td>-->
</tr>
</t>
</tbody>
</t>
</t>
</template>
<template id="portal_my_reservation_detail" name="My Reservation">
<t t-call="portal.portal_layout">
<!-- <t t-set="o_portal_fullwidth_alert" groups="project.group_project_user">-->
<!-- <t t-call="portal.portal_back_in_edit_mode">-->
<!-- <t t-set="backend_url" t-value="'/web#model=project.task&amp;id=%s&amp;view_type=form' % (task.id)"/>-->
<!-- </t>-->
<!-- </t>-->
<t t-call="portal.portal_record_layout">
<t t-set="card_header">
<div class="row no-gutters">
<div class="col-12">
<h5 class="d-flex mb-1 mb-md-0 row">
<span t-field="reservation.name" class="col-9 text-truncate"/>
<small class="text-muted d-none d-md-inline"> (#<span t-field="reservation.id"/>)</small>
<div class="col-3 col-md-2 text-right">
<small class="text-right">Status:</small>
<span t-field="reservation.state" class=" badge badge-pill badge-info" title="Current state of this reservation"/>
</div>
</h5>
</div>
</div>
</t>
<t t-set="card_body">
<!-- <div class="mb-1" t-if="user in reservation.sudo().allowed_user_ids">-->
<!-- <strong>Project:</strong> <a t-attf-href="/my/project/#{reservation.project_id.id}" t-field="reservation.name"/>-->
<!-- </div>-->
<div class="row mb-4">
<div class="col-12 col-md-6" t-if="reservation.checkin">
<strong>Checkin:</strong> <span t-field="reservation.checkin" t-options='{"widget": "date"}'/>
</div>
<div class="col-12 col-md-6 mb-1">
<strong>Checkout:</strong> <span t-field="reservation.checkout" t-options='{"widget": "date"}'/>
</div>
</div>
<div class="row mb-4" t-if="reservation.partner_id">
<div class="col-12 col-md-6 pb-2" t-if="reservation.partner_id">
<strong>Assigned to</strong>
<div class="row">
<div class="col flex-grow-0 pr-3">
<img t-if="reservation.partner_id.image_1024" class="rounded-circle mt-1 o_portal_contact_img" t-att-src="image_data_uri(reservation.partner_id.image_1024)" alt="Contact"/>
<img t-else="" class="rounded-circle mt-1 o_portal_contact_img" src="/web/static/src/img/user_menu_avatar.png" alt="Contact"/>
</div>
<div class="col pl-md-0">
<div t-field="reservation.partner_id" t-options='{"widget": "contact", "fields": ["name", "email", "phone"]}'/>
</div>
</div>
</div>
<div class="coll-12 col-md-6 pb-2" t-if="reservation.partner_id">
<strong>Reported by</strong>
<div class="row">
<div class="col flex-grow-0 pr-3">
<img t-if="reservation.partner_id.image_1024" class="rounded-circle mt-1 o_portal_contact_img" t-att-src="image_data_uri(reservation.partner_id.image_1024)" alt="Contact"/>
<img t-else="" class="rounded-circle mt-1 o_portal_contact_img" src="/web/static/src/img/user_menu_avatar.png" alt="Contact"/>
</div>
<div class="col pl-md-0">
<div t-field="reservation.partner_id" t-options='{"widget": "contact", "fields": ["name", "email", "phone"]}'/>
</div>
</div>
</div>
</div>
<!-- <div class="row" t-if="reservation.description">-->
<!-- <div t-if="reservation.description" t-attf-class="col-12 col-lg-7 mb-4 mb-md-0 ">-->
<!-- <hr class="mb-1"/>-->
<!-- <div class="d-flex my-2">-->
<!-- <strong>Description</strong>-->
<!-- </div>-->
<!-- <div class="py-1 px-2 bg-100 small" t-field="reservation.description"/>-->
<!-- </div>-->
<!-- <div t-if="reservation.attachment_ids" t-attf-class="col-12 col-lg-5 o_project_portal_attachments {{'col-lg-5' if reservation.description else 'col-lg-12'}}">-->
<!-- <hr class="mb-1 d-none d-lg-block"/>-->
<!-- <strong class="d-block mb-2">Attachments</strong>-->
<!-- <div class="row">-->
<!-- <div t-attf-class="col {{'col-lg-6' if not reservation.description else 'col-lg-12'}}">-->
<!-- <ul class="list-group">-->
<!-- <a class="list-group-item list-group-item-action d-flex align-items-center oe_attachments py-1 px-2" t-foreach='reservation.attachment_ids' t-as='attachment' t-attf-href="/web/content/#{attachment.id}?download=true&amp;access_token=#{attachment.access_token}" target="_blank" data-no-post-process="">-->
<!-- <div class='oe_attachment_embedded o_image o_image_small mr-2 mr-lg-3' t-att-title="attachment.name" t-att-data-mimetype="attachment.mimetype" t-attf-data-src="/web/image/#{attachment.id}/50x40?access_token=#{attachment.access_token}"/>-->
<!-- <div class='oe_attachment_name text-truncate'><t t-esc='attachment.name'/></div>-->
<!-- </a>-->
<!-- </ul>-->
<!-- </div>-->
<!-- </div>-->
<!-- </div>-->
<!-- </div>-->
</t>
</t>
<div class="mt32">
<h4><strong>Message and communication history</strong></h4>
<t t-call="portal.message_thread">
<t t-set="object" t-value="reservation"/>
<t t-set="token" t-value="reservation.access_token"/>
<t t-set="pid" t-value="pid"/>
<t t-set="hash" t-value="hash"/>
</t>
</div>
</t>
</template>
</odoo>