Skip to content

Commit 69e1a02

Browse files
committed
[ADD] website_appointment_filter: add module to filter the appointments
- add a module to filter the appointments on website - filters: - mode [all/online/offline] - type [all/paid/free] - schedule [all/resources/users] task-4505947
1 parent 97549be commit 69e1a02

File tree

5 files changed

+164
-0
lines changed

5 files changed

+164
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from . import controllers
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
'name': 'Website Appointment Filters',
3+
'version': '1.0',
4+
'depends': ['base', 'website_appointment', 'appointment_account_payment'],
5+
'author': 'Kishan B. Gajera',
6+
'category': 'Appointment',
7+
'description': """
8+
A sample module to add filters in Appointment Website View
9+
""",
10+
11+
'application': True,
12+
'installable': True,
13+
14+
'data': [
15+
'views/appointment_templates_appointment_filters.xml'
16+
],
17+
18+
'license':'LGPL-3',
19+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from . import main
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
from odoo import http
2+
from odoo.http import request
3+
from odoo.addons.website_appointment.controllers.appointment import WebsiteAppointment
4+
5+
class WebsiteAppointmentFiltersController(WebsiteAppointment):
6+
@http.route(['/appointment'], type='http', auth='public', website=True)
7+
def appointment_type_index(self, page=1, **filters):
8+
filtered_appointments_by_mode = set()
9+
filtered_appointments_by_type = set()
10+
filtered_appointments_by_schedule = set()
11+
12+
if 'mode' in filters:
13+
if filters['mode'] == 'online':
14+
for appointment in request.env['appointment.type'].search([('location_id', '=', None)]):
15+
filtered_appointments_by_mode.add(appointment.id)
16+
elif filters['mode'] == 'offline':
17+
for appointment in request.env['appointment.type'].search([('location_id', '!=', None)]):
18+
filtered_appointments_by_mode.add(appointment.id)
19+
elif filters['mode'] == 'all':
20+
for appointment in request.env['appointment.type'].search([]):
21+
filtered_appointments_by_mode.add(appointment.id)
22+
else:
23+
for appointment in request.env['appointment.type'].search([]):
24+
filtered_appointments_by_mode.add(appointment.id)
25+
26+
if 'type' in filters:
27+
if filters['type'] == 'paid':
28+
for appointment in request.env['appointment.type'].search([('has_payment_step', '=', 'true')]):
29+
filtered_appointments_by_type.add(appointment.id)
30+
elif filters['type'] == 'free':
31+
for appointment in request.env['appointment.type'].search([('has_payment_step', '!=', 'null')]):
32+
filtered_appointments_by_type.add(appointment.id)
33+
elif filters['type'] == 'all':
34+
for appointment in request.env['appointment.type'].search([]):
35+
filtered_appointments_by_type.add(appointment.id)
36+
else:
37+
for appointment in request.env['appointment.type'].search([]):
38+
filtered_appointments_by_type.add(appointment.id)
39+
40+
if 'schedule' in filters:
41+
if filters['schedule'] == 'resources':
42+
for appointment in request.env['appointment.type'].search([('schedule_based_on', '=', 'resources')]):
43+
filtered_appointments_by_schedule.add(appointment.id)
44+
elif filters['schedule'] == 'users':
45+
for appointment in request.env['appointment.type'].search([('schedule_based_on', '=', 'users')]):
46+
filtered_appointments_by_schedule.add(appointment.id)
47+
elif filters['schedule'] == 'all':
48+
for appointment in request.env['appointment.type'].search([]):
49+
filtered_appointments_by_schedule.add(appointment.id)
50+
else:
51+
for appointment in request.env['appointment.type'].search([]):
52+
filtered_appointments_by_schedule.add(appointment.id)
53+
54+
filtered_appointments_by_mode = set(map(lambda id: str(id), filtered_appointments_by_mode))
55+
filtered_appointments_by_type = set(map(lambda id: str(id), filtered_appointments_by_type))
56+
filtered_appointments_by_schedule = set(map(lambda id: str(id), filtered_appointments_by_schedule))
57+
58+
filters['filter_appointment_type_ids'] = f"[{','.join(filtered_appointments_by_mode & filtered_appointments_by_type & filtered_appointments_by_schedule)}]"
59+
60+
if 'mode' not in filters.keys():
61+
filters['mode'] = 'all'
62+
if 'type' not in filters.keys():
63+
filters['type'] = 'all'
64+
if 'schedule' not in filters.keys():
65+
filters['schedule'] = 'all'
66+
67+
68+
return super().appointment_type_index(**filters)
69+
70+
def _prepare_appointments_cards_data(self, page, appointment_types, **kwargs):
71+
res = super()._prepare_appointments_cards_data(page, appointment_types, **kwargs)
72+
res.update(kwargs)
73+
return res
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<odoo>
3+
4+
<template id="website_calendar_index_topbar_mode_filter" name="Filter by Mode" inherit_id="website_appointment.website_calendar_index_topbar">
5+
<xpath expr="//t[@t-call='website.website_search_box_input']" position="before">
6+
<t t-set="selected_mode" t-value="mode" />
7+
<div class="dropdown d-none d-lg-block">
8+
<a href="#" role="button" class="btn dropdown-toggle btn-light" data-bs-toggle="dropdown" title="Filter by Mode">
9+
Mode <span t-if="selected_mode != 'all'" t-out="1" class="badge bg-primary ms-1"/>
10+
</a>
11+
<div class="dropdown-menu">
12+
<span t-att-data-post="'/appointment?%s' % keep_query('*', mode='all')" t-attf-class="post_link cursor-pointer dropdown-item d-flex align-items-center justify-content-between #{'active' if selected_mode == 'all' else ''}">
13+
All
14+
</span>
15+
<span t-att-data-post="'/appointment?%s' % keep_query('*', mode='online')" t-attf-class="post_link cursor-pointer dropdown-item d-flex align-items-center justify-content-between #{'active' if selected_mode == 'online' else ''}">
16+
Online
17+
</span>
18+
<span t-att-data-post="'/appointment?%s' % keep_query('*', mode='offline')" t-attf-class="post_link cursor-pointer dropdown-item d-flex align-items-center justify-content-between #{'active' if selected_mode == 'offline' else ''}">
19+
Offline
20+
</span>
21+
</div>
22+
</div>
23+
</xpath>
24+
</template>
25+
26+
<template id="website_calendar_index_topbar_type_filter" name="Filter by Type" inherit_id="website_appointment.website_calendar_index_topbar">
27+
<xpath expr="//t[@t-call='website.website_search_box_input']" position="before">
28+
<t t-set="selected_type" t-value="type" />
29+
<div class="dropdown d-none d-lg-block">
30+
<a href="#" role="button" class="btn dropdown-toggle btn-light" data-bs-toggle="dropdown" title="Filter by Type">
31+
Type <span t-if="selected_type != 'all'" t-out="1" class="badge bg-primary ms-1"/>
32+
</a>
33+
<div class="dropdown-menu">
34+
<span t-att-data-post="'/appointment?%s' % keep_query('*', type='all')" t-attf-class="post_link cursor-pointer dropdown-item d-flex align-items-center justify-content-between #{'active' if selected_type == 'all' else ''}">
35+
All
36+
</span>
37+
<span t-att-data-post="'/appointment?%s' % keep_query('*', type='paid')" t-attf-class="post_link cursor-pointer dropdown-item d-flex align-items-center justify-content-between #{'active' if selected_type == 'paid' else ''}">
38+
Paid
39+
</span>
40+
<span t-att-data-post="'/appointment?%s' % keep_query('*', type='free')" t-attf-class="post_link cursor-pointer dropdown-item d-flex align-items-center justify-content-between #{'active' if selected_type == 'free' else ''}">
41+
Free
42+
</span>
43+
</div>
44+
</div>
45+
</xpath>
46+
</template>
47+
48+
<template id="website_calendar_index_topbar_schedule_filter" name="Filter by Date" inherit_id="website_appointment.website_calendar_index_topbar">
49+
<xpath expr="//t[@t-call='website.website_search_box_input']" position="before">
50+
<t t-set="selected_schedule" t-value="schedule" />
51+
<div class="dropdown d-none d-lg-block">
52+
<a href="#" role="button" class="btn dropdown-toggle btn-light" data-bs-toggle="dropdown" title="Filter by Date">
53+
Schedule <span t-if="selected_schedule != 'all'" t-out="1" class="badge bg-primary ms-1"/>
54+
</a>
55+
<div class="dropdown-menu">
56+
<span t-att-data-post="'/appointment?%s' % keep_query('*', schedule='all')" t-attf-class="post_link cursor-pointer dropdown-item d-flex align-items-center justify-content-between #{'active' if selected_schedule == 'all' else ''}">
57+
All
58+
</span>
59+
<span t-att-data-post="'/appointment?%s' % keep_query('*', schedule='resources')" t-attf-class="post_link cursor-pointer dropdown-item d-flex align-items-center justify-content-between #{'active' if selected_schedule == 'resources' else ''}">
60+
Resources
61+
</span>
62+
<span t-att-data-post="'/appointment?%s' % keep_query('*', schedule='users')" t-attf-class="post_link cursor-pointer dropdown-item d-flex align-items-center justify-content-between #{'active' if selected_schedule == 'users' else ''}">
63+
Users
64+
</span>
65+
</div>
66+
</div>
67+
</xpath>
68+
</template>
69+
70+
</odoo>

0 commit comments

Comments
 (0)