Skip to Content
Menu
This question has been flagged
4 Replies
29863 Views

Hello, I have a form that opens in edit mode when a menu item is clicked from a sub menu, but what I would like to do is open the form in view mode. I have an xml action defined like so:

<record id="action_view_product_version" model="ir.actions.act_window">
        <field name="name">Product Version</field>
        <field name="res_model">product.version</field>
        <field name="view_type">form</field>
        <field name="view_mode">form,tree</field>
        <field name="target">current</field>
</record>

i saw this post here which says that setting the target to current will open the form in view mode, but when I did this it isnt working: https://accounts.openerp.com/forum/Help-1/question/3447

does anyone know how to open the form in view mode? I noticed that when the form view button is clicked on the upper right corner, then it opens the form in the view mode. Thank you

Avatar
Discard

you can define a button as this code <button string="Product Version" type="action" name="%(action_view_product_version)d" icon="gtk-go-forward"/> on your form.

Best Answer

Hi, if you are using JS or you are returning an action to open the form you can add `flags` for this, unfortunately there is no `flags` field in the python model of `ir.action.act_window`.

JS:

 var action = {
                type: 'ir.actions.act_window',
                name: 'Action Name',
                target: 'new', //use 'current' for not opening in a dialog
                res_model: 'target.model',
                res_id: target_id,
                view_id: 'view_xml_id',//optional
                view_type: 'form',
                views: [[false,'form']],
                context: {//your context
                         },
                flags:{
                mode:'readonly'
} // default is 'edit'
            };
        this.do_action(action);
 


in python code (assuming that your button has `type='object'`):

@api.multi
def your_button_name(self):
return {
                'type': 'ir.actions.act_window',
                'name': 'Action Name',
                'target': 'new', #use 'current' for not opening in a dialog
                'res_model': 'target.model',
                'res_id': target_id,
                'view_id': 'view_xml_id',#optional
                'view_type': 'form',
                'views': [[false,'form']],
                'context': {#your context
                         },
                'flags':{mode:'readonly'} # default is 'edit'
            };

Avatar
Discard
Best Answer

try something like that

<record model="ir.actions.act_window" id="action_view_product_version">
    <field name="name">Product Version</field>
    <field name="type">ir.actions.act_window</field>
    <field name="res_model">product.version</field>
    <field name="view_type">form</field>
    <field name="view_id" ref="[your_product_version_form_view]"/>
</record>
Avatar
Discard
Best Answer

Found this way in calendar module and it works fine :-)

Add following key into the action dict:

'flags': {'form': {'action_buttons': True, 'options': {'mode': 'edit'}}},
Avatar
Discard
Best Answer

If you want to open a form then you can use:

return {
'type': 'ir.actions.act_window',
'view_type': 'form',
'view_id': self.env.ref('module_name.view_id').id,
'view_mode': 'form',
'res_model': 'model.ame',
'context': {
},
# 'res_id': self.get_open_obstetrics_file_id(),
'target': 'self',
}
Avatar
Discard
Related Posts Replies Views Activity
1
Dec 21
6335
1
Jun 15
5424
0
Jun 15
88
2
Mar 15
7596
0
Mar 15
3139