Browse Source

[REVIEW] Change onchange to new api

pull/14/head
Thibault Francois 8 years ago
parent
commit
86e9574aca
  1. 40
      beesdoo_base/wizard/portal_wizard.py
  2. 50
      beesdoo_base/wizard/views/partner.xml

40
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}}
})

50
beesdoo_base/wizard/views/partner.xml

@ -1,22 +1,34 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<!-- New eater generation wizard -->
<record id="Eater Wizard" model="ir.ui.view">
<field name="name">New Eater Wizard</field>
<field name="model">eater.new.wizard</field>
<field name="arch" type="xml">
<form string="Create a new eater">
<group>
<field name="first_name" />
<field name="last_name" />
<field name="email" />
</group>
<footer>
<button type="object" name="create_new_eater" string="Create"
class="oe_highlight" />
<button special="cancel" string="Cancel" />
</footer>
</form>
</field>
</record>
<!-- New eater generation wizard -->
<record id="Eater Wizard" model="ir.ui.view">
<field name="name">New Eater Wizard</field>
<field name="model">eater.new.wizard</field>
<field name="arch" type="xml">
<form string="Create a new eater">
<group>
<field name="first_name" />
<field name="last_name" />
<field name="email" />
</group>
<footer>
<button type="object" name="create_new_eater"
string="Create" class="oe_highlight" />
<button special="cancel" string="Cancel" />
</footer>
</form>
</field>
</record>
<record id="beesdoo_portal_wizard_view" model="ir.ui.view">
<field name="name">Unfuck Portal Wizard</field>
<field name="model">portal.wizard</field>
<field name="inherit_id" ref="portal.wizard_view" />
<field name="arch" type="xml">
<field name="portal_id" position="attributes">
<attribute name="on_change" />
</field>
</field>
</record>
</odoo>
Loading…
Cancel
Save