Files
2026-07-01 14:41:49 +07:00

85 lines
3.4 KiB
Python

# -*- coding: utf-8 -*-
from odoo import http
from odoo.http import request
class SaasTrialController(http.Controller):
"""Flow 1: User Registration & App Selection Flow
Handles: domain-name.com/trial
"""
@http.route('/trial', type='http', auth='public', website=True, sitemap=True)
def trial_signup_page(self, **kw):
"""Step: Choose your Apps
Mirrors odoo.com/trial - shows ONLY real installed apps
(saas.app is synced from ir.module.module where
state='installed' and application=True), grouped by category,
exactly like the reference screenshot.
"""
apps = request.env['saas.app'].sudo().search([('active', '=', True)])
groups = {}
order = []
for app in apps:
cat_name = app.category_id.name or 'Other'
if cat_name not in groups:
groups[cat_name] = []
order.append(cat_name)
groups[cat_name].append(app)
app_groups = [(cat, groups[cat]) for cat in order]
countries = request.env['res.country'].sudo().search([], order='name')
languages = request.env['res.lang'].sudo().get_installed()
return request.render('saas_trial_portal.trial_signup_template', {
'app_groups': app_groups,
'countries': countries,
'languages': languages,
})
@http.route('/trial/submit', type='http', auth='public', website=True, methods=['POST'])
def trial_signup_submit(self, **post):
import json
app_ids_raw = post.get('app_ids_json') or '[]'
try:
app_ids = [int(a) for a in json.loads(app_ids_raw)]
except (ValueError, TypeError):
app_ids = []
trial = request.env['saas.trial.request'].sudo().create({
'name': post.get('name'),
'company_name': post.get('company_name'),
'email': post.get('email'),
'phone': post.get('phone'),
'country_id': int(post['country_id']) if post.get('country_id') else False,
'lang': post.get('lang') or False,
'company_size': post.get('company_size') or False,
'primary_interest': post.get('primary_interest') or False,
'app_ids': [(6, 0, app_ids)],
})
trial.action_submit_and_send_verification()
return request.render('saas_trial_portal.trial_check_email_template', {
'email': trial.email,
})
@http.route('/trial/verify', type='http', auth='public', website=True)
def trial_verify_email(self, token=None, id=None, **kw):
trial = request.env['saas.trial.request'].sudo().browse(int(id)) if id else None
if not trial or not trial.exists():
return request.render('saas_trial_portal.trial_error_template', {
'message': 'Invalid verification link.'
})
trial.action_verify_email(token)
return request.render('saas_trial_portal.trial_activated_template', {
'trial': trial,
})
@http.route('/trial/continue', type='http', auth='public', website=True, methods=['POST'])
def trial_continue(self, id=None, **kw):
trial = request.env['saas.trial.request'].sudo().browse(int(id))
database = trial.action_continue_to_provisioning()
return request.render('saas_trial_portal.trial_provisioning_template', {
'trial': trial,
'database': database,
})