This question has been flagged
1 Reply
3744 Views

In the basic form view when I click on a record in a Many2many relation it creates a popup with the record.


1) How can I make this click instead go directly to the record?

2) If the parent model isn't in "edit mode" the popup won't be in "edit mode". Is it possible to have the parent "read mode" and in the popup somehow press an edit button to make that in "edit mode" ? ..the only way now is to close the popup, press parent "edit" and then open the popup again


Thanks!

Avatar
Discard
Best Answer

Hi,

In your M2M, add a button ( that will be displayed for each line ). this button will redirect you to the form view of that record.


Avatar
Discard
Author

The Many2many records is listed in a tree view. How do you propose I add a button there? And with what attributes? Do you have an example?

suppose your field is x_ids.

in Xml add context like this :

<field name="x_ids"

context="{'tree_view_ref':'your_model.your_tree_view_to_display_in_x_ids'}"/>

Then declare the tree view :

<record model="ir.ui.view" id="your_tree_view_to_display_in_x_ids">

<field name="name">your.tree.view.to.display.in.x.ids</field>

<field name="model">your.model</field>

<field name="priority">500</field>

<field name="arch" type="xml">

<tree readonly="1">

<field name="Field1"/>

<field name="Field2"/>

<field name="Field3"/>

<field name="Field4"/>

<field name="Field5"/>

<button name="button_redirect_to_record" type="object" icon="fa-archive"

string="Open Record"/>

</tree>

</field>

</record>

Now Your button function should be like this :

@api.multi

def button_redirect_to_record(self):

self.ensure_one()

return {

'name': _('Model'),

'view_type': 'form',

'view_mode': 'form',

'view_id': self.env.ref('Your_model.Your_Form_View').id,

'res_model': 'your.model',

'context': self._context,

'type': 'ir.actions.act_window',

'nodestroy': True,

'target': 'current',

'res_id': your_record_id,

}

Let me know the output in your case.

Redirect to tree view on button click: https://goo.gl/Baw9Zt

Hope this will help you.

Author

Thanks guys for you help. Actually I was more hoping there was an option for the m2m widget that could do this. Even adding a button feels like a hack in the user interface for the user since clicking the whole row still opens the dialog. I'm gonna research how to extend the widget and change the behaviour there

Author

Im also hoping someone can answer the second part of the question 2)