Thibault Francois
8 years ago
2 changed files with 45 additions and 49 deletions
@ -1,42 +1,26 @@ |
|||||
from openerp.osv import osv |
|
||||
from openerp import models, fields, api |
from openerp import models, fields, api |
||||
from openerp import SUPERUSER_ID |
from openerp import SUPERUSER_ID |
||||
|
|
||||
class BeesdooWizard(osv.osv_memory): |
|
||||
|
class BeesdooWizard(models.Model): |
||||
|
|
||||
_inherit = 'portal.wizard' |
_inherit = 'portal.wizard' |
||||
|
|
||||
def onchange_portal_id(self, cr, uid, ids, portal_id, context=None): |
|
||||
|
@api.onchange('portal_id') |
||||
|
def onchange_portal(self): |
||||
# for each partner, determine corresponding portal.wizard.user records |
# 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 [] |
|
||||
|
res_partner = self.env['res.partner'] |
||||
|
partner_ids = self._context.get('active_ids', []) |
||||
|
|
||||
contact_ids = set() |
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): |
|
||||
|
for partner in res_partner.browse(partner_ids): |
||||
|
for contact in (partner.child_ids | partner): |
||||
# make sure that each contact appears at most once in the list |
# make sure that each contact appears at most once in the list |
||||
if contact.id not in contact_ids: |
if contact.id not in contact_ids: |
||||
contact_ids.add(contact.id) |
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, { |
|
||||
|
in_portal = self.portal_id in contact.user_ids.mapped('groups_id') |
||||
|
self.user_ids |= self.env['portal.wizard.user'].new({ |
||||
'partner_id': contact.id, |
'partner_id': contact.id, |
||||
'email': contact.email, |
'email': contact.email, |
||||
'in_portal': in_portal, |
'in_portal': in_portal, |
||||
})) |
|
||||
return {'value': {'user_ids': user_changes}} |
|
||||
|
}) |
||||
|
|
Write
Preview
Loading…
Cancel
Save
Reference in new issue