Skip to Content
Menú
This question has been flagged
2 Respostes
8946 Vistes

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
Best Answer

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 Best Answer

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
Related Posts Respostes Vistes Activitat
2
de març 15
9584
1
de març 15
4025
2
d’abr. 24
1789
4
de set. 24
20922
3
d’oct. 20
4552