4
votes

In the below code is working for form view

search_ids = self.env['sale.order'].search([])
last_id = search_ids and max(search_ids)        
return {
    'name': _('Revise Quote'),
    'view_type': 'form',
    'view_mode': 'form',
    'res_model': 'sale.order',
    'res_id': last_id.id,
    'type': 'ir.actions.act_window',
}

How to redirect to edit view?

enter image description here

3

3 Answers

6
votes

In the calendar module I can see they return an additional key 'flags'.

Edit: I got the chance to test it, as I received a similar task, and I can confirm that the below flags do the trick.

calendar/calendar.py

def open_after_detach_event(self, cr, uid, ids, context=None):
    ...
    return {
        'type': 'ir.actions.act_window',
        'res_model': 'calendar.event',
        'view_mode': 'form',
        'res_id': new_id,
        'target': 'current',
        'flags': {'form': {'action_buttons': True, 'options': {'mode': 'edit'}}}
    }
0
votes

I don't think that you can open edit view directly.

Edit is working in Odoo like this, when you start editing you are not editing actual record its something like virtual one (copied example of real) and after pressing save you are updating records in db.

So you cant just open edit view on virtual record using action return that's impossible using standard methods.

0
votes

Try this in /web/static/src/js/view_form.js (line no :116) change value of initial_mode value from view to edit. It will affect all form views.

 _.defaults(this.options, {
        "not_interactible_on_create": false,
        // "initial_mode": "view",
        "initial_mode": "edit",
        "disable_autofocus": false,
        "footer_to_buttons": false,
    });

Hope it will solve your problem.