How to open one2many record in current window, not a popup in odoo V13

Question:

I searched through the old forums and didn’t find any decent answers. Is it possible to click on a record in a one2many list and have it open the full page, rather than just the popup?

If yes, where else i can make changes in the code ?

I’m trying to access attachments/reports/links associated with that record, and that’s not possible if I’m only ever getting a popup window.

Thanks for your input.

Asked By: aru

||

Answers:

You can use button to achieve this in form view list. The button type has to be object and it will return ir.actions.act_window type action.

Add following button inside the tree tag:

<button name="open_action" string="Open" type="object" class="oe_highlight"/>

Add this function to the model:

def open_action(self):
  return {
    'name': self.display_name,
    'type': 'ir.actions.act_window',
    'view_mode': 'form',
    'res_model': self._name,
    'res_id': self.id,
    'target': 'current
}

Note that target current ensure the object will open in current window. Target new opens in a modal popup.

Answered By: arryph

As of this writing, in Odoo 15, it is still not possible to do that directly. You need to add a button in the view, but that can be done easily in the view XML only:

<tree no_open="1">
  <field name="name"/>
  <button name="get_formview_action" string="View" type="object" class="btn-primary"/>
</tree>

With no_open="1", clicking on a line in the tree will not open the popup.
get_formview_action is a Python method that already exists in Odoo for all models, and you don’t have to write yourself.

Answered By: Jerther
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.