From 86e9574acaeb52a6a806e3f4a902e27ffc4187b7 Mon Sep 17 00:00:00 2001 From: Thibault Francois Date: Thu, 22 Dec 2016 19:03:10 +0100 Subject: [PATCH] [REVIEW] Change onchange to new api --- beesdoo_base/wizard/portal_wizard.py | 44 ++++++++--------------- beesdoo_base/wizard/views/partner.xml | 50 +++++++++++++++++---------- 2 files changed, 45 insertions(+), 49 deletions(-) diff --git a/beesdoo_base/wizard/portal_wizard.py b/beesdoo_base/wizard/portal_wizard.py index 3a3430c..4f10bf8 100644 --- a/beesdoo_base/wizard/portal_wizard.py +++ b/beesdoo_base/wizard/portal_wizard.py @@ -1,42 +1,26 @@ -from openerp.osv import osv from openerp import models, fields, api from openerp import SUPERUSER_ID -class BeesdooWizard(osv.osv_memory): - +class BeesdooWizard(models.Model): + _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 - 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() - 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 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, { + 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, 'email': contact.email, 'in_portal': in_portal, - })) - return {'value': {'user_ids': user_changes}} + }) + diff --git a/beesdoo_base/wizard/views/partner.xml b/beesdoo_base/wizard/views/partner.xml index bae9c33..302bab5 100644 --- a/beesdoo_base/wizard/views/partner.xml +++ b/beesdoo_base/wizard/views/partner.xml @@ -1,22 +1,34 @@ - - - New Eater Wizard - eater.new.wizard - -
- - - - - -
-
-
-
-
+ + + New Eater Wizard + eater.new.wizard + +
+ + + + + +
+
+
+
+
+ + + Unfuck Portal Wizard + portal.wizard + + + + + + + +
\ No newline at end of file