odooodoo-12formview

Odoo12 - Open form in view mode


I'm trying to open a form in view mode like sale.order forms in my custom module. I'm tring to explain better: When I save my record and re enter in it, this form view is in editable mode, and I need it in view mode.

I tried to call to my form with <field name="target">current</field> in my action, like others answers that I saw on internet, but it didn't change.

EDIT:

I fix it change kanban view to another that I copy from standard code.


Solution

  • You can pass readonly mode to action values using flags:

    'flags': {'mode': 'readonly'}  
    


    EDIT:

    You can define a server action and execute a python code to return a custom action.

    In the following example the sale order form is opened in readonly mode:

    <record id="action_sale_order_readonly" model="ir.actions.server">
            <field name="name">Sale Order</field>
            <field name="model_id" ref="sale.model_sale_order"/>
            <field name="state">code</field>
            <field name="code">
    form_view = env.ref('sale.view_order_form')
    action = {
            'name': 'Sale Order',
            'res_model': 'sale.order',
            'views': [(form_view.id, 'form'),],
            'view_mode': 'form,tree,kanban',
            'type': 'ir.actions.act_window',
            'target': 'current',
            'flags': {'mode': 'readonly'}
        }
            </field>
    </record>