如何通过单击many2many字段中的记录来显示表单视图,而无需提升模式面板

问题描述 投票:0回答:1

我有一个带有Many2many字段的表单,我将其显示为树视图:

enter image description here

通过单击上面提到的Many2many字段中的记录,相应模型的形式将按照预期在模态面板中提升:

enter image description here

我找不到点击Many2many字段记录的方法,而不是提起向导,我将获得与Many2many字段模型相对应的表单视图,而无需提起弹出窗口。换句话说,这样:

enter image description here

有什么建议?

odoo odoo-11
1个回答
1
投票

您可以在模型上编写一个操作方法,并将树视图扩展为按钮。此方法应返回一个在窗体视图中打开记录的操作。使用当前的Odoo框架,这是唯一“简单”的方法。

一个小例子:

class MyModel(models.Model):
    _name = 'my.model'

    name = fields.Char()

class MyOtherModel(models.Model)
    _name = 'my.other.model'

    name = fields.Char
    my_model_ids = fields.Many2many(
        comodel_name='my.model')

    @api.multi
    def action_show_record(self):
        # only use on singletons
        self.ensure_one()
        return {
            'name': self.name,
            'type': 'ir.actions.act_window',
            'view_type': 'form',
            'view_mode': 'form',
            'res_model': 'my.model',
            'context': self.env.context,
            # don't open a popup
            'target': 'current'
        }

和my.other.model的视图

<record id="my_other_model_view_form" model="ir.ui.view">
    <field name="name">my.other.model.view.form</field>
    <field name="model">my.other.model</field>
    <field name="arch" type="xml">
        <form>
            <sheet>
                <group>
                    <field name="name" />
                    <field name="my_model_ids">
                        <tree>
                            <field name="name" />
                            <button name="action_show_record" type="object"
                                string="Open" icon="an-font-awesome-icon" />
                        </tree>
                    </field>
                </group>
            </sheet>
        </form>
    </field>
</record>
© www.soinside.com 2019 - 2024. All rights reserved.