Browse Source

[IMP] add fields on the create sign on form

9.0_remove_national_register_number
houssine 5 years ago
parent
commit
b5fdd66be9
  1. 4
      easy_my_coop/__openerp__.py
  2. 89
      easy_my_coop/controllers/AuthSignupHome.py
  3. 1
      easy_my_coop/controllers/__init__.py
  4. 48
      easy_my_coop/view/auth_signup_template.xml

4
easy_my_coop/__openerp__.py

@ -20,8 +20,9 @@
############################################################################## ##############################################################################
{ {
"name": "Easy My Coop", "name": "Easy My Coop",
"version": "9.0.1.3.1",
"version": "9.1.0.0.1",
"depends": ["base", "depends": ["base",
'auth_signup',
"sale", "sale",
"purchase", "purchase",
"account_accountant", "account_accountant",
@ -56,6 +57,7 @@
'view/cooperator_register_view.xml', 'view/cooperator_register_view.xml',
'view/operation_request_view.xml', 'view/operation_request_view.xml',
'view/account_invoice_view.xml', 'view/account_invoice_view.xml',
'view/auth_signup_template.xml',
'view/subscription_template.xml', 'view/subscription_template.xml',
'view/product_view.xml', 'view/product_view.xml',
'view/res_company_view.xml', 'view/res_company_view.xml',

89
easy_my_coop/controllers/AuthSignupHome.py

@ -0,0 +1,89 @@
# -*- coding: utf-8 -*-
# © 2019 Coop IT Easy (http://www.coopiteasy.be)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
import logging
from openerp import tools
from openerp.tools.translate import _
from openerp import http
from openerp.http import request
from openerp.addons.auth_signup.res_users import SignupError
from openerp.addons.auth_signup.controllers.main import AuthSignupHome
from openerp.addons.base_iban import base_iban
from openerp.exceptions import ValidationError
_logger = logging.getLogger(__name__)
FORM_FIELDS = ['login', 'name', 'password', 'phone', 'street',
'city', 'zip_code', 'country_id']
class AuthSignupHome(AuthSignupHome):
def _signup_with_values(self, token, values):
user_obj = request.env['res.users']
db, login, password = user_obj.sudo().signup(values, token)
# as authenticate will use its own cursor we need to commit
# the current transaction
request.cr.commit()
uid = request.session.authenticate(db, login, password)
if not uid:
raise SignupError(_('Authentication Failed.'))
return uid
def do_signup(self, qcontext):
""" Shared helper that creates a res.partner out of a token """
bank_obj = request.env['res.partner.bank']
lang_obj = request.env['res.lang']
values = dict((key, qcontext.get(key)) for key in FORM_FIELDS)
assert any([k for k in values.values()]),"The form was not properly filled in."
assert values.get('password') == qcontext.get('confirm_password'), "Passwords do not match; please retype them."
supported_langs = [lang['code'] for lang
in lang_obj.sudo().search_read([], ['code'])]
if request.lang in supported_langs:
values['lang'] = request.lang
values['zip'] = values['zip_code']
uid = self._signup_with_values(qcontext.get('token'), values)
iban = qcontext.get('iban')
user = request.env['res.users'].sudo().search([('id', '=', uid)])
bank_obj.sudo().create({'partner_id': user.partner_id.id,
'acc_number': iban})
request.cr.commit()
@http.route('/web/signup', type='http', auth='public', website=True)
def web_auth_signup(self, *args, **kw):
qcontext = self.get_auth_signup_qcontext()
users_obj = request.env["res.users"]
country_obj = request.env['res.country']
if qcontext.get("login", False) and not tools.single_email_re.match(qcontext.get("login", "")):
qcontext["error"] = _("That does not seem to be an email address.")
if qcontext.get("iban", False):
try:
base_iban.validate_iban(qcontext.get("iban"))
except ValidationError:
qcontext["error"] = _("Please give a correct IBAN number.")
if not qcontext.get('token') and not qcontext.get('signup_enabled'):
raise werkzeug.exceptions.NotFound()
if 'error' not in qcontext and request.httprequest.method == 'POST':
try:
self.do_signup(qcontext)
return super(AuthSignupHome, self).web_login(*args, **kw)
except (SignupError, AssertionError), e:
domain = [("login", "=", qcontext.get("login"))]
if users_obj.sudo().search(domain):
qcontext["error"] = _("Another user is already registered "
"using this email address.")
else:
_logger.error(e.message)
qcontext['error'] = _("Could not create a new account.")
if not qcontext.get('raliment_point_id', False):
qcontext['raliment_point_id'] = 0
if not qcontext.get('delivery_point_id', False):
qcontext['delivery_point_id'] = 0
qcontext['countries'] = country_obj.sudo().search([])
qcontext['country_id'] = '21'
return request.render('auth_signup.signup', qcontext)

1
easy_my_coop/controllers/__init__.py

@ -1 +1,2 @@
from . import main from . import main
from . import AuthSignupHome

48
easy_my_coop/view/auth_signup_template.xml

@ -0,0 +1,48 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data>
<template id="easy_my_coop_auth_fields" inherit_id="auth_signup.fields" name="Auth Signup/ResetPassword form fields">
<xpath expr="//div[@class='form-group field-name']" position="after">
<div class="form-group field-name">
<label for="iban" class="control-label">IBAN number</label>
<input type="text" name="iban" t-att-value="iban" id="iban" class="form-control" placeholder="BE645215965478"
required="required" t-att-readonly="'readonly' if only_passwords else None" />
</div>
<div class="form-group field-name">
<label for="phone" class="control-label">Your Phone</label>
<input type="text" name="phone" t-att-value="phone" id="phone" class="form-control" placeholder="+325552365"
required="required" t-att-readonly="'readonly' if only_passwords else None" />
</div>
<div class="form-group field-name">
<label for="street" class="control-label">Your Street and Number</label>
<input type="text" name="street" t-att-value="street" id="street" class="form-control" placeholder="Rue de la transition, 63"
required="required" t-att-readonly="'readonly' if only_passwords else None" />
</div>
<div class="form-group field-name">
<label for="zip_code" class="control-label">Your Zip Code</label>
<input type="text" name="zip_code" t-att-value="zip_code" id="zip_code" class="form-control" placeholder="1040"
required="required" t-att-readonly="'readonly' if only_passwords else None" />
</div>
<div class="form-group field-name">
<label for="city" class="control-label">Your City</label>
<input type="text" name="city" t-att-value="city" id="city" class="form-control" placeholder="Bruxelles"
required="required" t-att-readonly="'readonly' if only_passwords else None" />
</div>
<div class="form-group field-name">
<label for="country_id" class="control-label">Your Country</label>
<select name="country_id" id="country_id" class="form-control" style="width:54%;" required="required"
t-att-disabled="'disabled' if only_passwords else None" >
<option value="">Country...</option>
<t t-foreach="countries or []" t-as="country">
<option t-att-value="country.id" t-att-selected="country.id == int(country_id)"><t t-esc="country.name"/></option>
</t>
</select>
</div>
</xpath>
</template>
</data>
</odoo>
Loading…
Cancel
Save