4

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,

M.E.
  • 4,955
  • 4
  • 49
  • 128

3 Answers3

7

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',
        }
Charif DZ
  • 14,415
  • 3
  • 21
  • 40
  • I would like to edit the selected row, so each row (record) would have its own button, is that possible? – M.E. Jul 26 '17 at 07:17
3

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.

CZoellner
  • 13,553
  • 3
  • 25
  • 38
0

Go to the tree view, and remove the attribute editable="bottom"

 <tree editable="bottom" string="Journal Items">
      <field name="account_id" domain="[('company_id', '=', parent.company_id), ('deprecated', '=', False)]"/>
  </tree>

Once you remove that attribute the form view will be opened

sfx
  • 1,793
  • 17
  • 24