Skip to Content
Menu
This question has been flagged
12 Replies
14346 Views

This question is related to:
https://www.odoo.com/forum/help-1/question/open-a-form-view-for-a-specific-record-or-go-back-to-previous-view-64998

When I'm navigating between views, in the header I can see this history:

Example: Opportunities / New oportunity / Administrator 
Clicking in New oportunity would navigate one view back, clicking in Opportunities would navigate 2 views back.

How can I do this automatically from a function in python? 

I have managed to create a new view, but can't go back to last view.

Thanks,
Pau

 

Avatar
Discard
Author Best Answer

I managed to solve it!! (where's the smiley of infinite happiness?)

I just navigate back in browser history.

For this I need to create an action: 

        <record model="ir.actions.client" id="action_client_back">
            <field name="name">instance.bdt.Back</field>
            <field name="tag">bdt.back</field>
            <field name="params">{}</field>
        </record>

and the JS function:

openerp.request_project = function(instance) {
    instance.request_project = {};
    instance.request_project.back = function(){
        window.history.back();
    };
    instance.web.client_actions.add('bdt.back', 'instance.request_project.back');
}

So, when I finish what button does I can return back:

return {'type': 'ir.actions.client', 'tag': 'bdt.back'}
Avatar
Discard

And just to update this for odoo 16 (and probably above).

Add the following JS to your module:

```js
/** @odoo-module **/
import { registry } from '@web/core/registry';

async function goBack(env, action) {
env.services.action.restore();
}

registry.category('actions').add('history_back', goBack);
```

Now you can actually use the following in your python code

```python
return {'type': 'ir.actions.client', 'tag': 'history_back'}
```

Best Answer

To navigate back in history,

you don't need to create a new function. It is already in Odoo.

Just add at the end of your button python function:

return {'type': 'ir.actions.client', 'tag': 'history_back'}

Avatar
Discard

Best. Thanks :)

FYI Tried this in Odoo 16 and it doesn't work

Best Answer

If you are meaning, to load a particular action...

then in your return statement of the function, return the action / ir_act_window...

Example:

model_obj = self.pool.get('ir.model.data')
        
form_view = model_obj._get_id(cr, uid, 'MODULE_NAME', 'XML_VIEW')
if form_view:
            form_view = model_obj.browse(cr, uid, form_view, context=context).res_id

return {
                    'view_type' : 'form',
                    'view_mode' : 'form',
                    'res_model' : 'MODEL',
                    'res_id'    : False,
                    'view_id'   : False,
                    'views'     : [(form_view, 'form'), ],
                    'type'      : 'ir.actions.act_window',
                    'target'    : 'current',
                  }

You can also refer in standard, Invoice to Refund option as well, in which when an invoice is refunded, it loads action of Refunds...

Avatar
Discard
Author

Hi deep, thanks but I don't mean it. You can check the link to the other question.

Author

Now I do as you described, and the problem is that I get a new element in the navigation history instead of deleting the last one.

add reload: True in the value list

'tag': 'reload',

Author

Could you clarify last answer?

If still the problem persists, then you can write you own widget to do the same....

I didnt get... which one?

Author

I tried reload, but it doesn't go to the previous view, it just refresh the new one.

Author

Thanks anyway deep.