如何在注册页面Odoo中添加字段“状态”?

时间:2018-09-24 13:43:19

标签: authentication select state odoo checkout

我需要在Odoo 8的页面Sinup页面中添加“状态”字段。

该字段正确显示在页面中,但是我没有状态列表...

为什么?

这是我的控制者:

import logging
import werkzeug
import openerp
from openerp.addons.auth_signup.res_users import SignupError
from openerp.addons.web.controllers.main import ensure_db
from openerp import http
from openerp.http import request
from openerp.addons.website_sale.controllers.main import website_sale
_logger = logging.getLogger(__name__)

def login_redirect_a():
url = '/sale_login?'
# built the redirect url, keeping all the query parameters of the url
redirect_url = '%s?%s' % (
    request.httprequest.base_url, werkzeug.urls.url_encode(request.params))
return """<html><head><script>
window.location = '%sredirect=' + encodeURIComponent("%s" + location.hash);
</script></head></html>
""" % (url, redirect_url)

@http.route(['/sale_login'], type='http', auth="public", website=True)

def do_signup(self, qcontext):
    """ Shared helper that creates a res.partner out of a token """
    values = dict((key, qcontext.get(key))
                  for key in ('login', 'name', 'password', 'state_id', 'country_id'))
    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."
    values['lang'] = request.lang
    self._signup_with_values(qcontext.get('token'), values)
    request.cr.commit()

def get_auth_signup_qcontext(self):
    """ Shared helper returning the rendering
    context for signup and reset password """
    qcontext = request.params.copy()
    qcontext['states'] = request.env["res.country.state"].sudo().search([])
qcontext['countries'] = request.env["res.country"].sudo().search([])
    return qcontext

1 个答案:

答案 0 :(得分:0)

我的问题是,为什么期望在new字段中获取要加载的状态列表? 为了加载它,您需要对AuthSignupHome控制器进行python扩展,特别是重写方法get_auth_signup_qcontext以添加状态列表,例如:

from openerp.http import request
from openerp.addons.auth_signup.controllers.main import AuthSignupHome

class AuthSignupHomeExt(AuthSignupHome):

    def get_auth_signup_qcontext(self):
        qcontext = super(AuthSignupHomeExt, self).get_auth_signup_qcontext()
        qcontext['states'] = request.env["res.country.state"].sudo().search([])
        return qcontext