Skip to content
Snippets Groups Projects

MOD public subscription form improvements

Merged Xavier Bonet requested to merge MOD_public_subscription_form_improvements into main
2 files
+ 119
2
Compare changes
  • Side-by-side
  • Inline
Files
2
@@ -2,6 +2,8 @@ from odoo import http
from odoo.http import request
from odoo.tools.translate import _
from odoo.addons.cooperator_website.controllers import main as emyc_wsc
from urllib.parse import urljoin
import re
class WebsiteSubscriptionCCEE(emyc_wsc.WebsiteSubscription):
@@ -28,15 +30,48 @@ class WebsiteSubscriptionCCEE(emyc_wsc.WebsiteSubscription):
self).display_become_cooperator_page(**kwargs)
return res
@http.route() # noqa: C901 (method too complex)
def share_subscription(self, **kwargs):
target_odoo_company_id = False
if kwargs.get('company_id', False):
try:
target_odoo_company_id = int(kwargs.get('company_id'))
except:
pass
if ('odoo_company_id' in kwargs) and (not target_odoo_company_id or not request.env['res.company'].sudo().search(
[('id', '=', target_odoo_company_id)])):
return http.Response(_("Not valid parameter value [odoo_company_id]"), status=500)
ctx = dict(request.context)
ctx.update({'target_odoo_company_id': target_odoo_company_id})
request.context = ctx
res = super(WebsiteSubscriptionCCEE,
self).share_subscription(**kwargs)
return res
def fill_values(self, values, is_company, logged, load_from_user=False):
values = super(WebsiteSubscriptionCCEE, self).fill_values(
values, is_company, logged, load_from_user)
default_company = request.env["res.company"]._company_default_get()
# get target_company under display_become_cooperator_page controller:
target_company_id = request.context.get('target_odoo_company_id', False) and int(
request.context.get('target_odoo_company_id')) or None
# get target_company under share_subscription controller:
if values.get('company_id',None) and (int(values['company_id']) != default_company.id):
target_company_id = values['company_id']
#ctx = dict(request.context)
#ctx.update({'target_odoo_company_id': target_company_id})
#request.context = ctx
if target_company_id and target_company_id != default_company.id:
company = request.env['res.company'].sudo().search(
[('id', '=', target_company_id)])
@@ -77,3 +112,49 @@ class WebsiteSubscriptionCCEE(emyc_wsc.WebsiteSubscription):
return values
def validation( # noqa: C901 (method too complex)
self, kwargs, logged, values, post_file
):
ret = super(WebsiteSubscriptionCCEE, self).validation(kwargs, logged, values, post_file)
target_odoo_company_id = kwargs.get('company_id') and int(kwargs.get('company_id')) or None
redirect = "cooperator_website.becomecooperator"
# redirect url to fall back on become coopererator in template redirection
if target_odoo_company_id:
values["redirect_url"] = urljoin(
request.httprequest.host_url, "/page/become_cooperator?odoo_company_id={}".format(target_odoo_company_id)
)
else:
values["redirect_url"] = urljoin(
request.httprequest.host_url, "/page/become_cooperator"
)
email = kwargs.get("email")
sani_vat = re.sub(r"[^a-zA-Z0-9]","",kwargs.get("vat", "")).lower()
is_company = kwargs.get("is_company") == "on"
if not logged and sani_vat:
user_in_ce = request.env['res.users'].sudo().search([("login", "=", sani_vat), ('company_id','=', target_odoo_company_id)])
if user_in_ce:
values = self.fill_values(values, is_company, logged)
values.update(kwargs)
values["error_msg"] = _(
"There is an existing account for this"
" vat number on this community. "
"Please contact with the community administrators."
)
return request.render(redirect, values)
if not logged and email:
user_in_ce = request.env['res.users'].sudo().search([("partner_id.email", "=", email), ('company_id','=', target_odoo_company_id)])
if user_in_ce:
values = self.fill_values(values, is_company, logged)
values.update(kwargs)
values["error_msg"] = _(
"There is an existing account for this"
" email address on this community. "
"Please contact with the community administrators."
)
return request.render(redirect, values)
return ret
Loading