This question has been flagged
6 Replies
15267 Views

I have a module that overrides the default write functionality for sales orders. This works fine, but after the write I would like to return to the tree view of sales orders instead of the form view which is the default functionality.

The following code is what I'm working with at the moment, i.e. I'm trying to pass the treeview information inside the result object. There are no error messages, but the user is still always returned to the form view. Any suggestions? Thanks!

class Sales_order(osv.Model):

_inherit = 'sale.order' 

def write(self, cr, uid, ids, vals, context=None):

    # own custom code goes here - works OK
    # ...

    # call write - works OK
    super(Sales_order, self).write(cr, uid, ids, vals, context)

    # After all done, how to return to the tree view?
    models_data = self.pool.get('ir.model.data')       

    sale_order_tree = models_data._get_id(cr, uid, 'sale', 'view_order_tree')

    return {
        'name': 'Quotations',
        'view_type': 'tree',
        "view_mode": 'tree,form',
        'res_model': 'sale.order',
        'type': 'ir.actions.act_window',
        'search_view_id': sale_order_tree,
    }
Avatar
Discard

I have the same requirement.Any one please help :(

Hi, Please have a look on answer and if it is ok then mark it as answer.

Best Answer

hi,

please write down as like the below for the return.

return { 
'name': 'Quotations', 
'view_type': 'form', 
'view_mode': 'tree,form', 
'res_model': 'sale.order', 
'type': 'ir.actions.act_window', 
'search_view_id': sale_order_tree, 
}

Avatar
Discard
Best Answer

 Hi, what wrong in my case? Code

return {
'type': 'ir.actions.act_window',
'res_model': 'ita.contact',
'view_type': 'form',
'view_mode': 'tree,form',
}
 

works if  I call method from button, but the same code doesn't work on write method:

 

@api.multi
def write(self, vals):
super(ita_contact, self).write(vals)
return {
'type': 'ir.actions.act_window',
'res_model': 'ita.contact',
'view_type': 'form',
'view_mode': 'tree,form',
}

I have no ideas :(

Avatar
Discard
Best Answer

I found that write or create doesnt return action 

so i have to look to other places.

what i know is that odoo using alot of js

after poking around for a bit i found that this js that control the event in form

baseodoov12\odoo\addons\web\static\src\js\views\form\form_controller.js

so i hack a bit on line 219, after saving the record i force the code to click breadcrumb which going to the treeview.


    saveRecord: function () {
        var self = this;
        alert('SAVE RECORD IS PUSH')
        return this._super.apply(this, arguments).then(function (changedFields) {
            // the title could have been changed
            self.set('title', self.getTitle());
            self._updateEnv();
            alert('CLICK BREADCRUMB')
            var $homeMenu = $("ol.breadcrumb > li.breadcrumb-item:first-child");
            $homeMenu.click()
.....


i know its not the best. but its working

ps. dont forget to clear cache on browser to refresh the js

Avatar
Discard
Best Answer

Any solution for this topic? I'm interested too.

Avatar
Discard