Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
2 Trả lời
9278 Lượt xem

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>

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

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

Ảnh đại diện
Huỷ bỏ
Tác giả

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

Tác giả Câu trả lời hay nhất

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.

Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
2
thg 3 15
9878
1
thg 3 15
4253
2
thg 4 24
2090
4
thg 9 24
21293
3
thg 10 20
4785