diff --git a/bemade_sports_clinic/controllers/task_management_portal.py b/bemade_sports_clinic/controllers/task_management_portal.py index 35b3854..0acf3b6 100644 --- a/bemade_sports_clinic/controllers/task_management_portal.py +++ b/bemade_sports_clinic/controllers/task_management_portal.py @@ -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'), diff --git a/bemade_sports_clinic/models/sports_event.py b/bemade_sports_clinic/models/sports_event.py index 822edfd..6d590dc 100644 --- a/bemade_sports_clinic/models/sports_event.py +++ b/bemade_sports_clinic/models/sports_event.py @@ -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 diff --git a/bemade_sports_clinic/views/portal_event_create_template.xml b/bemade_sports_clinic/views/portal_event_create_template.xml index 81e70f1..b9bd733 100644 --- a/bemade_sports_clinic/views/portal_event_create_template.xml +++ b/bemade_sports_clinic/views/portal_event_create_template.xml @@ -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); diff --git a/bemade_sports_clinic/views/portal_event_edit_template.xml b/bemade_sports_clinic/views/portal_event_edit_template.xml index 910f005..f799b88 100644 --- a/bemade_sports_clinic/views/portal_event_edit_template.xml +++ b/bemade_sports_clinic/views/portal_event_edit_template.xml @@ -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); diff --git a/bemade_sports_clinic/views/task_management_portal_templates.xml b/bemade_sports_clinic/views/task_management_portal_templates.xml index 68ece30..973d707 100644 --- a/bemade_sports_clinic/views/task_management_portal_templates.xml +++ b/bemade_sports_clinic/views/task_management_portal_templates.xml @@ -411,7 +411,7 @@