Skip to Content
Meniu
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
Această întrebare a fost marcată
4 Răspunsuri
31890 Vizualizări

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

Imagine profil
Abandonează

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.

Cel mai bun răspuns

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'
            };

Imagine profil
Abandonează
Cel mai bun răspuns

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>
Imagine profil
Abandonează
Cel mai bun răspuns

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'}}},
Imagine profil
Abandonează
Cel mai bun răspuns

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',
}
Imagine profil
Abandonează
Related Posts Răspunsuri Vizualizări Activitate
1
dec. 21
7736
1
iun. 15
6458
0
iun. 15
89
2
mar. 15
8756
0
mar. 15
4031