Odoo Help

0

Why is many2many field with readonly=True not saved in database and Is there a way to do this?

By
Mathias Neef
on 11/21/14, 9:40 AM 2,123 views

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>

1

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

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

Mathias Neef
on 11/21/14, 1:52 PM
0
Mathias Neef
On 11/22/14, 12:14 AM

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.

About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

Register

Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)

Stats

Asked: 11/21/14, 9:40 AM
Seen: 2123 times
Last updated: 3/16/15, 8:10 AM