From 50ce6ab36806ba574b2aaddad4910c87b3352092 Mon Sep 17 00:00:00 2001 From: "admin.suherdy" Date: Sat, 6 Dec 2025 19:13:44 +0700 Subject: [PATCH] feat: Extend appointment capacity limit to use total resource capacity. --- README.md | 68 +++++++++--------- __init__.py | 2 +- __manifest__.py | 49 ++++++------- __pycache__/__init__.cpython-310.pyc | Bin 0 -> 231 bytes __pycache__/__init__.cpython-312.pyc | Bin 0 -> 209 bytes controllers/__init__.py | 2 +- .../__pycache__/__init__.cpython-310.pyc | Bin 0 -> 236 bytes .../__pycache__/__init__.cpython-312.pyc | Bin 0 -> 214 bytes controllers/__pycache__/main.cpython-310.pyc | Bin 0 -> 1120 bytes controllers/__pycache__/main.cpython-312.pyc | Bin 0 -> 1281 bytes controllers/main.py | 44 ++++++------ static/src/js/appointment_capacity_extend.js | 48 ++++++------- views/appointment_templates.xml | 16 ++--- 13 files changed, 115 insertions(+), 114 deletions(-) create mode 100644 __pycache__/__init__.cpython-310.pyc create mode 100644 __pycache__/__init__.cpython-312.pyc create mode 100644 controllers/__pycache__/__init__.cpython-310.pyc create mode 100644 controllers/__pycache__/__init__.cpython-312.pyc create mode 100644 controllers/__pycache__/main.cpython-310.pyc create mode 100644 controllers/__pycache__/main.cpython-312.pyc diff --git a/README.md b/README.md index a9f2c0b..3f48ce5 100644 --- a/README.md +++ b/README.md @@ -1,35 +1,35 @@ -# Appointment Capacity Extension - -This module extends the appointment capacity limit in Odoo to use the total capacity of all resources assigned to an appointment type instead of the hardcoded limit of 12 people. - -## Functionality - -- Removes the hardcoded 12-person limit for appointment bookings -- Sets the maximum capacity based on the total capacity of all resources assigned to an appointment type -- Works with resource-based appointment types that have the "Manage Capacities" option enabled - -## Installation - -1. Copy the `appointment_capacity_extend` folder to your Odoo custom addons directory -2. Update the Odoo apps list -3. Install the "Appointment Capacity Extension" module - -## Configuration - -No additional configuration is required. The module automatically extends the capacity limit based on the total capacity of resources assigned to each appointment type. - -## Usage - -1. Create or edit an appointment type -2. Assign resources with capacities to the appointment type -3. Enable the "Manage Capacities" option -4. The maximum capacity for bookings will automatically be set to the total capacity of all assigned resources - -## Technical Details - -The module overrides the `_prepare_appointment_type_page_values` method in the appointment controller to modify the `max_capacity` value that is passed to the frontend template. It also includes a JavaScript extension to handle capacity selection in the frontend. - -## Limitations - -- Only works with resource-based appointment types (not user-based) +# Appointment Capacity Extension + +This module extends the appointment capacity limit in Odoo to use the total capacity of all resources assigned to an appointment type instead of the hardcoded limit of 12 people. + +## Functionality + +- Removes the hardcoded 12-person limit for appointment bookings +- Sets the maximum capacity based on the total capacity of all resources assigned to an appointment type +- Works with resource-based appointment types that have the "Manage Capacities" option enabled + +## Installation + +1. Copy the `appointment_capacity_extend` folder to your Odoo custom addons directory +2. Update the Odoo apps list +3. Install the "Appointment Capacity Extension" module + +## Configuration + +No additional configuration is required. The module automatically extends the capacity limit based on the total capacity of resources assigned to each appointment type. + +## Usage + +1. Create or edit an appointment type +2. Assign resources with capacities to the appointment type +3. Enable the "Manage Capacities" option +4. The maximum capacity for bookings will automatically be set to the total capacity of all assigned resources + +## Technical Details + +The module overrides the `_prepare_appointment_type_page_values` method in the appointment controller to modify the `max_capacity` value that is passed to the frontend template. It also includes a JavaScript extension to handle capacity selection in the frontend. + +## Limitations + +- Only works with resource-based appointment types (not user-based) - Requires the "Manage Capacities" option to be enabled on the appointment type \ No newline at end of file diff --git a/__init__.py b/__init__.py index 8e3fc39..f6fd3f2 100644 --- a/__init__.py +++ b/__init__.py @@ -1,2 +1,2 @@ -# -*- coding: utf-8 -*- +# -*- coding: utf-8 -*- from . import controllers \ No newline at end of file diff --git a/__manifest__.py b/__manifest__.py index 47ea14d..335b65b 100644 --- a/__manifest__.py +++ b/__manifest__.py @@ -1,25 +1,26 @@ -# -*- coding: utf-8 -*- -{ - 'name': 'Appointment Capacity Extension', - "author": "Suheardy Yacob", - 'summary': 'Extends appointment capacity based on resource total capacity', - 'description': """ - This module extends the appointment capacity limit to use the total capacity - of all resources assigned to an appointment type instead of the hardcoded limit of 12 people. - """, - 'version': '1.0', - 'category': 'Productivity', - 'depends': ['appointment'], - 'data': [ - 'views/appointment_templates.xml', - ], - 'assets': { - 'web.assets_frontend': [ - 'appointment_capacity_extend/static/src/js/appointment_capacity_extend.js', - ], - }, - 'installable': True, - 'application': False, - 'auto_install': False, - 'license': 'OEEL-1', +# -*- coding: utf-8 -*- +{ + 'name': 'Appointment Capacity Extension', + "author": "Suheardy Yacob", + 'summary': 'Extends appointment capacity based on resource total capacity', + 'description': """ + This module extends the appointment capacity limit to use the total capacity + of all resources assigned to an appointment type instead of the hardcoded limit of 12 people. + """, + 'author': 'Suherdy Yacob', + 'version': '1.0', + 'category': 'Productivity', + 'depends': ['appointment'], + 'data': [ + 'views/appointment_templates.xml', + ], + 'assets': { + 'web.assets_frontend': [ + 'appointment_capacity_extend/static/src/js/appointment_capacity_extend.js', + ], + }, + 'installable': True, + 'application': False, + 'auto_install': False, + 'license': 'OEEL-1', } \ No newline at end of file diff --git a/__pycache__/__init__.cpython-310.pyc b/__pycache__/__init__.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..076cee7b1c702d6103cdb7d35a6b5b2cb1eb72da GIT binary patch literal 231 zcmYjLu?oU46iljvC7Uk{XkrlAmvA9+O;J zT#}!gn39s8R~(aAP>`RQSCX5WR}!C`Sdf^USyCCFT2Ydkml6{npP83g5+AQuPO9jnCTXtGAP7wuJ$0S&K}c!QMk$*58mShCx#56WEOS+tjUV}2`Mh1?OAEurpQ_r z@|2v}yX$?nxa7Wxdvc0Ub3&r|f~&fUWF;cGic9awxM;PDLP;-`iH*>Qs2y@eE(R(~ l9V#w_aV82e^G!QgS;D&1>o7 zll~Q6`j-gaz2xet|AHrz*={>}YT&)Ryd>}Y@+A?Y(HgSt=hq*zUp_*=-JsiS4((V| z&T+(Xj#Af?92X=d*u`G%6@Kcsv7ZM;n1&d=LpUY1G9{fuiFJ% zWX%i7ed2p3@9*$<;yWomCX0!_A3Y*%X52UazOwh}J7FZTb7tVe*nK$ZxpAvmywoc0Xl2D+ l{W{gnONY=_?+|GzIU=UNy*$Y)_b`={u#bmih=+LH`wLE^P>TQn literal 0 HcmV?d00001 diff --git a/controllers/__pycache__/main.cpython-312.pyc b/controllers/__pycache__/main.cpython-312.pyc new file mode 100644 index 0000000000000000000000000000000000000000..10105d922e9690d5f4b851409e51198b93fbc8fb GIT binary patch literal 1281 zcma)5&1(}u6rb6zG$s)Pw)LyBs0AZ5;z`g_6=}pvrFvU}6fUkG|h6cGjlK|Od=s#rWZvzyf5$p`c1y_q+^_c^air7b|xt9vh-?+gGw zDP>6JKv=Iy;W5AfLmxP5*L)agjs}&i`+8tFMk*V=8CZ@5fd{YK1%?AwM03oJPJ+sFyv@_y7y6+fu(Hqawh8 z7&sc%x}X6uT+2Ip7py?XxBx1;*gp#C#;(`mo%t0`LOkL?Cca53>4IGAtCBr}j{%2L zNa=1a0r#YB0uwFK8+r>Q#uIoS-ZT?3Hv$)N+3#;}Pkbm^%wCJaXWhS>HmtSB+=HX5kS2t_R{wr|2nd*X3|)v0yux=XJx zVGaCm{l`ZhAFLHsev?VjP96J{r)l z9w@7G-P;^ORu9}(SdBZhB=K*Y{g1J#{#Pm0tg-WwZLEUN<%x%r{qkJz#JS$$#oi^} zFW>I1+>*R&eX~Gu&-=nmzcBM+_nX4($Elh3Q}g|)`R>B!>4Q(pPZ!=!AMe&4%=L@= zr0uqeZfRYjf{IqF$@Y#R6uJRHNNhnUh|<;}QAB8|?fThGnwcmKD(Mm5N2mhn4i%sp znUi#<Qf#>N`>WfaYc??5uTYk04EewE3|FjU#8`ne*n#H#xFRDBq6IMuUG zR7W~d9jW~2IaS{?4dEHcJgJz(*ld>496caa6)f8;**6_R_z4ugfbkDt>H}E(VQqyI Ny+bE{0=cK}{{XGodWir4 literal 0 HcmV?d00001 diff --git a/controllers/main.py b/controllers/main.py index f909833..7b3e42a 100644 --- a/controllers/main.py +++ b/controllers/main.py @@ -1,23 +1,23 @@ -# -*- coding: utf-8 -*- -import json - -from odoo import http -from odoo.http import request -from odoo.addons.appointment.controllers.appointment import AppointmentController - - -class AppointmentCapacityExtendController(AppointmentController): - - def _prepare_appointment_type_page_values(self, appointment_type, staff_user_id=False, resource_selected_id=False, **kwargs): - """ Override to extend the max capacity based on total resource capacity """ - values = super()._prepare_appointment_type_page_values(appointment_type, staff_user_id, resource_selected_id, **kwargs) - - # For resource-based appointments, use the total capacity of all resources - if appointment_type.schedule_based_on == 'resources': - # Get the total capacity of all resources assigned to this appointment type - total_capacity = appointment_type.resource_total_capacity - # Override the max_capacity to use the total resource capacity instead of the hardcoded 12 - values['max_capacity'] = max(1, total_capacity) # Ensure at least 1 - # For user-based appointments, keep the default behavior or implement a different logic if needed - +# -*- coding: utf-8 -*- +import json + +from odoo import http +from odoo.http import request +from odoo.addons.appointment.controllers.appointment import AppointmentController + + +class AppointmentCapacityExtendController(AppointmentController): + + def _prepare_appointment_type_page_values(self, appointment_type, staff_user_id=False, resource_selected_id=False, **kwargs): + """ Override to extend the max capacity based on total resource capacity """ + values = super()._prepare_appointment_type_page_values(appointment_type, staff_user_id, resource_selected_id, **kwargs) + + # For resource-based appointments, use the total capacity of all resources + if appointment_type.schedule_based_on == 'resources': + # Get the total capacity of all resources assigned to this appointment type + total_capacity = appointment_type.resource_total_capacity + # Override the max_capacity to use the total resource capacity instead of the hardcoded 12 + values['max_capacity'] = max(1, total_capacity) # Ensure at least 1 + # For user-based appointments, keep the default behavior or implement a different logic if needed + return values \ No newline at end of file diff --git a/static/src/js/appointment_capacity_extend.js b/static/src/js/appointment_capacity_extend.js index 3e78231..ee030b0 100644 --- a/static/src/js/appointment_capacity_extend.js +++ b/static/src/js/appointment_capacity_extend.js @@ -1,25 +1,25 @@ -/** @odoo-module **/ - -import publicWidget from "@web/legacy/js/public/public_widget"; - -publicWidget.registry.appointmentSlotSelect.include({ - /** - * Override to allow higher capacity values - */ - _onRefresh: async function (ev) { - // Call the original method - this._super.apply(this, arguments); - - // Additional logic for capacity extension - if (ev.target.id === 'resourceCapacity') { - const selectedCapacity = parseInt($(ev.target).val()); - const maxCapacity = parseInt($(ev.target).data('max_capacity') || 12); - - // Allow higher capacity values based on resource total capacity - if (selectedCapacity > 12 && selectedCapacity <= maxCapacity) { - // The selection is valid, proceed with refresh - return; - } - } - }, +/** @odoo-module **/ + +import publicWidget from "@web/legacy/js/public/public_widget"; + +publicWidget.registry.appointmentSlotSelect.include({ + /** + * Override to allow higher capacity values + */ + _onRefresh: async function (ev) { + // Call the original method + this._super.apply(this, arguments); + + // Additional logic for capacity extension + if (ev.target.id === 'resourceCapacity') { + const selectedCapacity = parseInt($(ev.target).val()); + const maxCapacity = parseInt($(ev.target).data('max_capacity') || 12); + + // Allow higher capacity values based on resource total capacity + if (selectedCapacity > 12 && selectedCapacity <= maxCapacity) { + // The selection is valid, proceed with refresh + return; + } + } + }, }); \ No newline at end of file diff --git a/views/appointment_templates.xml b/views/appointment_templates.xml index 3c9ccdb..7158a9d 100644 --- a/views/appointment_templates.xml +++ b/views/appointment_templates.xml @@ -1,9 +1,9 @@ - - - + + + \ No newline at end of file