تخطي للذهاب إلى المحتوى
القائمة
لقد تم الإبلاغ عن هذا السؤال
4 الردود
31870 أدوات العرض

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

الصورة الرمزية
إهمال

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.

أفضل إجابة

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

الصورة الرمزية
إهمال
أفضل إجابة

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>
الصورة الرمزية
إهمال
أفضل إجابة

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'}}},
الصورة الرمزية
إهمال
أفضل إجابة

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',
}
الصورة الرمزية
إهمال
المنشورات ذات الصلة الردود أدوات العرض النشاط
1
ديسمبر 21
7721
1
يونيو 15
6425
0
يونيو 15
89
2
مارس 15
8740
0
مارس 15
4021