Reputation: 133
I have a form with a Many2many
field and I'm showing it as a tree view:
By clicking on a record in the Many2many
field mentioned above, the form of the corresponding model is lifted in a modal panel, as expected:
I can't find a way to click on a record of the Many2many
field, instead of lifting a wizard, I will have the form view corresponding to the model of that Many2many
field, without lifting a popup. In other words, this way:
Any suggestions?
Upvotes: 0
Views: 792
Reputation: 14778
You can write an action method on the model and extend the tree view showing this as button. This method should return an action which opens the record in a form view. That's the only "easy" way to do that, with the current Odoo framework.
A little example:
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'
}
and the view of 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>
Upvotes: 1