From 22c6b69b505b6d3427f63743c8c574a58d3a5029 Mon Sep 17 00:00:00 2001 From: Christophe Matthieu Date: Thu, 16 May 2013 11:16:00 +0200 Subject: [PATCH 01/11] [FIX] portal: "Portal Access Managment" can't create or edit portal access for a contact when they are already an user with the same login. The wizard don't display all the list of contacts related to the selection. The wrong contact must be replace by the contact who have the login equal to the contact email. Get all child contacts and do not filtered by active user. bzr revid: chm@openerp.com-20130516091600-20ukr9vbe5qa3lv8 --- addons/portal/wizard/portal_wizard.py | 33 +++++++++++++++++++++------ 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/addons/portal/wizard/portal_wizard.py b/addons/portal/wizard/portal_wizard.py index e3047cd5edb..5ea4edd8308 100644 --- a/addons/portal/wizard/portal_wizard.py +++ b/addons/portal/wizard/portal_wizard.py @@ -83,13 +83,33 @@ class wizard(osv.osv_memory): def onchange_portal_id(self, cr, uid, ids, portal_id, context=None): # for each partner, determine corresponding portal.wizard.user records + context = dict(context or {}, active_test=False) res_partner = self.pool.get('res.partner') + res_users = self.pool.get('res.users') partner_ids = context and context.get('active_ids') or [] contact_ids = set() user_changes = [] + emails_used = [] + partners_used = [] for partner in res_partner.browse(cr, SUPERUSER_ID, partner_ids, context): - for contact in (partner.child_ids or [partner]): + stack = [partner] + while stack: + contact = stack.pop(0) + if contact.id in partners_used: + continue + partners_used.append(contact.id) + stack.extend(contact.child_ids) + if contact.email in emails_used: + continue # make sure that each contact appears at most once in the list + if not contact.user_id: + # search user with the same login/email + domain = [('partner_id', '!=', contact.id), ('login', '=', contact.email)] + user_ids = res_users.search(cr, uid, domain, context=context) + user = user_ids and res_users.browse(cr, uid, user_ids[0], context=context) or False + if user: + contact = user.partner_id + stack.extend(contact.child_ids) if contact.id not in contact_ids: contact_ids.add(contact.id) in_portal = False @@ -100,6 +120,7 @@ class wizard(osv.osv_memory): 'email': contact.email, 'in_portal': in_portal, })) + emails_used.append(contact.email) return {'value': {'user_ids': user_changes}} def action_apply(self, cr, uid, ids, context=None): @@ -158,13 +179,11 @@ class wizard_user(osv.osv_memory): @param wizard_user: browse record of model portal.wizard.user @return: browse record of model res.users """ - if wizard_user.partner_id.user_ids: - return wizard_user.partner_id.user_ids[0] - # the user may be inactive, search for it + context = dict(context or {}, active_test=False) res_users = self.pool.get('res.users') - domain = [('partner_id', '=', wizard_user.partner_id.id), ('active', '=', False)] - user_ids = res_users.search(cr, uid, domain) - return user_ids and res_users.browse(cr, uid, user_ids[0], context) or False + domain = [('partner_id', '=', wizard_user.partner_id.id)] + user_ids = res_users.search(cr, uid, domain, context=context) + return user_ids and res_users.browse(cr, uid, user_ids[0], context=context) or False def _create_user(self, cr, uid, wizard_user, context=None): """ create a new user for wizard_user.partner_id From 1b53e9114f0f44a9883221a76579c6bb21596948 Mon Sep 17 00:00:00 2001 From: Christophe Matthieu Date: Thu, 16 May 2013 14:12:51 +0200 Subject: [PATCH 02/11] [IMP] Portal Access Managment: don't search by user bzr revid: chm@openerp.com-20130516121251-lbddg5wot6el7emx --- addons/portal/wizard/portal_wizard.py | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/addons/portal/wizard/portal_wizard.py b/addons/portal/wizard/portal_wizard.py index 5ea4edd8308..8425c752e50 100644 --- a/addons/portal/wizard/portal_wizard.py +++ b/addons/portal/wizard/portal_wizard.py @@ -83,33 +83,16 @@ class wizard(osv.osv_memory): def onchange_portal_id(self, cr, uid, ids, portal_id, context=None): # for each partner, determine corresponding portal.wizard.user records - context = dict(context or {}, active_test=False) res_partner = self.pool.get('res.partner') res_users = self.pool.get('res.users') partner_ids = context and context.get('active_ids') or [] contact_ids = set() user_changes = [] - emails_used = [] - partners_used = [] for partner in res_partner.browse(cr, SUPERUSER_ID, partner_ids, context): stack = [partner] while stack: contact = stack.pop(0) - if contact.id in partners_used: - continue - partners_used.append(contact.id) stack.extend(contact.child_ids) - if contact.email in emails_used: - continue - # make sure that each contact appears at most once in the list - if not contact.user_id: - # search user with the same login/email - domain = [('partner_id', '!=', contact.id), ('login', '=', contact.email)] - user_ids = res_users.search(cr, uid, domain, context=context) - user = user_ids and res_users.browse(cr, uid, user_ids[0], context=context) or False - if user: - contact = user.partner_id - stack.extend(contact.child_ids) if contact.id not in contact_ids: contact_ids.add(contact.id) in_portal = False @@ -120,7 +103,6 @@ class wizard(osv.osv_memory): 'email': contact.email, 'in_portal': in_portal, })) - emails_used.append(contact.email) return {'value': {'user_ids': user_changes}} def action_apply(self, cr, uid, ids, context=None): From f18b1d73749ed4eb5a75cb1d157cad3d464924ed Mon Sep 17 00:00:00 2001 From: Christophe Matthieu Date: Thu, 16 May 2013 14:39:44 +0200 Subject: [PATCH 03/11] [IMP] portal: remove code not used bzr revid: chm@openerp.com-20130516123944-y1nwv5582mxmsvt7 --- addons/portal/wizard/portal_wizard.py | 1 - 1 file changed, 1 deletion(-) diff --git a/addons/portal/wizard/portal_wizard.py b/addons/portal/wizard/portal_wizard.py index 8425c752e50..8e0c952c398 100644 --- a/addons/portal/wizard/portal_wizard.py +++ b/addons/portal/wizard/portal_wizard.py @@ -84,7 +84,6 @@ class wizard(osv.osv_memory): def onchange_portal_id(self, cr, uid, ids, portal_id, context=None): # for each partner, determine corresponding portal.wizard.user records res_partner = self.pool.get('res.partner') - res_users = self.pool.get('res.users') partner_ids = context and context.get('active_ids') or [] contact_ids = set() user_changes = [] From 47998aee0d02db613f2c79b359c5d7c56255374e Mon Sep 17 00:00:00 2001 From: Christophe Matthieu Date: Fri, 17 May 2013 12:25:08 +0200 Subject: [PATCH 04/11] [IMP] portal managment: check and raise complete errors (empty email, double, existing user) bzr revid: chm@openerp.com-20130517102508-7qrboloxd2wow2rs --- addons/portal/wizard/portal_wizard.py | 44 +++++++++++++++++++++++---- 1 file changed, 38 insertions(+), 6 deletions(-) diff --git a/addons/portal/wizard/portal_wizard.py b/addons/portal/wizard/portal_wizard.py index 8e0c952c398..9abb6664adf 100644 --- a/addons/portal/wizard/portal_wizard.py +++ b/addons/portal/wizard/portal_wizard.py @@ -88,10 +88,8 @@ class wizard(osv.osv_memory): contact_ids = set() user_changes = [] for partner in res_partner.browse(cr, SUPERUSER_ID, partner_ids, context): - stack = [partner] - while stack: - contact = stack.pop(0) - stack.extend(contact.child_ids) + for contact in (partner.child_ids or [partner]): + # make sure that each contact appears at most once in the list if contact.id not in contact_ids: contact_ids.add(contact.id) in_portal = False @@ -133,7 +131,41 @@ class wizard_user(osv.osv_memory): return id def action_apply(self, cr, uid, ids, context=None): - for wizard_user in self.browse(cr, SUPERUSER_ID, ids, context): + res_users = self.pool.get('res.users') + wizards = self.browse(cr, SUPERUSER_ID, ids, context) + emails = [] + error_empty = [] + error_emails = [] + error_user = [] + ctx = dict(context or {}, active_test=False) + for wizard_user in wizards: + email = wizard_user.partner_id.email + if not email: + error_empty.append(wizard_user.partner_id) + elif email in emails: + error_emails.append(email) + user = res_users.search(cr, SUPERUSER_ID, [('partner_id', '!=', wizard_user.partner_id.id), ('login', '=', email)], context=ctx) + if user: + error_user.append((wizard_user.partner_id, res_users.browse(cr, SUPERUSER_ID, user[0], context=ctx).partner_id,)) + emails.append(email) + + error_msg = "" + if error_empty: + error_msg = _("%sSome contacts don't have email address: \n%r") % (error_msg, map(lambda p: p.name_get()[0], error_empty)) + if error_emails: + if error_msg: + error_msg += '\n\n' + error_msg = _("%sYou have more than one email address equal to: \n%r") % (error_msg, error_emails) + if error_user: + if error_msg: + error_msg += '\n\n' + error_msg = _("%sSome contact have the same email address than an other contact who have already an user's access: \n%s") % \ + (error_msg, [(p_u[0].id, p_u[0].name, '=>', p_u[1].id, p_u[1].name) for p_u in error_user]) + if error_msg: + raise osv.except_osv(_('Contacts Error'), error_msg) + + for wizard_user in wizards: + print wizard_user portal = wizard_user.wizard_id.portal_id user = self._retrieve_user(cr, SUPERUSER_ID, wizard_user, context) if wizard_user.in_portal: @@ -145,7 +177,7 @@ class wizard_user(osv.osv_memory): # prepare for the signup process user.partner_id.signup_prepare() wizard_user = self.browse(cr, SUPERUSER_ID, wizard_user.id, context) - self._send_email(cr, uid, wizard_user, context) + self._send_email(cr, uid, wizard_user, context) else: # remove the user (if it exists) from the portal group if user and (portal in user.groups_id): From 14308b8c92d3a9625eb303aa705f7d9ff59b1e73 Mon Sep 17 00:00:00 2001 From: Christophe Matthieu Date: Fri, 17 May 2013 12:47:54 +0200 Subject: [PATCH 05/11] [IMP] portal_crm: overwrite error message to portal managment bzr revid: chm@openerp.com-20130517104754-n13kq2cg3e1msta7 --- addons/portal_crm/__init__.py | 1 + addons/portal_crm/wizard/__init__.py | 25 ++++++++++++++ addons/portal_crm/wizard/portal_wizard.py | 41 +++++++++++++++++++++++ 3 files changed, 67 insertions(+) create mode 100644 addons/portal_crm/wizard/__init__.py create mode 100644 addons/portal_crm/wizard/portal_wizard.py diff --git a/addons/portal_crm/__init__.py b/addons/portal_crm/__init__.py index 92b3ac62321..cfd48eddc52 100644 --- a/addons/portal_crm/__init__.py +++ b/addons/portal_crm/__init__.py @@ -20,3 +20,4 @@ ############################################################################## import contact +import wizard diff --git a/addons/portal_crm/wizard/__init__.py b/addons/portal_crm/wizard/__init__.py new file mode 100644 index 00000000000..2fd59f43322 --- /dev/null +++ b/addons/portal_crm/wizard/__init__.py @@ -0,0 +1,25 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# Copyright (C) 2004-2011 OpenERP S.A (). +# +# 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 . +# +############################################################################## + +import portal_wizard + + +# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/addons/portal_crm/wizard/portal_wizard.py b/addons/portal_crm/wizard/portal_wizard.py new file mode 100644 index 00000000000..ff3b1562fb0 --- /dev/null +++ b/addons/portal_crm/wizard/portal_wizard.py @@ -0,0 +1,41 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# Copyright (C) 2004-2011 OpenERP S.A (). +# +# 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 . +# +############################################################################## + +import logging + +from openerp.osv import osv +from openerp.tools.translate import _ + +_logger = logging.getLogger(__name__) + +class wizard_user(osv.osv_memory): + _inherit = 'portal.wizard.user' + + def action_apply(self, cr, uid, ids, context=None): + try: + return super(wizard_user, self).action_apply(cr, uid, ids, context) + except osv.except_osv, e: + raise osv.except_osv(e[0], "%s\n\n%s" % (e[1], _("To resolve this error, you can:\ + Change and use an other contact's email adresse; \ + Select other contacts; \ + Use the partner merge action (more option of the contacts list) to merge the identical partners."))) + +# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: From f5f14d6a22fa34bbdb1c17eb3de136a9b287e47b Mon Sep 17 00:00:00 2001 From: Christophe Matthieu Date: Fri, 17 May 2013 17:41:16 +0200 Subject: [PATCH 06/11] [FIX] portal managment bzr revid: chm@openerp.com-20130517154116-wowkjjx40dzjbpvc --- addons/portal/wizard/portal_wizard.py | 42 ++++++++++++----------- addons/portal_crm/wizard/__init__.py | 5 +-- addons/portal_crm/wizard/portal_wizard.py | 12 +++---- 3 files changed, 31 insertions(+), 28 deletions(-) diff --git a/addons/portal/wizard/portal_wizard.py b/addons/portal/wizard/portal_wizard.py index 9abb6664adf..eb6aeac8864 100644 --- a/addons/portal/wizard/portal_wizard.py +++ b/addons/portal/wizard/portal_wizard.py @@ -139,33 +139,32 @@ class wizard_user(osv.osv_memory): error_user = [] ctx = dict(context or {}, active_test=False) for wizard_user in wizards: - email = wizard_user.partner_id.email - if not email: - error_empty.append(wizard_user.partner_id) - elif email in emails: - error_emails.append(email) - user = res_users.search(cr, SUPERUSER_ID, [('partner_id', '!=', wizard_user.partner_id.id), ('login', '=', email)], context=ctx) - if user: - error_user.append((wizard_user.partner_id, res_users.browse(cr, SUPERUSER_ID, user[0], context=ctx).partner_id,)) - emails.append(email) + if wizard_user.in_portal: + email = extract_email(wizard_user.partner_id.email) + if not email: + error_empty.append(wizard_user.partner_id) + elif email in emails: + error_emails.append(email) + user = res_users.search(cr, SUPERUSER_ID, [('partner_id', '!=', wizard_user.partner_id.id), ('login', '=', email)], context=ctx) + if user: + error_user.append((wizard_user.partner_id, res_users.browse(cr, SUPERUSER_ID, user[0], context=ctx).partner_id,)) + emails.append(email) - error_msg = "" + error_msg = [] if error_empty: - error_msg = _("%sSome contacts don't have email address: \n%r") % (error_msg, map(lambda p: p.name_get()[0], error_empty)) + error_msg.append("%s\n%r" % (_("Some contacts don't have valid email address: "), [p.display_name for p in error_empty])) if error_emails: - if error_msg: - error_msg += '\n\n' - error_msg = _("%sYou have more than one email address equal to: \n%r") % (error_msg, error_emails) + error_msg.append("%s\n%r" % (_("You have more than one email address equal to:"), error_emails)) if error_user: - if error_msg: - error_msg += '\n\n' - error_msg = _("%sSome contact have the same email address than an other contact who have already an user's access: \n%s") % \ - (error_msg, [(p_u[0].id, p_u[0].name, '=>', p_u[1].id, p_u[1].name) for p_u in error_user]) + error_msg.append("%s\n%s" % (_("Some contact have the same email address than an other contact who have already an user's access:"), + (error_msg, [(p_u[0].id, p_u[0].name, '=>', p_u[1].id, p_u[1].name) for p_u in error_user]))) if error_msg: - raise osv.except_osv(_('Contacts Error'), error_msg) + error_msg.append(_("To resolve this error, you can:\ + Change and use an other contact's email adresse; \ + Select other contacts; ")) + raise osv.except_osv(_('Contacts Error'), "\n\n".join(error_msg)) for wizard_user in wizards: - print wizard_user portal = wizard_user.wizard_id.portal_id user = self._retrieve_user(cr, SUPERUSER_ID, wizard_user, context) if wizard_user.in_portal: @@ -205,12 +204,15 @@ class wizard_user(osv.osv_memory): """ res_users = self.pool.get('res.users') create_context = dict(context or {}, noshortcut=True) # to prevent shortcut creation + print extract_email(wizard_user.email) values = { + 'email': extract_email(wizard_user.email), 'login': extract_email(wizard_user.email), 'partner_id': wizard_user.partner_id.id, 'groups_id': [(6, 0, [])], 'share': True, } + print values user_id = res_users.create(cr, uid, values, context=create_context) return res_users.browse(cr, uid, user_id, context) diff --git a/addons/portal_crm/wizard/__init__.py b/addons/portal_crm/wizard/__init__.py index 2fd59f43322..31287ddc938 100644 --- a/addons/portal_crm/wizard/__init__.py +++ b/addons/portal_crm/wizard/__init__.py @@ -1,8 +1,8 @@ # -*- coding: utf-8 -*- ############################################################################## # -# OpenERP, Open Source Management Solution -# Copyright (C) 2004-2011 OpenERP S.A (). +# OpenERP, Open Source Business Applications +# Copyright (c) 2012-TODAY OpenERP S.A. # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as @@ -19,6 +19,7 @@ # ############################################################################## + import portal_wizard diff --git a/addons/portal_crm/wizard/portal_wizard.py b/addons/portal_crm/wizard/portal_wizard.py index ff3b1562fb0..7c43310dce7 100644 --- a/addons/portal_crm/wizard/portal_wizard.py +++ b/addons/portal_crm/wizard/portal_wizard.py @@ -1,8 +1,8 @@ # -*- coding: utf-8 -*- ############################################################################## # -# OpenERP, Open Source Management Solution -# Copyright (C) 2004-2011 OpenERP S.A (). +# OpenERP, Open Source Business Applications +# Copyright (c) 2012-TODAY OpenERP S.A. # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as @@ -33,9 +33,9 @@ class wizard_user(osv.osv_memory): try: return super(wizard_user, self).action_apply(cr, uid, ids, context) except osv.except_osv, e: - raise osv.except_osv(e[0], "%s\n\n%s" % (e[1], _("To resolve this error, you can:\ - Change and use an other contact's email adresse; \ - Select other contacts; \ - Use the partner merge action (more option of the contacts list) to merge the identical partners."))) + if "Contact" in e[0]: + raise osv.except_osv(e[0], "%s %s" % (e[1], _("Use the partner merge action (more option of the contacts list) to merge the identical partners."))) + else: + raise e # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: From 98d829c8eed322db618232da6bccdfe2ebf77454 Mon Sep 17 00:00:00 2001 From: Christophe Matthieu Date: Fri, 17 May 2013 17:53:25 +0200 Subject: [PATCH 07/11] [FIX] portal managment: wizard email check bzr revid: chm@openerp.com-20130517155325-pmmlm29weerw0x0k --- addons/portal/wizard/portal_wizard.py | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/addons/portal/wizard/portal_wizard.py b/addons/portal/wizard/portal_wizard.py index eb6aeac8864..7665db34bc4 100644 --- a/addons/portal/wizard/portal_wizard.py +++ b/addons/portal/wizard/portal_wizard.py @@ -122,14 +122,6 @@ class wizard_user(osv.osv_memory): 'in_portal': fields.boolean('In Portal'), } - def create(self, cr, uid, values, context=None): - """ overridden to update the partner's email (if necessary) """ - id = super(wizard_user, self).create(cr, uid, values, context) - wuser = self.browse(cr, uid, id, context) - if wuser.partner_id.email != wuser.email: - wuser.partner_id.write({'email': wuser.email}) - return id - def action_apply(self, cr, uid, ids, context=None): res_users = self.pool.get('res.users') wizards = self.browse(cr, SUPERUSER_ID, ids, context) @@ -140,7 +132,7 @@ class wizard_user(osv.osv_memory): ctx = dict(context or {}, active_test=False) for wizard_user in wizards: if wizard_user.in_portal: - email = extract_email(wizard_user.partner_id.email) + email = extract_email(wizard_user.email) if not email: error_empty.append(wizard_user.partner_id) elif email in emails: @@ -204,7 +196,8 @@ class wizard_user(osv.osv_memory): """ res_users = self.pool.get('res.users') create_context = dict(context or {}, noshortcut=True) # to prevent shortcut creation - print extract_email(wizard_user.email) + if wizard_user.partner_id.email != wizard_user.email: + wizard_user.partner_id.write({'email': wizard_user.email}) values = { 'email': extract_email(wizard_user.email), 'login': extract_email(wizard_user.email), @@ -212,7 +205,6 @@ class wizard_user(osv.osv_memory): 'groups_id': [(6, 0, [])], 'share': True, } - print values user_id = res_users.create(cr, uid, values, context=create_context) return res_users.browse(cr, uid, user_id, context) @@ -242,7 +234,7 @@ class wizard_user(osv.osv_memory): mail_mail = self.pool.get('mail.mail') mail_values = { 'email_from': this_user.email, - 'email_to': user.email, + 'email_to': wizard_user.email, 'subject': _(WELCOME_EMAIL_SUBJECT) % data, 'body_html': '
%s
' % (_(WELCOME_EMAIL_BODY) % data), 'state': 'outgoing', From 15f8a6519f55615e065226ab79f9c886b000e00b Mon Sep 17 00:00:00 2001 From: Christophe Matthieu Date: Fri, 17 May 2013 17:56:41 +0200 Subject: [PATCH 08/11] [FIX] portal managment: send mail to user email bzr revid: chm@openerp.com-20130517155641-xazwkmedy56b9jv0 --- addons/portal/wizard/portal_wizard.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/portal/wizard/portal_wizard.py b/addons/portal/wizard/portal_wizard.py index 7665db34bc4..9cb5e6a4f85 100644 --- a/addons/portal/wizard/portal_wizard.py +++ b/addons/portal/wizard/portal_wizard.py @@ -234,7 +234,7 @@ class wizard_user(osv.osv_memory): mail_mail = self.pool.get('mail.mail') mail_values = { 'email_from': this_user.email, - 'email_to': wizard_user.email, + 'email_to': user.email, 'subject': _(WELCOME_EMAIL_SUBJECT) % data, 'body_html': '
%s
' % (_(WELCOME_EMAIL_BODY) % data), 'state': 'outgoing', From 854671b9300e0010ed05ed87a1f147f6ebb2e93e Mon Sep 17 00:00:00 2001 From: Christophe Matthieu Date: Fri, 17 May 2013 17:59:33 +0200 Subject: [PATCH 09/11] [FIX] portal managment: wizard refresh and write email bzr revid: chm@openerp.com-20130517155933-e2tc2u9ns9m9jdh7 --- addons/portal/wizard/portal_wizard.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/addons/portal/wizard/portal_wizard.py b/addons/portal/wizard/portal_wizard.py index 9cb5e6a4f85..b88d0edcec0 100644 --- a/addons/portal/wizard/portal_wizard.py +++ b/addons/portal/wizard/portal_wizard.py @@ -167,7 +167,9 @@ class wizard_user(osv.osv_memory): user.write({'active': True, 'groups_id': [(4, portal.id)]}) # prepare for the signup process user.partner_id.signup_prepare() - wizard_user = self.browse(cr, SUPERUSER_ID, wizard_user.id, context) + if wizard_user.partner_id.email != wizard_user.email: + wizard_user.partner_id.write({'email': wizard_user.email}) + wizard_user.refresh() self._send_email(cr, uid, wizard_user, context) else: # remove the user (if it exists) from the portal group @@ -196,8 +198,6 @@ class wizard_user(osv.osv_memory): """ res_users = self.pool.get('res.users') create_context = dict(context or {}, noshortcut=True) # to prevent shortcut creation - if wizard_user.partner_id.email != wizard_user.email: - wizard_user.partner_id.write({'email': wizard_user.email}) values = { 'email': extract_email(wizard_user.email), 'login': extract_email(wizard_user.email), From 41c10c5de71ec1fc5e7952ababf26ce62fab68d9 Mon Sep 17 00:00:00 2001 From: Christophe Matthieu Date: Fri, 17 May 2013 18:01:00 +0200 Subject: [PATCH 10/11] [IMP] portal managment: write email all time bzr revid: chm@openerp.com-20130517160100-oos81x3x3994po6b --- addons/portal/wizard/portal_wizard.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/addons/portal/wizard/portal_wizard.py b/addons/portal/wizard/portal_wizard.py index b88d0edcec0..4c513d0ec2f 100644 --- a/addons/portal/wizard/portal_wizard.py +++ b/addons/portal/wizard/portal_wizard.py @@ -159,6 +159,8 @@ class wizard_user(osv.osv_memory): for wizard_user in wizards: portal = wizard_user.wizard_id.portal_id user = self._retrieve_user(cr, SUPERUSER_ID, wizard_user, context) + if wizard_user.partner_id.email != wizard_user.email: + wizard_user.partner_id.write({'email': wizard_user.email}) if wizard_user.in_portal: # create a user if necessary, and make sure it is in the portal group if not user: @@ -167,8 +169,6 @@ class wizard_user(osv.osv_memory): user.write({'active': True, 'groups_id': [(4, portal.id)]}) # prepare for the signup process user.partner_id.signup_prepare() - if wizard_user.partner_id.email != wizard_user.email: - wizard_user.partner_id.write({'email': wizard_user.email}) wizard_user.refresh() self._send_email(cr, uid, wizard_user, context) else: From 48f5b7b4801ca2df2ac52fb5641a527ecf7d1f07 Mon Sep 17 00:00:00 2001 From: Christophe Matthieu Date: Tue, 21 May 2013 16:49:41 +0200 Subject: [PATCH 11/11] [IMP] portal managment: add get_error_messages method bzr revid: chm@openerp.com-20130521144941-a0pfm3ulx7wr5cs1 --- addons/portal/wizard/portal_wizard.py | 20 ++++++++++++-------- addons/portal_crm/wizard/portal_wizard.py | 14 ++++++-------- 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/addons/portal/wizard/portal_wizard.py b/addons/portal/wizard/portal_wizard.py index 4c513d0ec2f..dd07f85d3a5 100644 --- a/addons/portal/wizard/portal_wizard.py +++ b/addons/portal/wizard/portal_wizard.py @@ -116,21 +116,20 @@ class wizard_user(osv.osv_memory): _description = 'Portal User Config' _columns = { - 'wizard_id': fields.many2one('portal.wizard', string='Wizard', required=True), + 'wizard_id': fields.many2one('portal.wizard', string='Wizard', required=True, ondelete='cascade'), 'partner_id': fields.many2one('res.partner', string='Contact', required=True, readonly=True), 'email': fields.char(size=240, string='Email'), 'in_portal': fields.boolean('In Portal'), } - def action_apply(self, cr, uid, ids, context=None): + def get_error_messages(self, cr, uid, ids, context=None): res_users = self.pool.get('res.users') - wizards = self.browse(cr, SUPERUSER_ID, ids, context) emails = [] error_empty = [] error_emails = [] error_user = [] ctx = dict(context or {}, active_test=False) - for wizard_user in wizards: + for wizard_user in self.browse(cr, SUPERUSER_ID, ids, context): if wizard_user.in_portal: email = extract_email(wizard_user.email) if not email: @@ -144,19 +143,24 @@ class wizard_user(osv.osv_memory): error_msg = [] if error_empty: - error_msg.append("%s\n%r" % (_("Some contacts don't have valid email address: "), [p.display_name for p in error_empty])) + error_msg.append("%s\n%s" % (_("Some contacts don't have valid email address: "), '\n'.join([p.display_name for p in error_empty]))) if error_emails: - error_msg.append("%s\n%r" % (_("You have more than one email address equal to:"), error_emails)) + error_msg.append("%s\n%s" % (_("You have more than one email address equal to:"), '\n'.join(error_emails))) if error_user: error_msg.append("%s\n%s" % (_("Some contact have the same email address than an other contact who have already an user's access:"), - (error_msg, [(p_u[0].id, p_u[0].name, '=>', p_u[1].id, p_u[1].name) for p_u in error_user]))) + '\n'.join([(p_u[0].id, p_u[0].name, '=>', p_u[1].id, p_u[1].name) for p_u in error_user]))) if error_msg: error_msg.append(_("To resolve this error, you can:\ Change and use an other contact's email adresse; \ Select other contacts; ")) + return error_msg + + def action_apply(self, cr, uid, ids, context=None): + error_msg = self.get_error_messages(cr, uid, ids, context=context) + if error_msg: raise osv.except_osv(_('Contacts Error'), "\n\n".join(error_msg)) - for wizard_user in wizards: + for wizard_user in self.browse(cr, SUPERUSER_ID, ids, context): portal = wizard_user.wizard_id.portal_id user = self._retrieve_user(cr, SUPERUSER_ID, wizard_user, context) if wizard_user.partner_id.email != wizard_user.email: diff --git a/addons/portal_crm/wizard/portal_wizard.py b/addons/portal_crm/wizard/portal_wizard.py index 7c43310dce7..e74a975ee58 100644 --- a/addons/portal_crm/wizard/portal_wizard.py +++ b/addons/portal_crm/wizard/portal_wizard.py @@ -26,16 +26,14 @@ from openerp.tools.translate import _ _logger = logging.getLogger(__name__) + class wizard_user(osv.osv_memory): _inherit = 'portal.wizard.user' - def action_apply(self, cr, uid, ids, context=None): - try: - return super(wizard_user, self).action_apply(cr, uid, ids, context) - except osv.except_osv, e: - if "Contact" in e[0]: - raise osv.except_osv(e[0], "%s %s" % (e[1], _("Use the partner merge action (more option of the contacts list) to merge the identical partners."))) - else: - raise e + def get_error_messages(self, cr, uid, ids, context=None): + error_msg = super(wizard_user, self).get_error_messages(cr, uid, ids, context) + if error_msg: + error_msg[-1] = '%s %s' % (error_msg[-1], _("Use the partner merge action (more option of the contacts list) to merge the identical partners.")) + return error_msg # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: