Ir al contenido
Menú
Se marcó esta pregunta
2 Respuestas
8902 Vistas

I have this columns:

_columns = {
    'pos_name': fields.many2one('pos.config', 'Point of Sale', required=True),
    'session_master_ids': fields.many2many('pos.session', 'pos_gta_session_rel', 'export_id', 'session_id', string='POS Sessions', readonly=True),
}

And this function:

    def on_change_pos_name(self, cr, uid, ids, pos_name, context=None):
        val = {}
        if pos_name:
            session_ids = self.pool.get('pos.session').search(cr, uid, [('config_id', '=', pos_name)], context=context)
            val = {
                'session_master_ids': session_ids
            }
        return {'value': val}

I konw that it is not sotred in the database becaus of the parameter "readonly=True". 
It would help me a lot if create="false" delete="false" in tree would work, but it does't.

                                <field name="session_master_ids" widget="many2many">
                                    <tree create="false" delete="false">
                                        <field name="name"/>
                                        <field name="user_id"/>
                                        <field name="state"/>
                                        <field name="create_date"/>
                                        <field name="write_date"/>
                                        <field name="start_at"/>
                                        <field name="stop_at"/>
                                    </tree>
                                </field>

Avatar
Descartar
Mejor respuesta

Hello Mathias,

 

In this case you need to programatically create the records for many2many fields, keeping the field as readonly.

Go to http://stackoverflow.com/questions/9377402/insert-into-many-to-many-openerp

This is the example where you can get to know how to programatically write the data in many2many fields

Avatar
Descartar
Autor

Sorry, I can't, need 20 karma for this.

Autor Mejor respuesta

Thank you very much, this helped me a lot. I only changed 'session_master_ids': session_ids to 'session_master_ids': [(6, 0, session_ids)] and it works perfectly.

Avatar
Descartar
Publicaciones relacionadas Respuestas Vistas Actividad
2
mar 15
9528
1
mar 15
3999
2
abr 24
1715
4
sept 24
20873
3
oct 20
4529