mirror of
https://github.com/OCA/pms.git
synced 2025-01-29 00:17:45 +02:00
[WIP] add sort by and pager
This commit is contained in:
@@ -1,8 +1,8 @@
|
|||||||
from odoo import http
|
from odoo import _, http
|
||||||
from odoo.exceptions import AccessError, MissingError
|
from odoo.exceptions import AccessError, MissingError
|
||||||
from odoo.http import request
|
from odoo.http import request
|
||||||
|
|
||||||
from odoo.addons.portal.controllers.portal import CustomerPortal
|
from odoo.addons.portal.controllers.portal import CustomerPortal, pager as portal_pager
|
||||||
|
|
||||||
|
|
||||||
class PortalFolio(CustomerPortal):
|
class PortalFolio(CustomerPortal):
|
||||||
@@ -28,25 +28,61 @@ class PortalFolio(CustomerPortal):
|
|||||||
folio, access_token, values, "my_folios_history", False, **kwargs
|
folio, access_token, values, "my_folios_history", False, **kwargs
|
||||||
)
|
)
|
||||||
|
|
||||||
@http.route(["/my/folios"], type="http", auth="user", website=True)
|
@http.route(
|
||||||
|
["/my/folios", "/my/folios/page/<int:page>"],
|
||||||
|
type="http",
|
||||||
|
auth="user",
|
||||||
|
website=True,
|
||||||
|
)
|
||||||
def portal_my_folios(
|
def portal_my_folios(
|
||||||
self, page=1, date_begin=None, date_end=None, sortby=None, filterby=None, **kw
|
self, page=1, date_begin=None, date_end=None, sortby=None, filterby=None, **kw
|
||||||
):
|
):
|
||||||
partner = request.env.user.partner_id
|
partner = request.env.user.partner_id
|
||||||
values = self._prepare_portal_layout_values()
|
values = self._prepare_portal_layout_values()
|
||||||
values["folios"] = (
|
PmsFolio = request.env["pms.folio"]
|
||||||
request.env["pms.folio"]
|
values["folios"] = PmsFolio.sudo().search(
|
||||||
.sudo()
|
[
|
||||||
.search(
|
("partner_id", "child_of", partner.id),
|
||||||
[
|
]
|
||||||
("partner_id", "child_of", partner.id),
|
|
||||||
]
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
|
domain = [
|
||||||
|
("partner_id", "child_of", partner.id),
|
||||||
|
]
|
||||||
|
searchbar_sortings = {
|
||||||
|
"date": {"label": _("Order Date"), "folio": "date_order desc"},
|
||||||
|
"name": {"label": _("Reference"), "folio": "name"},
|
||||||
|
"stage": {"label": _("Stage"), "folio": "state"},
|
||||||
|
}
|
||||||
|
if not sortby:
|
||||||
|
sortby = "date"
|
||||||
|
sort_order = searchbar_sortings[sortby]["folio"]
|
||||||
|
|
||||||
|
if date_begin and date_end:
|
||||||
|
domain += [
|
||||||
|
("create_date", ">", date_begin),
|
||||||
|
("create_date", "<=", date_end),
|
||||||
|
]
|
||||||
|
folio_count = PmsFolio.search_count(domain)
|
||||||
|
pager = portal_pager(
|
||||||
|
url="/my/folios",
|
||||||
|
url_args={"date_begin": date_begin, "date_end": date_end, "sortby": sortby},
|
||||||
|
total=folio_count,
|
||||||
|
page=page,
|
||||||
|
step=self._items_per_page,
|
||||||
|
)
|
||||||
|
folios = PmsFolio.search(
|
||||||
|
domain, order=sort_order, limit=self._items_per_page, offset=pager["offset"]
|
||||||
|
)
|
||||||
|
request.session["my_folios_history"] = folios.ids[:100]
|
||||||
values.update(
|
values.update(
|
||||||
{
|
{
|
||||||
|
"date": date_begin,
|
||||||
|
"folios": folios.sudo(),
|
||||||
"page_name": "folios",
|
"page_name": "folios",
|
||||||
|
"pager": pager,
|
||||||
"default_url": "/my/folios",
|
"default_url": "/my/folios",
|
||||||
|
"searchbar_sortings": searchbar_sortings,
|
||||||
|
"sortby": sortby,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
return request.render("pms.portal_my_folio", values)
|
return request.render("pms.portal_my_folio", values)
|
||||||
|
|||||||
@@ -736,7 +736,7 @@ class PmsFolio(models.Model):
|
|||||||
# Action methods
|
# Action methods
|
||||||
def _get_report_base_filename(self):
|
def _get_report_base_filename(self):
|
||||||
self.ensure_one()
|
self.ensure_one()
|
||||||
return 'Folio %s' % self.name
|
return "Folio %s" % self.name
|
||||||
|
|
||||||
def action_pay(self):
|
def action_pay(self):
|
||||||
self.ensure_one()
|
self.ensure_one()
|
||||||
|
|||||||
@@ -6,12 +6,15 @@
|
|||||||
priority="20"
|
priority="20"
|
||||||
>
|
>
|
||||||
<xpath expr="//ol[hasclass('o_portal_submenu')]" position="inside">
|
<xpath expr="//ol[hasclass('o_portal_submenu')]" position="inside">
|
||||||
<li t-if="page_name == 'folios'" t-attf-class="breadcrumb-item #{'active ' if not folios else ''}">
|
<li
|
||||||
|
t-if="page_name == 'folios'"
|
||||||
|
t-attf-class="breadcrumb-item #{'active ' if not folios else ''}"
|
||||||
|
>
|
||||||
<a t-attf-href="/my/folios?{{ keep_query() }}">Folios</a>
|
<a t-attf-href="/my/folios?{{ keep_query() }}">Folios</a>
|
||||||
</li>
|
</li>
|
||||||
<li t-if="folio" class="breadcrumb-item active">
|
<li t-if="folio" class="breadcrumb-item active">
|
||||||
<a t-attf-href="/my/folios?{{ keep_query() }}">Folios/</a>
|
<a t-attf-href="/my/folios?{{ keep_query() }}">Folios/</a>
|
||||||
<t t-esc="folio.name"/>
|
<t t-esc="folio.name" />
|
||||||
</li>
|
</li>
|
||||||
</xpath>
|
</xpath>
|
||||||
</template>
|
</template>
|
||||||
@@ -121,8 +124,18 @@
|
|||||||
>Salesperson</strong></div>
|
>Salesperson</strong></div>
|
||||||
<div class="row flex-nowrap">
|
<div class="row flex-nowrap">
|
||||||
<div class="col flex-grow-0 pr-2">
|
<div class="col flex-grow-0 pr-2">
|
||||||
<img class="rounded-circle mr4 float-left o_portal_contact_img" t-if="folio.user_id.image_1024" t-att-src="image_data_uri(folio.user_id.image_1024)" alt="Contact"/>
|
<img
|
||||||
<img class="rounded-circle mr4 float-left o_portal_contact_img" t-if="not folio.user_id.image_1024" src="/web/static/src/img/placeholder.png" alt="Contact"/>
|
class="rounded-circle mr4 float-left o_portal_contact_img"
|
||||||
|
t-if="folio.user_id.image_1024"
|
||||||
|
t-att-src="image_data_uri(folio.user_id.image_1024)"
|
||||||
|
alt="Contact"
|
||||||
|
/>
|
||||||
|
<img
|
||||||
|
class="rounded-circle mr4 float-left o_portal_contact_img"
|
||||||
|
t-if="not folio.user_id.image_1024"
|
||||||
|
src="/web/static/src/img/placeholder.png"
|
||||||
|
alt="Contact"
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div class="col pl-0" style="min-width: 150px">
|
<div class="col pl-0" style="min-width: 150px">
|
||||||
<span
|
<span
|
||||||
|
|||||||
Reference in New Issue
Block a user