Modified sports.event creation interfaces onchange events for start and end datetimes to adjust therapist start time to 120 min before. Extended functionality to internal views. Modified add activity interface to default to To-Do type.

This commit is contained in:
Denis Durepos 2025-08-15 20:10:28 -04:00
parent 2d052d630b
commit 580e61d840
5 changed files with 16 additions and 8 deletions

View file

@ -4,7 +4,7 @@ from odoo.exceptions import UserError, ValidationError
from odoo.http import request
from odoo.addons.portal.controllers.portal import CustomerPortal, pager
from .access_control_mixin import AccessControlMixin
from datetime import timedelta
from datetime import date, timedelta
_logger = logging.getLogger(__name__)
@ -81,8 +81,6 @@ class TaskManagementPortal(CustomerPortal, AccessControlMixin):
# Get activity types for filtering
activity_types = request.env['mail.activity.type'].search([])
from datetime import date
# Get available users for reassignment (treatment professionals)
available_users = request.env['res.users'].search([
('groups_id', 'in', [request.env.ref('bemade_sports_clinic.group_portal_treatment_professional').id])
@ -119,6 +117,15 @@ class TaskManagementPortal(CustomerPortal, AccessControlMixin):
# Get activity types
activity_types = request.env['mail.activity.type'].search([])
# Determine default activity type robustly
# 1) Try canonical XML-ID from mail: 'mail.mail_activity_data_todo'
default_activity_type = request.env.ref('mail.mail_activity_data_todo', raise_if_not_found=False)
# 2) Fallback: category 'todo'
if not default_activity_type:
default_activity_type = request.env['mail.activity.type'].search([('category', '=', 'todo')], limit=1)
# 3) Fallback: name contains 'todo'
if not default_activity_type:
default_activity_type = request.env['mail.activity.type'].search([('name', 'ilike', 'todo')], limit=1)
# Get users that can be assigned to activities
domain = []
@ -157,6 +164,7 @@ class TaskManagementPortal(CustomerPortal, AccessControlMixin):
'model': model,
'res_id': res_id,
'default_user_id': request.env.user.id,
'default_activity_type_id': default_activity_type.id if default_activity_type else False,
'return_url': kw.get('return_url', return_url),
'page_name': 'create_activity',
'today': date.today().strftime('%Y-%m-%d'),

View file

@ -249,13 +249,13 @@ class SportsEvent(models.Model):
@api.onchange('date_start')
def _onchange_date_start(self):
"""When event start changes:
- therapist_start = 30 minutes prior
- therapist_start = 120 minutes prior
- date_end = 2 hours after
- therapist_end = date_end
"""
if self.date_start:
from datetime import timedelta
self.therapist_start = self.date_start - timedelta(minutes=30)
self.therapist_start = self.date_start - timedelta(minutes=120)
self.date_end = self.date_start + timedelta(hours=2)
self.therapist_end = self.date_end

View file

@ -451,7 +451,7 @@
var startDt = parseLocal(dateStart.value);
if (!startDt) return;
if (therapistStart) {
therapistStart.value = formatLocal(addMinutes(startDt, -30));
therapistStart.value = formatLocal(addMinutes(startDt, -120));
}
if (dateEnd) {
var endDt = addMinutes(startDt, 120);

View file

@ -484,7 +484,7 @@
var startDt = parseLocal(dateStart.value);
if (!startDt) return;
if (therapistStart) {
therapistStart.value = formatLocal(addMinutes(startDt, -30));
therapistStart.value = formatLocal(addMinutes(startDt, -120));
}
if (dateEnd) {
var endDt = addMinutes(startDt, 120);

View file

@ -411,7 +411,7 @@
<select name="activity_type_id" id="activity_type_id" class="form-control" required="required">
<option value="">Select Activity Type</option>
<t t-foreach="activity_types" t-as="activity_type">
<option t-att-value="activity_type.id">
<option t-att-value="activity_type.id" t-att-selected="activity_type.id == default_activity_type_id and 'selected' or None">
<t t-esc="activity_type.name"/>
</option>
</t>