forvas
forvas

Reputation: 10189

How to open an existing record in edit mode in Odoo 10?

I am not able to open an existing record in edit mode. This is the return of the Python method which opens the form view of the record:

@api.multi
def open_view(self):
    return {
        'name': _('My Wizard'),
        'type': 'ir.actions.act_window',
        'view_type': 'form',
        'view_mode': 'form',
        'res_model': 'my.model',
        'target': 'current',
        'res_id': self.id,
    }

And I have tried (with no success) to add to the return dictionary the following keys:

Flag option mode

'flags': {
    'form': {
        'options': {
            'mode': 'edit',
        },
    }
},

It does nothing, I guess it only works if the key res_id is missing.

Flag option initial_mode

'flags': {
    'form': {
        'options': {
            'initial_mode': 'edit',
        },
    }
},

Same as mode.

Context keys form_view_initial_mode and force_detailed_view

'context': {
    'form_view_initial_mode': 'edit',
    'force_detailed_view': 'true'
},

They do nothing either, they seem to work only in version 11.

Target inline

'target': 'inline',

This is the only one which works, but it makes dissapear Create and Edit buttons from the top of the form, and I do not want that.

In conclusion, I need to open an existing record in edit mode and with 'target': 'current' to have common form buttons and be like a normal form (not a pop-up).

Does anyone know how to manage this?

Upvotes: 2

Views: 2827

Answers (2)

paul boutin
paul boutin

Reputation: 31

with odoo v12

return {
        'type': 'ir.actions.act_window',
        'view_type': 'form',
        'view_mode': 'form',
        'res_model': 'project.project',
        'res_id': MY_RECORD.id,
        'context': {'form_view_initial_mode': 'edit'},
    }

Upvotes: 3

CZoellner
CZoellner

Reputation: 14768

'flags': {'initial_mode': 'edit'} should work in Odoo V10.

I tried it with a server action on hr.employee with the folling code. I added the action to the more/action menu, opened an employee in form view and started the action.

action ={
        'type': 'ir.actions.act_window',
        'view_type': 'form',
        'view_mode': 'form',
        'res_model': 'hr.employee',
        'target': 'current',
        'res_id': record.id,
        'flags': {'initial_mode': 'edit'}
    }

Upvotes: 1

Related Questions