Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Odoo 10: Open a form view in an editable tree view

Tags:

odoo

odoo-10

I am creating a new model in Odoo 10. This model is accessed through a menu item which launches tree view.

Tree view is editable but I would like to be able to launch form view for the specific record user is editing if user wants to.

Is there any option to either put a button in the tree view to launch the form view or something? Could someone highlight the steps required or point to a similar code example?

Thanks,

like image 365
M.E. Avatar asked Sep 13 '25 07:09

M.E.


2 Answers

using a buttons : in tree view:

 <tree editable="top">
        ...
        ...
      <button name="open_record" type="object" class="oe_highlight"/>
  </tree>

in your model:

  @api.multi
  def open_record(self):
    # first you need to get the id of your record
    # you didn't specify what you want to edit exactly
    rec_id = self.someMany2oneField.id
    # then if you have more than one form view then specify the form id
    form_id = self.env.ref('module_name.form_xml_id')

    # then open the form
    return {
            'type': 'ir.actions.act_window',
            'name': 'title',
            'res_model': 'your.model',
            'res_id': rec_id.id,
            'view_type': 'form',
            'view_mode': 'form',
            'view_id': form_id.id,
            'context': {},  
            # if you want to open the form in edit mode direclty            
            'flags': {'initial_mode': 'edit'},
            'target': 'current',
        }
like image 103
Charif DZ Avatar answered Sep 16 '25 08:09

Charif DZ


You don't need a special function or button or whatever for this requirement. Just add the form view in your menu actions view_mode:

<record id="my_menu_action" model="ir.actions.act_window">
    <field name="name">Action</field>
    <field name="res_model">my.model</field>
    <field name="view_mode">tree,form</field>
    <field name="view_id" ref="my_tree_view" />
</record>

While editing an entry in the editable list view, you can change to the form view via view switcher upper right corner of the client.

Note: Not working in later versions of Odoo.

like image 39
CZoellner Avatar answered Sep 16 '25 08:09

CZoellner