From 622b95ab7ed2317dbfba762c44648d3dc066c956 Mon Sep 17 00:00:00 2001 From: Raphael Collet Date: Fri, 22 Apr 2011 16:41:22 +0200 Subject: [PATCH] [IMP] first sketch of wizard to create users from partner contacts bzr revid: rco@openerp.com-20110422144122-w0hq230zj8imva77 --- addons/portal/__init__.py | 1 + addons/portal/__openerp__.py | 2 +- addons/portal/wizard.py | 79 ++++++++++++++++++++++++++++++++++++ 3 files changed, 81 insertions(+), 1 deletion(-) create mode 100644 addons/portal/wizard.py diff --git a/addons/portal/__init__.py b/addons/portal/__init__.py index 0d6d510dbe6..5aea1cf958f 100644 --- a/addons/portal/__init__.py +++ b/addons/portal/__init__.py @@ -20,4 +20,5 @@ ############################################################################## import portal +import wizard diff --git a/addons/portal/__openerp__.py b/addons/portal/__openerp__.py index ca664c6b4d3..012403a1a52 100644 --- a/addons/portal/__openerp__.py +++ b/addons/portal/__openerp__.py @@ -38,7 +38,7 @@ module 'share'. """, 'website': 'http://www.openerp.com', 'demo_xml': [], - 'data': ['portal_view.xml'], + 'data': ['portal_view.xml', 'wizard_view.xml'], 'installable': True, 'certificate' : '', } diff --git a/addons/portal/wizard.py b/addons/portal/wizard.py new file mode 100644 index 00000000000..e325e407531 --- /dev/null +++ b/addons/portal/wizard.py @@ -0,0 +1,79 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# Copyright (C) 2004-2011 Tiny SPRL (). +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## + +from osv import osv, fields +from tools.translate import _ +from base.res.res_user import _lang_get + + + +class user_wizard(osv.osv_memory): + """ + A wizard to create a portal user from a res.partner.address. The use + case of the wizard is to provide access to a customer or supplier. + """ + _name = 'res.portal.user_wizard' + _description = 'Portal User Wizard' + + _columns = { + 'name': fields.char(size=64, required=True, + string='User Name', + help="The new user's real name"), + 'login': fields.char(size=64, required=True, + string='Login', + help="Used to log into the system"), + 'email': fields.char(size=64, required=True, + string='E-mail', + help="A welcome e-mail will be sent to the new user, " + "with the necessary information to connect to OpenERP"), + 'lang': fields.selection(_lang_get, required=True, + string='Language', + help="The language for the user's user interface"), + 'address_id': fields.many2one('res.partner.address', readonly=True, + string='Address'), + 'portal_id': fields.many2one('res.portal', required=True, + string='Portal', + help="The Portal that the new user must belong to"), + } + + def default_get(self, cr, uid, fields, context=None): + """ define the default name, login, email, address_id from the active + res.partner.address record """ + # get existing defaults + defs = super(user_wizard, self).default_get(cr, uid, fields, context) + + # override name, login, email, address_id, and lang + if context and ('active_id' in context): + address_obj = self.pool.get('res.partner.address') + address = address_obj.browse(cr, uid, context['active_id'], context) + defs['name'] = address.name + defs['login'] = address.email + defs['email'] = address.email + defs['address_id'] = address.id + if address.partner_id and address.partner_id.lang: + defs['lang'] = address.partner_id.lang + + return defs + +user_wizard() + + +