Skip to content

[ADD] filter_appointment: add advanced filters to appointment listing page #748

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: 18.0
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions filter_appointment/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import controllers
13 changes: 13 additions & 0 deletions filter_appointment/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
'name': 'Website Appointment Filters',
'version': '1.0',
'summary': 'Add filters to appointment page on website',
'author': 'kame',
'depends': ['website', 'appointment'],
'data': [
'views/appointment_template.xml',
],
'installable': True,
'application': False,
'license': 'LGPL-3',
}
1 change: 1 addition & 0 deletions filter_appointment/controllers/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import appointment
49 changes: 49 additions & 0 deletions filter_appointment/controllers/appointment.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
from odoo import http
from odoo.addons.website_appointment.controllers.appointment import WebsiteAppointment
from odoo.http import request


class WebsiteAppointmentFilter(WebsiteAppointment):

@http.route()
def appointment_type_index(self, page=1, **kwargs):
filter_domain = []

if kwargs.get("appointment_type"):
if kwargs["appointment_type"] == "online":
filter_domain.append(("location_id", "=", False))
elif kwargs["appointment_type"] == "offline":
filter_domain.append(("location_id", "!=", False))

if kwargs.get("payment_step"):
if kwargs["payment_step"] == "required":
filter_domain.append(("has_payment_step", "=", True))
elif kwargs["payment_step"] == "not_required":
filter_domain.append(("has_payment_step", "=", False))

if kwargs.get("schedule_based_on"):
if kwargs["schedule_based_on"] == "users":
filter_domain.append(("schedule_based_on", "=", "users"))
elif kwargs["schedule_based_on"] == "resources":
filter_domain.append(("schedule_based_on", "=", "resources"))

domain = self._appointments_base_domain(
filter_appointment_type_ids=kwargs.get('filter_appointment_type_ids'),
search=kwargs.get('search'),
additional_domain=filter_domain
)

available_appointment_types = self._fetch_and_check_private_appointment_types(
kwargs.get('filter_appointment_type_ids'),
kwargs.get('filter_staff_user_ids'),
kwargs.get('filter_resource_ids'),
kwargs.get('invite_token'),
domain=domain
)

return request.render(
'website_appointment.appointments_cards_layout',
self._prepare_appointments_cards_data(
page, available_appointment_types, **kwargs
)
)
26 changes: 26 additions & 0 deletions filter_appointment/views/appointment_template.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<odoo>
<template id="appointment_website_filter_template" inherit_id="website_appointment.website_calendar_index_topbar">
<xpath expr="//h4" position="after">
<form method="get" action="/appointment" class="d-flex align-items-center gap-2 px-2" role="search">

<select name="appointment_type" class="form-select" style="width: 160px;" onchange="this.form.submit()">
<option value="" t-att-selected="'selected' if not request.params.get('appointment_type') else None">All Types</option>
<option value="online" t-att-selected="'selected' if request.params.get('appointment_type') == 'online' else None">Online</option>
<option value="offline" t-att-selected="'selected' if request.params.get('appointment_type') == 'offline' else None">Offline</option>
</select>

<select name="payment_step" class="form-select" style="width: 160px;" onchange="this.form.submit()">
<option value="" t-att-selected="'selected' if not request.params.get('payment_step') else None">All Payments</option>
<option value="required" t-att-selected="'selected' if request.params.get('payment_step') == 'required' else None">Required</option>
<option value="not_required" t-att-selected="'selected' if request.params.get('payment_step') == 'not_required' else None">Not Required</option>
</select>

<select name="schedule_based_on" class="form-select" style="width: 160px;" onchange="this.form.submit()">
<option value="" t-att-selected="'selected' if not request.params.get('schedule_based_on') else None">All</option>
<option value="users" t-att-selected="'selected' if request.params.get('schedule_based_on') == 'users' else None">Users</option>
<option value="resources" t-att-selected="'selected' if request.params.get('schedule_based_on') == 'resources' else None">Resources</option>
</select>
</form>
</xpath>
</template>
</odoo>