我有一个带有Many2many
字段的表单,我将其显示为树视图:
通过单击上面提到的Many2many
字段中的记录,相应模型的形式将按照预期在模态面板中提升:
我找不到点击Many2many
字段记录的方法,而不是提起向导,我将获得与Many2many
字段模型相对应的表单视图,而无需提起弹出窗口。换句话说,这样:
有什么建议?
您可以在模型上编写一个操作方法,并将树视图扩展为按钮。此方法应返回一个在窗体视图中打开记录的操作。使用当前的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>