问题
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,
回答1:
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',
}
回答2:
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.
回答3:
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
来源:https://stackoverflow.com/questions/45316649/odoo-10-open-a-form-view-in-an-editable-tree-view