Ashvin Rathod (OpenERP) has proposed merging
lp:~openerp-dev/openobject-addons/trunk-portal_wizard-sbh-add_remove-ara into
lp:~openerp-dev/openobject-addons/trunk-portal_wizard-sbh.
Requested reviews:
OpenERP R&D Team (openerp-dev)
For more details, see:
https://code.launchpad.net/~openerp-dev/openobject-addons/trunk-portal_wizard-sbh-add_remove-ara/+merge/107978
Hello
Portal: Improve portal management wizard of partner.
Thanks,
ara
--
https://code.launchpad.net/~openerp-dev/openobject-addons/trunk-portal_wizard-sbh-add_remove-ara/+merge/107978
Your team OpenERP R&D Team is requested to review the proposed merge of
lp:~openerp-dev/openobject-addons/trunk-portal_wizard-sbh-add_remove-ara into
lp:~openerp-dev/openobject-addons/trunk-portal_wizard-sbh.
=== modified file 'portal/wizard/portal_wizard.py'
--- portal/wizard/portal_wizard.py 2012-05-07 18:13:46 +0000
+++ portal/wizard/portal_wizard.py 2012-05-30 14:04:34 +0000
@@ -91,11 +91,21 @@
def _default_user_ids(self, cr, uid, context):
""" determine default user_ids from the active records """
def create_user_from_address(address):
- return { # a user config based on a contact (address)
+ has_portal=False
+ portal_id = context.get('portal_id',False)
+ if portal_id:
+ portal_users = self.pool.get('res.portal').browse(cr,uid,portal_id).group_id.users
+ active_user = [u.login for u in portal_users]
+ if address.email in active_user:
+ has_portal = True
+
+ return { # a user config based on a contact (address)
'name': address.name,
'user_email': extract_email(address.email),
'lang': address.parent_id and address.parent_id.lang or 'en_US',
'partner_id': address.parent_id and address.parent_id.id,
+ 'has_portal_user':has_portal,
+ 'portal_id': context.get('portal_id', False)
}
user_ids = []
@@ -116,6 +126,14 @@
'user_ids': _default_user_ids
}
+ def onchange_portal_id(self, cr, uid, ids, portal_id=False, context=None):
+ if not portal_id:
+ return {'value': {}}
+ user_obj = self.pool.get('res.users')
+ context.update({'portal_id':portal_id})
+ user_list = self._default_user_ids(cr, uid, context=context)
+ return {'value': {'user_ids': user_list}}
+
def action_create(self, cr, uid, ids, context=None):
""" create new users in portal(s), and notify them by email """
# we copy the context to change the language for translating emails
@@ -133,25 +151,33 @@
portal_obj = self.pool.get('res.portal')
for wiz in self.browse(cr, uid, ids, context):
# determine existing users
- login_cond = [('login', 'in', [u.user_email for u in wiz.user_ids])]
- existing_uids = user_obj.search(cr, ROOT_UID, login_cond)
- existing_users = user_obj.browse(cr, ROOT_UID, existing_uids)
- existing_logins = [u.login for u in existing_users]
-
- # create new users in portal (skip existing logins)
- new_users_data = [ {
- 'name': u.name,
- 'login': u.user_email,
- 'password': random_password(),
- 'user_email': u.user_email,
- 'context_lang': u.lang,
- 'share': True,
- 'action_id': wiz.portal_id.home_action_id and wiz.portal_id.home_action_id.id or False,
- 'partner_id': u.partner_id and u.partner_id.id,
- } for u in wiz.user_ids if u.user_email not in existing_logins ]
- portal_obj.write(cr, ROOT_UID, [wiz.portal_id.id],
- {'users': [(0, 0, data) for data in new_users_data]}, context0)
-
+
+ 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]
+ new_users_data = []
+ if u.has_portal_user==False:
+ new_users_data = []
+ if u.user_email in existing_logins:
+ portal_uids = user_obj.search(cr, ROOT_UID, [('login','=',u.user_email),('partner_id', '=', u.partner_id.id)])
+ user_obj.unlink(cr,uid,portal_uids)
+ else:
+ if u.user_email not in existing_logins:
+ new_users_data.append({
+ 'name': u.name,
+ 'login': u.user_email,
+ 'password': random_password(),
+ 'user_email': u.user_email,
+ 'context_lang': u.lang,
+ 'share': True,
+ 'action_id': wiz.portal_id.home_action_id and wiz.portal_id.home_action_id.id or False,
+ 'partner_id': u.partner_id and u.partner_id.id,
+ } )
+ portal_obj.write(cr, ROOT_UID, [wiz.portal_id.id],
+ {'users': [(0, 0, data) for data in new_users_data]}, context0)
+
# send email to all users (translated in their language)
data = {
'company': user.company_id.name,
@@ -205,6 +231,7 @@
help="The language for the user's user interface"),
'partner_id': fields.many2one('res.partner',
string='Partner'),
+ 'has_portal_user':fields.boolean('Has portal access')
}
def _check_email(self, cr, uid, ids):
=== modified file 'portal/wizard/portal_wizard_view.xml'
--- portal/wizard/portal_wizard_view.xml 2012-03-26 10:41:23 +0000
+++ portal/wizard/portal_wizard_view.xml 2012-05-30 14:04:34 +0000
@@ -17,7 +17,7 @@
<field name="type">form</field>
<field name="arch" type="xml">
<form string="Add Portal Access">
- <field name="portal_id" widget="selection"/>
+ <field name="portal_id" widget="selection" on_change="onchange_portal_id(portal_id,context)"/>
<newline/>
<notebook colspan="4">
<page string="Users">
@@ -30,7 +30,7 @@
</notebook>
<label colspan="2"/>
<button string="Cancel" special="cancel" icon="gtk-cancel"/>
- <button string="Send Invitations"
+ <button string="Apply and Send Invitations"
name="action_create" type="object" icon="gtk-ok"/>
</form>
</field>
@@ -48,6 +48,7 @@
<field name="name"/>
<field name="user_email"/>
<field name="partner_id"/>
+ <field name="has_portal_user"/>
</tree>
</field>
</record>
_______________________________________________
Mailing list: https://launchpad.net/~openerp-dev-gtk
Post to : [email protected]
Unsubscribe : https://launchpad.net/~openerp-dev-gtk
More help : https://help.launchpad.net/ListHelp