feat: Extend appointment capacity limit to use total resource capacity.
This commit is contained in:
parent
caa77dc51f
commit
50ce6ab368
68
README.md
68
README.md
@ -1,35 +1,35 @@
|
|||||||
# Appointment Capacity Extension
|
# 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.
|
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
|
## Functionality
|
||||||
|
|
||||||
- Removes the hardcoded 12-person limit for appointment bookings
|
- 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
|
- 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
|
- Works with resource-based appointment types that have the "Manage Capacities" option enabled
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
1. Copy the `appointment_capacity_extend` folder to your Odoo custom addons directory
|
1. Copy the `appointment_capacity_extend` folder to your Odoo custom addons directory
|
||||||
2. Update the Odoo apps list
|
2. Update the Odoo apps list
|
||||||
3. Install the "Appointment Capacity Extension" module
|
3. Install the "Appointment Capacity Extension" module
|
||||||
|
|
||||||
## Configuration
|
## 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.
|
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
|
## Usage
|
||||||
|
|
||||||
1. Create or edit an appointment type
|
1. Create or edit an appointment type
|
||||||
2. Assign resources with capacities to the appointment type
|
2. Assign resources with capacities to the appointment type
|
||||||
3. Enable the "Manage Capacities" option
|
3. Enable the "Manage Capacities" option
|
||||||
4. The maximum capacity for bookings will automatically be set to the total capacity of all assigned resources
|
4. The maximum capacity for bookings will automatically be set to the total capacity of all assigned resources
|
||||||
|
|
||||||
## Technical Details
|
## 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.
|
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
|
## Limitations
|
||||||
|
|
||||||
- Only works with resource-based appointment types (not user-based)
|
- Only works with resource-based appointment types (not user-based)
|
||||||
- Requires the "Manage Capacities" option to be enabled on the appointment type
|
- Requires the "Manage Capacities" option to be enabled on the appointment type
|
||||||
@ -1,2 +1,2 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
from . import controllers
|
from . import controllers
|
||||||
@ -1,25 +1,26 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
{
|
{
|
||||||
'name': 'Appointment Capacity Extension',
|
'name': 'Appointment Capacity Extension',
|
||||||
"author": "Suheardy Yacob",
|
"author": "Suheardy Yacob",
|
||||||
'summary': 'Extends appointment capacity based on resource total capacity',
|
'summary': 'Extends appointment capacity based on resource total capacity',
|
||||||
'description': """
|
'description': """
|
||||||
This module extends the appointment capacity limit to use the total capacity
|
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.
|
of all resources assigned to an appointment type instead of the hardcoded limit of 12 people.
|
||||||
""",
|
""",
|
||||||
'version': '1.0',
|
'author': 'Suherdy Yacob',
|
||||||
'category': 'Productivity',
|
'version': '1.0',
|
||||||
'depends': ['appointment'],
|
'category': 'Productivity',
|
||||||
'data': [
|
'depends': ['appointment'],
|
||||||
'views/appointment_templates.xml',
|
'data': [
|
||||||
],
|
'views/appointment_templates.xml',
|
||||||
'assets': {
|
],
|
||||||
'web.assets_frontend': [
|
'assets': {
|
||||||
'appointment_capacity_extend/static/src/js/appointment_capacity_extend.js',
|
'web.assets_frontend': [
|
||||||
],
|
'appointment_capacity_extend/static/src/js/appointment_capacity_extend.js',
|
||||||
},
|
],
|
||||||
'installable': True,
|
},
|
||||||
'application': False,
|
'installable': True,
|
||||||
'auto_install': False,
|
'application': False,
|
||||||
'license': 'OEEL-1',
|
'auto_install': False,
|
||||||
|
'license': 'OEEL-1',
|
||||||
}
|
}
|
||||||
BIN
__pycache__/__init__.cpython-310.pyc
Normal file
BIN
__pycache__/__init__.cpython-310.pyc
Normal file
Binary file not shown.
BIN
__pycache__/__init__.cpython-312.pyc
Normal file
BIN
__pycache__/__init__.cpython-312.pyc
Normal file
Binary file not shown.
@ -1,2 +1,2 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
from . import main
|
from . import main
|
||||||
BIN
controllers/__pycache__/__init__.cpython-310.pyc
Normal file
BIN
controllers/__pycache__/__init__.cpython-310.pyc
Normal file
Binary file not shown.
BIN
controllers/__pycache__/__init__.cpython-312.pyc
Normal file
BIN
controllers/__pycache__/__init__.cpython-312.pyc
Normal file
Binary file not shown.
BIN
controllers/__pycache__/main.cpython-310.pyc
Normal file
BIN
controllers/__pycache__/main.cpython-310.pyc
Normal file
Binary file not shown.
BIN
controllers/__pycache__/main.cpython-312.pyc
Normal file
BIN
controllers/__pycache__/main.cpython-312.pyc
Normal file
Binary file not shown.
@ -1,23 +1,23 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
import json
|
import json
|
||||||
|
|
||||||
from odoo import http
|
from odoo import http
|
||||||
from odoo.http import request
|
from odoo.http import request
|
||||||
from odoo.addons.appointment.controllers.appointment import AppointmentController
|
from odoo.addons.appointment.controllers.appointment import AppointmentController
|
||||||
|
|
||||||
|
|
||||||
class AppointmentCapacityExtendController(AppointmentController):
|
class AppointmentCapacityExtendController(AppointmentController):
|
||||||
|
|
||||||
def _prepare_appointment_type_page_values(self, appointment_type, staff_user_id=False, resource_selected_id=False, **kwargs):
|
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 """
|
""" 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)
|
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
|
# For resource-based appointments, use the total capacity of all resources
|
||||||
if appointment_type.schedule_based_on == 'resources':
|
if appointment_type.schedule_based_on == 'resources':
|
||||||
# Get the total capacity of all resources assigned to this appointment type
|
# Get the total capacity of all resources assigned to this appointment type
|
||||||
total_capacity = appointment_type.resource_total_capacity
|
total_capacity = appointment_type.resource_total_capacity
|
||||||
# Override the max_capacity to use the total resource capacity instead of the hardcoded 12
|
# 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
|
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
|
# For user-based appointments, keep the default behavior or implement a different logic if needed
|
||||||
|
|
||||||
return values
|
return values
|
||||||
@ -1,25 +1,25 @@
|
|||||||
/** @odoo-module **/
|
/** @odoo-module **/
|
||||||
|
|
||||||
import publicWidget from "@web/legacy/js/public/public_widget";
|
import publicWidget from "@web/legacy/js/public/public_widget";
|
||||||
|
|
||||||
publicWidget.registry.appointmentSlotSelect.include({
|
publicWidget.registry.appointmentSlotSelect.include({
|
||||||
/**
|
/**
|
||||||
* Override to allow higher capacity values
|
* Override to allow higher capacity values
|
||||||
*/
|
*/
|
||||||
_onRefresh: async function (ev) {
|
_onRefresh: async function (ev) {
|
||||||
// Call the original method
|
// Call the original method
|
||||||
this._super.apply(this, arguments);
|
this._super.apply(this, arguments);
|
||||||
|
|
||||||
// Additional logic for capacity extension
|
// Additional logic for capacity extension
|
||||||
if (ev.target.id === 'resourceCapacity') {
|
if (ev.target.id === 'resourceCapacity') {
|
||||||
const selectedCapacity = parseInt($(ev.target).val());
|
const selectedCapacity = parseInt($(ev.target).val());
|
||||||
const maxCapacity = parseInt($(ev.target).data('max_capacity') || 12);
|
const maxCapacity = parseInt($(ev.target).data('max_capacity') || 12);
|
||||||
|
|
||||||
// Allow higher capacity values based on resource total capacity
|
// Allow higher capacity values based on resource total capacity
|
||||||
if (selectedCapacity > 12 && selectedCapacity <= maxCapacity) {
|
if (selectedCapacity > 12 && selectedCapacity <= maxCapacity) {
|
||||||
// The selection is valid, proceed with refresh
|
// The selection is valid, proceed with refresh
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
@ -1,9 +1,9 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<odoo>
|
<odoo>
|
||||||
<template id="appointment_info_capacity_extend" inherit_id="appointment.appointment_info" name="Appointment Capacity Extension">
|
<template id="appointment_info_capacity_extend" inherit_id="appointment.appointment_info" name="Appointment Capacity Extension">
|
||||||
<!-- Override the capacity selection to allow higher values -->
|
<!-- Override the capacity selection to allow higher values -->
|
||||||
<xpath expr="//select[@id='resourceCapacity']" position="attributes">
|
<xpath expr="//select[@id='resourceCapacity']" position="attributes">
|
||||||
<attribute name="t-att-data-max_capacity">max_capacity</attribute>
|
<attribute name="t-att-data-max_capacity">max_capacity</attribute>
|
||||||
</xpath>
|
</xpath>
|
||||||
</template>
|
</template>
|
||||||
</odoo>
|
</odoo>
|
||||||
Loading…
Reference in New Issue
Block a user