feat: Extend appointment capacity limit to use total resource capacity.

This commit is contained in:
admin.suherdy 2025-12-06 19:13:44 +07:00
parent caa77dc51f
commit 50ce6ab368
13 changed files with 115 additions and 114 deletions

View File

@ -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

View File

@ -1,2 +1,2 @@
# -*- coding: utf-8 -*-
# -*- coding: utf-8 -*-
from . import controllers

View File

@ -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',
}

Binary file not shown.

Binary file not shown.

View File

@ -1,2 +1,2 @@
# -*- coding: utf-8 -*-
# -*- coding: utf-8 -*-
from . import main

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -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

View File

@ -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;
}
}
},
});

View File

@ -1,9 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<odoo>
<template id="appointment_info_capacity_extend" inherit_id="appointment.appointment_info" name="Appointment Capacity Extension">
<!-- Override the capacity selection to allow higher values -->
<xpath expr="//select[@id='resourceCapacity']" position="attributes">
<attribute name="t-att-data-max_capacity">max_capacity</attribute>
</xpath>
</template>
<?xml version="1.0" encoding="UTF-8"?>
<odoo>
<template id="appointment_info_capacity_extend" inherit_id="appointment.appointment_info" name="Appointment Capacity Extension">
<!-- Override the capacity selection to allow higher values -->
<xpath expr="//select[@id='resourceCapacity']" position="attributes">
<attribute name="t-att-data-max_capacity">max_capacity</attribute>
</xpath>
</template>
</odoo>