diff --git a/saas_portal/controllers/main.py b/saas_portal/controllers/main.py index 9ef86e432..945daced4 100644 --- a/saas_portal/controllers/main.py +++ b/saas_portal/controllers/main.py @@ -34,7 +34,7 @@ def add_new_client(self, redirect_to_signup=False, **post): query = {'redirect': redirect} return http.local_redirect(path=url, query=query) - dbname = self.get_full_dbname(post.get('dbname')) + dbname = self.get_full_dbname(post.get('dbname'), post.get('plan_id')) user_id = request.session.uid partner_id = None if user_id: @@ -78,10 +78,13 @@ def get_config_parameter(self, param): full_param = 'saas_portal.%s' % param return config.sudo().get_param(full_param) - def get_full_dbname(self, dbname): - if not dbname: + def get_full_dbname(self, dbname, plan_id): + if not dbname or not plan_id: return None - full_dbname = '%s.%s' % (dbname, self.get_config_parameter('base_saas_domain')) + Plan = request.env['saas_portal.plan'].sudo() + plan = Plan.browse(int(plan_id)) + base_saas_domain = plan.server_id.local_host + full_dbname = '%s.%s' % (dbname, base_saas_domain) return full_dbname.replace('www.', '') def get_plan(self, plan_id=None): diff --git a/saas_portal_signup/controllers/main.py b/saas_portal_signup/controllers/main.py index 2460b3b40..52457fee4 100644 --- a/saas_portal_signup/controllers/main.py +++ b/saas_portal_signup/controllers/main.py @@ -29,13 +29,19 @@ def get_auth_signup_qcontext(self): if not qcontext.get('countries', False): qcontext['countries'] = request.env['res.country'].search([]) if not qcontext.get('base_saas_domain', False): - qcontext['base_saas_domain'] = self.get_saas_domain() + qcontext['base_saas_domain'] = self.get_saas_domain(qcontext.get('plan_id')) return qcontext - def get_saas_domain(self): - config = request.env['ir.config_parameter'] - full_param = 'saas_portal.base_saas_domain' - base_saas_domain = config.sudo().get_param(full_param) + def get_saas_domain(self, plan_id): + # config = request.env['ir.config_parameter'] + # full_param = 'saas_portal.base_saas_domain' + # base_saas_domain = config.sudo().get_param(full_param) + if plan_id: + Plan = request.env['saas_portal.plan'].sudo() + plan = Plan.browse(int(plan_id)) + base_saas_domain = plan.server_id.local_host + else: + base_saas_domain = 'depends on the plan' return base_saas_domain def do_signup(self, qcontext): @@ -45,7 +51,7 @@ def do_signup(self, qcontext): if qcontext.get('country_id', False): values['country_id'] = qcontext['country_id'] if qcontext.get('dbname', False): - f_dbname = '%s.%s' % (qcontext['dbname'], self.get_saas_domain()) + f_dbname = '%s.%s' % (qcontext['dbname'], self.get_saas_domain(qcontext['plan_id'])) full_dbname = f_dbname.replace('www.', '') db_exists = odoo.service.db.exp_db_exist(full_dbname) assert re.match('[a-zA-Z0-9_.-]+$', qcontext.get('dbname')