Mani
Mani

Reputation: 2655

How to return form edit view in odoo?

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

Upvotes: 4

Views: 5282

Answers (3)

dgeorgiev
dgeorgiev

Reputation: 941

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

Upvotes: 6

KbiR
KbiR

Reputation: 4174

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.

Upvotes: 0

Dachi Darchiashvili
Dachi Darchiashvili

Reputation: 769

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.

Upvotes: 0

Related Questions