diff --git a/new_project/custom_addons/encoach_portal/controllers/portal.py b/new_project/custom_addons/encoach_portal/controllers/portal.py index f9fa5d0ab..d9275ba25 100644 --- a/new_project/custom_addons/encoach_portal/controllers/portal.py +++ b/new_project/custom_addons/encoach_portal/controllers/portal.py @@ -1,6 +1,6 @@ import json import logging -from odoo import http +from odoo import http, fields from odoo.http import request from odoo.addons.portal.controllers.portal import CustomerPortal @@ -41,6 +41,85 @@ class EncoachPortal(CustomerPortal): 'profile': profile, }) + # ------------------------------------------------------------------ + # JSON-RPC: /encoach/onboarding/goals (called by OWL wizard) + # ------------------------------------------------------------------ + @http.route('/encoach/onboarding/goals', type='json', auth='user') + def onboarding_goals_rpc(self, **kw): + Template = request.env['encoach.exam.template'].sudo() + templates = Template.search([('active', '=', True)]) + seen = set() + goals = [] + icon_map = { + 'ielts': 'fa-language', 'general_english': 'fa-comments', + 'general english': 'fa-comments', 'academic': 'fa-graduation-cap', + 'math': 'fa-calculator', 'mathematics': 'fa-calculator', + 'it': 'fa-laptop', 'information technology': 'fa-laptop', + } + for tpl in templates: + subj = tpl.subject_id + if subj and subj.name and subj.name.lower() not in seen: + seen.add(subj.name.lower()) + goal_id = subj.name.lower().replace(' ', '_') + goals.append({ + 'id': goal_id, + 'name': subj.name, + 'icon': icon_map.get(goal_id, icon_map.get(subj.name.lower(), 'fa-book')), + }) + if not goals: + goals = [ + {'id': 'ielts', 'name': 'IELTS Preparation', 'icon': 'fa-language'}, + {'id': 'general_english', 'name': 'General English', 'icon': 'fa-comments'}, + {'id': 'math', 'name': 'Mathematics', 'icon': 'fa-calculator'}, + {'id': 'it', 'name': 'Information Technology', 'icon': 'fa-laptop'}, + ] + return {'goals': goals} + + # ------------------------------------------------------------------ + # JSON-RPC: /encoach/onboarding/save (called by OWL wizard) + # ------------------------------------------------------------------ + @http.route('/encoach/onboarding/save', type='json', auth='user') + def onboarding_save_rpc(self, **kw): + user = request.env.user + goal = kw.get('goal') + target_level = kw.get('target_level') + study_preference = kw.get('study_preference') + skip_placement = kw.get('skip_placement', False) + learning_style = kw.get('learning_style') + hours_per_week = kw.get('hours_per_week', 0) + + placement_decision = 'skip' if skip_placement else 'take_now' + + profile_vals = { + 'user_id': user.id, + 'learning_goal': goal, + 'study_mode': study_preference, + 'hours_per_week': hours_per_week, + 'placement_decision': placement_decision, + } + + if learning_style: + if isinstance(learning_style, list): + profile_vals['learning_style'] = json.dumps(learning_style) + elif isinstance(learning_style, str): + profile_vals['learning_style'] = json.dumps([learning_style]) + + if skip_placement: + profile_vals['cefr_level'] = 'b1' + + Profile = request.env['encoach.student.profile'].sudo() + profile = Profile.search([('user_id', '=', user.id)], limit=1) + if profile: + profile.write(profile_vals) + else: + profile = Profile.create(profile_vals) + + user.sudo().write({ + 'account_status': 'activated', + 'first_login': False, + }) + return {'ok': True, 'profile_id': profile.id, 'placement_decision': placement_decision} + @http.route('/my/dashboard', type='http', auth='user', website=True) def student_dashboard(self, **kw): user = request.env.user diff --git a/new_project/custom_addons/encoach_portal/views/templates.xml b/new_project/custom_addons/encoach_portal/views/templates.xml index 2221ac386..d236d7d0a 100644 --- a/new_project/custom_addons/encoach_portal/views/templates.xml +++ b/new_project/custom_addons/encoach_portal/views/templates.xml @@ -249,7 +249,7 @@