Odoo 11 how to avoid loading the homepage after module upgrade

Odoo 11 by default redirects the user to his homepage after a module upgrade, to avoid this trouble I made a small modification of the module upgrade behavior. Additional module is available here. It inherits only the model “ir.module.module” and override “_button_immediate_function” method.

import base64
from collections import defaultdict
from decorator import decorator
from operator import attrgetter
import importlib
import io
import logging
import os
import shutil
import tempfile
import zipfile

import requests

from odoo.tools import pycompat

from docutils import nodes
from docutils.core import publish_string
from docutils.transforms import Transform, writer_aux
from docutils.writers.html4css1 import Writer
import lxml.html
import psycopg2

import odoo
from odoo import api, fields, models, modules, tools, _
from odoo.exceptions import AccessDenied, UserError
from odoo.tools.parse_version import parse_version
from odoo.tools.misc import topological_sort
from odoo.http import request

_logger = logging.getLogger(__name__)

class Module(models.Model):
    _inherit = "ir.module.module"

    def _button_immediate_function(self, function):
            # This is done because the installation/uninstallation/upgrade can modify a currently
            # running cron job and prevent it from finishing, and since the ir_cron table is locked
            # during execution, the lock won't be released until timeout.
            self._cr.execute("SELECT * FROM ir_cron FOR UPDATE NOWAIT")
        except psycopg2.OperationalError:
            raise UserError(_("The server is busy right now, module operations are not possible at"
                              " this time, please try again later."))

        modules.registry.Registry.new(self._cr.dbname, update_module=True)

        env = api.Environment(self._cr, self._uid, self._context)
        # pylint: disable=next-method-called
        config = env['ir.module.module'].next() or {}
        if config.get('type') not in ('ir.actions.act_window_close',):
            config['url'] = '/web?debug=1#id=%s&view_type=form&model=ir.module.module' % (self.id)
            return config

        # reload the client; open the first available root menu
        menu = env['ir.ui.menu'].search([('parent_id', '=', False)])[:1]
        return {
            'type': 'ir.actions.client',
            'tag': 'reload',
            'params': {'menu_id': menu.id},

How useful was this post?

Average rating / 5. Vote count:

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.