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 0000000..076cee7 Binary files /dev/null and b/__pycache__/__init__.cpython-310.pyc differ diff --git a/__pycache__/__init__.cpython-312.pyc b/__pycache__/__init__.cpython-312.pyc new file mode 100644 index 0000000..6decf4a Binary files /dev/null and b/__pycache__/__init__.cpython-312.pyc differ diff --git a/controllers/__init__.py b/controllers/__init__.py index cd4d6a8..5a3e3c8 100644 --- a/controllers/__init__.py +++ b/controllers/__init__.py @@ -1,2 +1,2 @@ -# -*- coding: utf-8 -*- +# -*- coding: utf-8 -*- from . import main \ No newline at end of file diff --git a/controllers/__pycache__/__init__.cpython-310.pyc b/controllers/__pycache__/__init__.cpython-310.pyc new file mode 100644 index 0000000..cc58cbf Binary files /dev/null and b/controllers/__pycache__/__init__.cpython-310.pyc differ diff --git a/controllers/__pycache__/__init__.cpython-312.pyc b/controllers/__pycache__/__init__.cpython-312.pyc new file mode 100644 index 0000000..0f8b334 Binary files /dev/null and b/controllers/__pycache__/__init__.cpython-312.pyc differ diff --git a/controllers/__pycache__/main.cpython-310.pyc b/controllers/__pycache__/main.cpython-310.pyc new file mode 100644 index 0000000..04a3f09 Binary files /dev/null and b/controllers/__pycache__/main.cpython-310.pyc differ diff --git a/controllers/__pycache__/main.cpython-312.pyc b/controllers/__pycache__/main.cpython-312.pyc new file mode 100644 index 0000000..10105d9 Binary files /dev/null and b/controllers/__pycache__/main.cpython-312.pyc differ 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