Open ERP Forum
   IndexIndex   SearchSearch     RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   RSSRSS   Mailing ListMailing List   Log inLog in 

[SOLVED] Dynamic view and fields with Wizard
 
Post new topic   Reply to topic    Open Object Forum Index -> Wizards Questions
View previous topic :: View next topic  
Author Message
zyphos



Joined: 31 May 2007
Posts: 45

PostPosted: Wed Jan 13, 2010 4:03 pm    Post subject: [SOLVED] Dynamic view and fields with Wizard Reply with quote

Hi,
Is it anyway to assign a wizard view and fields in a dynamic way ?

Example:
Code:
states = {'init': {
'actions': [_get_defaults],
'result': {'type': 'form', 'arch': form, 'fields': fields, 'state':[('end','Cancel'), ('send','Send')]}
},}


The _get_defaults() changes "form" and "fields" content.

Thanks in advance for any solution.

Regards,
Nicolas DS


Last edited by zyphos on Wed Jan 13, 2010 4:25 pm; edited 1 time in total
Back to top
View user's profile Send private message
zyphos



Joined: 31 May 2007
Posts: 45

PostPosted: Wed Jan 13, 2010 4:24 pm    Post subject: Reply with quote

After seeking in OpenObject server source:

Here is the way to achieve this:
Code:
def _get_defaults(self, cr, user, data, context):
    self.states['init']['result']['arch'] =  '''<?xml version="1.0"?><!-- My new view -->'''
    self.states['init']['result']['fields']['my_new_field'] = {'string':'My field', 'type':'boolean'}
Back to top
View user's profile Send private message
zyphos



Joined: 31 May 2007
Posts: 45

PostPosted: Mon Feb 01, 2010 6:08 pm    Post subject: Reply with quote

Another way to achieve this with osv.osv and osv.osv_memory is to do like in base_module/ir/ir_model.py @ class ir_model_grid(osv.osv):

Code:
def fields_get(self, cr, uid, fields=None, context=None, read_access=True):
        result = super(ir_model_grid, self).fields_get(cr, uid, fields, context)
        groups = self.pool.get('res.groups').search(cr, uid, [])
        groups_br = self.pool.get('res.groups').browse(cr, uid, groups)
        result['group_0'] = {'string': 'All Users','type': 'char','size': 7}
        for group in groups_br:
            result['group_%d'%group.id] = {'string': '%s'%group.name,'type': 'char','size': 7}
        return result

    def fields_view_get(self, cr, uid, view_id=None, view_type='form', context={}, toolbar=False):
        result = super(ir_model_grid, self).fields_view_get(cr, uid, view_id, view_type, context=context, toolbar=toolbar)
        groups = self.pool.get('res.groups').search(cr, uid, [])
        groups_br = self.pool.get('res.groups').browse(cr, uid, groups)
        cols = ['model', 'name']
        xml = '''<?xml version="1.0"?>
<%s editable="bottom">
    <field name="name" select="1" readonly="1" required="1"/>
    <field name="model" select="1" readonly="1" required="1"/>
    <field name="group_0"/>
    ''' % (view_type,)
        for group in groups_br:
            xml += '''<field name="group_%d"/>''' % (group.id, )
        xml += '''</%s>''' % (view_type,)
        result['arch'] = xml
        result['fields'] = self.fields_get(cr, uid, cols, context)
        return result

Thank you to Albert Cervera i Areny for the tip.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Open Object Forum Index -> Wizards Questions All times are GMT + 2 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum