-
-
Save enieber/d2f7215e3613823bcacc7585ce9f4d2f to your computer and use it in GitHub Desktop.
Odoo shell enviroment wrapper for executre custom code
This file contains hidden or 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 sys | |
def execute_script(env, script_path): | |
# Importa el archivo de script como un modulo | |
import importlib.util | |
spec = importlib.util.spec_from_file_location("module.name", script_path) | |
script_module = importlib.util.module_from_spec(spec) | |
spec.loader.exec_module(script_module) | |
# Ejecuta la función 'run' del modulo importado | |
script_module.run(env) | |
if __name__ == "__main__": | |
import odoo | |
from odoo import api, SUPERUSER_ID | |
config_file = "/etc/odoo/odoo.conf" | |
database_name = "dbname" | |
script_path = sys.argv[1] # TODO: Validate | |
odoo.tools.config.parse_config(['-c', config_file]) | |
with odoo.api.Environment.manage(): | |
registry = odoo.registry(database_name) | |
with registry.cursor() as cursor: | |
env = odoo.api.Environment(cursor, SUPERUSER_ID, {}) | |
execute_script(env, script_path) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment