From 7c6a7ff4ac3191813b3aaa222949a4c8aa430024 Mon Sep 17 00:00:00 2001 From: EliseDup Date: Wed, 14 Dec 2016 08:47:43 +0100 Subject: [PATCH] Bug Portal Access Management : only the contacts are displayed, not the partner itself ? --- beesdoo_base/wizard/__init__.py | 2 +- beesdoo_base/wizard/portal_wizard.py | 42 ++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 beesdoo_base/wizard/portal_wizard.py diff --git a/beesdoo_base/wizard/__init__.py b/beesdoo_base/wizard/__init__.py index ed4a740..5368e4a 100644 --- a/beesdoo_base/wizard/__init__.py +++ b/beesdoo_base/wizard/__init__.py @@ -1,2 +1,2 @@ -import member_card, partner +import member_card, partner, portal_wizard diff --git a/beesdoo_base/wizard/portal_wizard.py b/beesdoo_base/wizard/portal_wizard.py new file mode 100644 index 0000000..3a3430c --- /dev/null +++ b/beesdoo_base/wizard/portal_wizard.py @@ -0,0 +1,42 @@ +from openerp.osv import osv +from openerp import models, fields, api +from openerp import SUPERUSER_ID + +class BeesdooWizard(osv.osv_memory): + + _inherit = 'portal.wizard' + + 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') + partner_ids = context and context.get('active_ids') or [] + contact_ids = set() + user_changes = [] + for partner in res_partner.browse(cr, SUPERUSER_ID, partner_ids, context): + # Bug for BEESDOO : the partner itself did not appear in the list when he has contacts ? + # Is it a normal behaviour ? Here I have modified this function in order to first add the partner itself + # then all its contacts to the list + # make sure that each contact appears at most once in the list + if partner.id not in contact_ids: + contact_ids.add(partner.id) + in_portal = False + if partner.user_ids: + in_portal = portal_id in [g.id for g in partner.user_ids[0].groups_id] + user_changes.append((0, 0, { + 'partner_id': partner.id, + 'email': partner.email, + 'in_portal': in_portal, + })) + for contact in (partner.child_ids): + # 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 + if contact.user_ids: + in_portal = portal_id in [g.id for g in contact.user_ids[0].groups_id] + user_changes.append((0, 0, { + 'partner_id': contact.id, + 'email': contact.email, + 'in_portal': in_portal, + })) + return {'value': {'user_ids': user_changes}}