commit caa77dc51f3e69bbaa09d2130ff78639669a471d Author: Suherdy SYC. Yacob Date: Sat Sep 20 12:00:44 2025 +0700 first commit diff --git a/README.md b/README.md new file mode 100644 index 0000000..a9f2c0b --- /dev/null +++ b/README.md @@ -0,0 +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) +- 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 new file mode 100644 index 0000000..8e3fc39 --- /dev/null +++ b/__init__.py @@ -0,0 +1,2 @@ +# -*- coding: utf-8 -*- +from . import controllers \ No newline at end of file diff --git a/__manifest__.py b/__manifest__.py new file mode 100644 index 0000000..47ea14d --- /dev/null +++ b/__manifest__.py @@ -0,0 +1,25 @@ +# -*- 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', +} \ No newline at end of file diff --git a/controllers/__init__.py b/controllers/__init__.py new file mode 100644 index 0000000..cd4d6a8 --- /dev/null +++ b/controllers/__init__.py @@ -0,0 +1,2 @@ +# -*- coding: utf-8 -*- +from . import main \ No newline at end of file diff --git a/controllers/main.py b/controllers/main.py new file mode 100644 index 0000000..f909833 --- /dev/null +++ b/controllers/main.py @@ -0,0 +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 + + 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 new file mode 100644 index 0000000..3e78231 --- /dev/null +++ b/static/src/js/appointment_capacity_extend.js @@ -0,0 +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; + } + } + }, +}); \ No newline at end of file diff --git a/views/appointment_templates.xml b/views/appointment_templates.xml new file mode 100644 index 0000000..3c9ccdb --- /dev/null +++ b/views/appointment_templates.xml @@ -0,0 +1,9 @@ + + + + \ No newline at end of file