Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
4 Trả lời
31934 Lượt xem

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

Ảnh đại diện
Huỷ bỏ

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.

Câu trả lời hay nhất

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

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

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>
Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

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'}}},
Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

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',
}
Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
1
thg 12 21
7774
1
thg 6 15
6482
0
thg 6 15
89
2
thg 3 15
8784
0
thg 3 15
4063