From 95bcedf3b5132c14fac93ae6c0dab4d86c25fee5 Mon Sep 17 00:00:00 2001 From: "ara@tinyerp.com" <> Date: Fri, 8 Jun 2012 16:11:31 +0530 Subject: [IMP] improve code bzr revid: ara@tinyerp.com-20120608104131-w86kk0drvf3x1o2x --- addons/portal/wizard/portal_wizard.py | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/addons/portal/wizard/portal_wizard.py b/addons/portal/wizard/portal_wizard.py index 0f13a8cefbc..ed1baeb513a 100644 --- a/addons/portal/wizard/portal_wizard.py +++ b/addons/portal/wizard/portal_wizard.py @@ -179,7 +179,7 @@ class wizard(osv.osv_memory): # determine existing users portal_user=[user.id for user in wiz.portal_id.group_id.users] add_users=[] - removeuser=[] + remove_users=[] new_users_data = [] for u in wiz.user_ids: login_cond = [('login', 'in', [u.user_email])] @@ -189,7 +189,7 @@ class wizard(osv.osv_memory): if existing_uids and existing_uids[0] not in portal_user or existing_uids and u.has_portal_user: add_users.append(existing_uids[0]) if existing_uids and u.has_portal_user==False and existing_uids[0] in portal_user: - removeuser.append(existing_uids[0]) + remove_users.append(existing_uids[0]) if u.user_email not in existing_logins: new_users_data.append({ 'name': u.name, @@ -206,24 +206,21 @@ class wizard(osv.osv_memory): portal_obj.write(cr, ROOT_UID, [wiz.portal_id.id], {'users': [(0, 0, data)]}, context0) - created_user = user_obj.search(cr, ROOT_UID, [('user_email','=', data['login'])]) + created_user = user_obj.search(cr, ROOT_UID, [('user_email','=', data['login']),('partner_id','=', data['partner_id'])]) add_users.append(created_user[0]) - - + + #add the user relationship in portal. if add_users and add_users not in portal_user: portal_obj.write(cr, ROOT_UID, [wiz.portal_id.id], {'users': [(6, 0, add_users)]}, context0) #delete the user relationship from portal. - if removeuser: - portal_obj.write(cr, ROOT_UID, [wiz.portal_id.id], - {'users': [(3, user_data) for user_data in removeuser]}, context0) + portal_obj.write(cr, ROOT_UID, [wiz.portal_id.id], + {'users': [(3, user_data) for user_data in remove_users]}, context0) #unlink res user when portal user not in any portal. all_portal_user = self.get_all_portal_user(cr) - for data in removeuser: - if data not in all_portal_user: - user_obj.unlink(cr, ROOT_UID, [data]) + user_obj.unlink(cr, ROOT_UID, [remove_user for remove_user in remove_users if remove_user not in all_portal_user]) data = { 'company': user.company_id.name, -- cgit v1.2.3 From 92f4966a6a81c8e611fcb4c861898c9d69f2f872 Mon Sep 17 00:00:00 2001 From: "ara@tinyerp.com" <> Date: Mon, 11 Jun 2012 10:43:06 +0530 Subject: [IMP] send mail for new created user in portal bzr revid: ara@tinyerp.com-20120611051306-5lbbh93dneszar2l --- addons/portal/wizard/portal_wizard.py | 36 ++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/addons/portal/wizard/portal_wizard.py b/addons/portal/wizard/portal_wizard.py index ed1baeb513a..a2d0cb5fbc0 100644 --- a/addons/portal/wizard/portal_wizard.py +++ b/addons/portal/wizard/portal_wizard.py @@ -177,18 +177,20 @@ class wizard(osv.osv_memory): portal_obj = self.pool.get('res.portal') for wiz in self.browse(cr, uid, ids, context): # determine existing users - portal_user=[user.id for user in wiz.portal_id.group_id.users] + portal_users=[portal_user.id for portal_user in wiz.portal_id.group_id.users] add_users=[] remove_users=[] new_users_data = [] + login_conds = [] for u in wiz.user_ids: login_cond = [('login', 'in', [u.user_email])] existing_uids = user_obj.search(cr, ROOT_UID, login_cond) existing_users = user_obj.browse(cr, ROOT_UID, existing_uids) - existing_logins = [user.login for user in existing_users] - if existing_uids and existing_uids[0] not in portal_user or existing_uids and u.has_portal_user: + existing_logins = [existing_login.login for existing_login in existing_users] + if existing_uids and existing_uids[0] not in portal_users or existing_uids and u.has_portal_user: + login_conds.append(login_cond[0]) add_users.append(existing_uids[0]) - if existing_uids and u.has_portal_user==False and existing_uids[0] in portal_user: + if existing_uids and u.has_portal_user==False and existing_uids[0] in portal_users: remove_users.append(existing_uids[0]) if u.user_email not in existing_logins: new_users_data.append({ @@ -202,18 +204,18 @@ class wizard(osv.osv_memory): 'partner_id': u.partner_id and u.partner_id.id, } ) - for data in new_users_data: + for new_user_data in new_users_data: portal_obj.write(cr, ROOT_UID, [wiz.portal_id.id], - {'users': [(0, 0, data)]}, context0) + {'users': [(0, 0, new_user_data)]}, context0) - created_user = user_obj.search(cr, ROOT_UID, [('user_email','=', data['login']),('partner_id','=', data['partner_id'])]) + created_user = user_obj.search(cr, ROOT_UID, [('user_email','=', new_user_data['login']),('partner_id','=', new_user_data['partner_id'])]) add_users.append(created_user[0]) #add the user relationship in portal. - if add_users and add_users not in portal_user: + if add_users and add_users not in portal_users: portal_obj.write(cr, ROOT_UID, [wiz.portal_id.id], {'users': [(6, 0, add_users)]}, context0) - + #delete the user relationship from portal. portal_obj.write(cr, ROOT_UID, [wiz.portal_id.id], {'users': [(3, user_data) for user_data in remove_users]}, context0) @@ -228,9 +230,14 @@ class wizard(osv.osv_memory): 'url': wiz.portal_id.url or _("(missing url)"), 'db': cr.dbname, } + dest_uids = [] + dest_users = [] mail_message_obj = self.pool.get('mail.message') - dest_uids = user_obj.search(cr, ROOT_UID, login_cond) - dest_users = user_obj.browse(cr, ROOT_UID, dest_uids) + for login_cond in login_conds: + dest_uids.append(user_obj.search(cr, ROOT_UID, [login_cond])[0]) + for dest_uid in dest_uids: + dest_users.append(user_obj.browse(cr, ROOT_UID, dest_uid)) + for dest_user in dest_users: context['lang'] = dest_user.context_lang data['login'] = dest_user.login @@ -250,8 +257,6 @@ class wizard(osv.osv_memory): wizard() - - class wizard_user(osv.osv_memory): """ A model to configure users in the portal wizard. @@ -293,7 +298,4 @@ class wizard_user(osv.osv_memory): wizard_user() - - - -# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: +# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: \ No newline at end of file -- cgit v1.2.3 From 779c8587760f4a51f94fa5a64a2062c20fb5f604 Mon Sep 17 00:00:00 2001 From: "ara@tinyerp.com" <> Date: Mon, 11 Jun 2012 11:37:46 +0530 Subject: [IMP] imprpve code bzr revid: ara@tinyerp.com-20120611060746-rwtf3o7qytwcjkty --- addons/portal/wizard/portal_wizard.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/addons/portal/wizard/portal_wizard.py b/addons/portal/wizard/portal_wizard.py index a2d0cb5fbc0..7abbcfbec50 100644 --- a/addons/portal/wizard/portal_wizard.py +++ b/addons/portal/wizard/portal_wizard.py @@ -188,7 +188,6 @@ class wizard(osv.osv_memory): existing_users = user_obj.browse(cr, ROOT_UID, existing_uids) existing_logins = [existing_login.login for existing_login in existing_users] if existing_uids and existing_uids[0] not in portal_users or existing_uids and u.has_portal_user: - login_conds.append(login_cond[0]) add_users.append(existing_uids[0]) if existing_uids and u.has_portal_user==False and existing_uids[0] in portal_users: remove_users.append(existing_uids[0]) @@ -213,6 +212,7 @@ class wizard(osv.osv_memory): #add the user relationship in portal. if add_users and add_users not in portal_users: + login_conds.append(login_cond[0]) portal_obj.write(cr, ROOT_UID, [wiz.portal_id.id], {'users': [(6, 0, add_users)]}, context0) @@ -230,12 +230,10 @@ class wizard(osv.osv_memory): 'url': wiz.portal_id.url or _("(missing url)"), 'db': cr.dbname, } - dest_uids = [] - dest_users = [] + mail_message_obj = self.pool.get('mail.message') - for login_cond in login_conds: - dest_uids.append(user_obj.search(cr, ROOT_UID, [login_cond])[0]) - for dest_uid in dest_uids: + dest_users = [] + for dest_uid in add_users: dest_users.append(user_obj.browse(cr, ROOT_UID, dest_uid)) for dest_user in dest_users: -- cgit v1.2.3 From ef8f85f313bd2778587f8ae6477c83b83baecaad Mon Sep 17 00:00:00 2001 From: "ara@tinyerp.com" <> Date: Tue, 12 Jun 2012 16:30:57 +0530 Subject: [IMP] improve code bzr revid: ara@tinyerp.com-20120612110057-l8i0u1kyo3p389my --- addons/portal/wizard/portal_wizard.py | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/addons/portal/wizard/portal_wizard.py b/addons/portal/wizard/portal_wizard.py index 7abbcfbec50..4dadb88ba57 100644 --- a/addons/portal/wizard/portal_wizard.py +++ b/addons/portal/wizard/portal_wizard.py @@ -35,7 +35,7 @@ from base.res.res_users import _lang_get WELCOME_EMAIL_SUBJECT = _("Your OpenERP account at %(company)s") WELCOME_EMAIL_BODY = _("""Dear %(name)s, -You have been created an OpenERP account at %(url)s. +You have been created an OpenERP account of %(portal)s at %(url)s. Your login account data is: Database: %(db)s @@ -116,8 +116,8 @@ class wizard(osv.osv_memory): # add one user per contact, or one user if no contact if p.child_ids: user_ids.extend(map(create_user_from_address, p.child_ids)) - else: - user_ids.append({'lang': p.lang or 'en_US', 'parent_id': p.id}) +# else: +# user_ids.append({'lang': p.lang or 'en_US', 'name': p.name,'user_email':p.user_email, 'parent_id': p.id}) return user_ids @@ -140,8 +140,7 @@ class wizard(osv.osv_memory): user_obj = self.pool.get('res.users') context.update({'portal_id':portal_id}) user_list = self._default_user_ids(cr, uid, context=context) - - contact_user = [u['user_email'] for u in user_list] + contact_user = [u['user_email'] for u in user_list if u.get('user_email', False)] #add active portal user to portal wizard portal_users = self.pool.get('res.portal').browse(cr,uid,portal_id).group_id.users @@ -181,7 +180,6 @@ class wizard(osv.osv_memory): add_users=[] remove_users=[] new_users_data = [] - login_conds = [] for u in wiz.user_ids: login_cond = [('login', 'in', [u.user_email])] existing_uids = user_obj.search(cr, ROOT_UID, login_cond) @@ -212,7 +210,6 @@ class wizard(osv.osv_memory): #add the user relationship in portal. if add_users and add_users not in portal_users: - login_conds.append(login_cond[0]) portal_obj.write(cr, ROOT_UID, [wiz.portal_id.id], {'users': [(6, 0, add_users)]}, context0) @@ -225,6 +222,7 @@ class wizard(osv.osv_memory): user_obj.unlink(cr, ROOT_UID, [remove_user for remove_user in remove_users if remove_user not in all_portal_user]) data = { + 'portal':wiz.portal_id.name, 'company': user.company_id.name, 'message': wiz.message or "", 'url': wiz.portal_id.url or _("(missing url)"), @@ -234,7 +232,8 @@ class wizard(osv.osv_memory): mail_message_obj = self.pool.get('mail.message') dest_users = [] for dest_uid in add_users: - dest_users.append(user_obj.browse(cr, ROOT_UID, dest_uid)) + if dest_uid not in portal_users: + dest_users.append(user_obj.browse(cr, ROOT_UID, dest_uid)) for dest_user in dest_users: context['lang'] = dest_user.context_lang -- cgit v1.2.3