2014-12-09 53 views
1

我想通過python編碼在openerp中創建用戶。每當新用戶想要註冊時,我需要爲odoo的網站創建一個用戶。我怎樣才能做到這一點? 我做了以下內容:在OpenERP中創建用戶的問題

def register_user(self, **post): 
    cr, uid, context = request.cr, request.uid, request.context 
    user_obj = request.registry.get('res.users')  
    user_info = {} 
    user_info["name"] = post.get("name") 
    user_info["email"] = post.get("email") 
    user_info["password"] = post.get("password") 

    user_created = user_obj.create(cr, uid, vals_user, context) 

    return request.website.render("custom_module.custom_template") 

不過,我在這裏得到一個錯誤: 「你不能從這裏創建一個新用戶。要創建新用戶,請轉到配置面板'

任何人都可以提出我可能會出錯的地方嗎? 感謝您的幫助提前。

+0

我明白我要去哪裏錯了。把user_info ['login'] =真正解決了這個目的。但是,我不確定這是否是正確的做法。我仍然需要一些人來傳達一些理解。 – John 2014-12-09 11:57:22

+0

把你的追蹤放在這裏 – BomberMan 2014-12-09 12:48:57

+0

@BomberMan:我添加了類似問題的引用。你能建議一些步驟嗎? – 2015-11-05 22:26:11

回答

2

錯誤是指該代碼server/addons/mail/res_users.py

def create(self, cr, uid, data, context=None): 
    # create default alias same as the login 
    if not data.get('login', False): 
     raise osv.except_osv(_('Invalid Action!'), _('You may not create a user. To create new users, you should use the "Settings > Users" menu.')) 

所以,出現這種情況是因爲你沒有在參數設置dataloginlogin是res.users的用戶名字段

0

self.env [ 'res.users']創建({ 「名」: '名稱', 「電子郵件」: '電子郵件', 「登陸」: 'Email' })