Created
August 19, 2020 05:06
-
-
Save rvalyi/d293e1fce3ffcc735945ed43947499bc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import logging | |
import odoo | |
from odoo import http | |
from odoo.tools import config | |
_logger = logging.getLogger(__name__) | |
# similar to odoo.http.db_monodb but forcing the PRODUCTION_DB database | |
# in case there are several databases and request (like portal/website) | |
# doesn't specify any database. | |
def db_monodb_patched(httprequest=None): | |
""" | |
Magic function to find the current database. | |
Implementation details: | |
* Magic | |
* More magic | |
Returns ``None`` if the magic is not magic enough. | |
""" | |
httprequest = httprequest or request.httprequest | |
dbs = http.db_list(True, httprequest) | |
# try the db already in the session | |
db_session = httprequest.session.db | |
if db_session in dbs: | |
return db_session | |
# if there is only one possible db, we take that one | |
if len(dbs) == 1: | |
return dbs[0] | |
elif config.get('db_name') in dbs and not httprequest.args.get('db'): | |
_logger.info("request %s with database ambiguity: " | |
"forcing production database: %s" % (httprequest.path, | |
config['db_name'],)) | |
return config['db_name'] | |
return None | |
http.db_monodb = db_monodb_patched |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment