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

Hi everyone, everything fine?

Odoo 12:


I have a Tree View of a custom module, I needed to add an item to change the status in bulk in my action dropdown.


So far so good:


      <act_window id = "id_for_record"
                    name = "Construction - Change Status"
                    src_model = "construction"
                    res_model = "construction.change.state"
                    view_type = "form" view_mode = "form"
                    key2 = "client_action_multi"
                    
        />



<record id = "wizard_view" model = "ir.ui.view">
            <field name = "name"> Test </field>
            <field name = "model"> construction.change.state </field>
            <field name = "arch" type = "xml">
                <form string = "Test">
                    <group>
                        <group>
                            <field name = "state"> </field>
                        </group>
                    </group>
                    <footer>
                        <button string = "Apply" name = "action_apply" type = "object" class = "btn-primary" />
                        <button string = "Cancel" class = "btn-default" special = "cancel" />
                    </footer>
                </form>
            </field>
        </record>



I added a model:


class constructionChangeState (models.TransientModel):
    _name = 'construction.change.state'
    state = fields.Selection ([('finalized', 'Finalized'), ('progress', 'In Progress')], string = 'State')


    def action_apply (self):
        pass


My problem is quite simple actually, how can I pass the selected Ids in the Tree View to the Form and make the bulk change?

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

Hi,

Inside the function in the wizard, to get the selected records in the tree, use below code,

selected_ids = self.env.context.get('active_ids', [])
selected_records = self.env['your_model_name'].browse(selected_ids)

We will get the selected record from active_ids

Thanks

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

Thank you!:)

Bài viết liên quan Trả lời Lượt xem Hoạt động
2
thg 4 20
14278
2
thg 1 24
15844
4
thg 4 15
11388
1
thg 8 24
1451
0
thg 6 24
1677