Skip to content
Snippets Groups Projects
Commit 161317f2 authored by Vincent Hatakeyama's avatar Vincent Hatakeyama
Browse files

:sparkles: new method to ease developing scripts

parent 5bf563e0
No related branches found
No related tags found
1 merge request!64Topic/default/odoo connect
...@@ -2,6 +2,11 @@ ...@@ -2,6 +2,11 @@
History History
======= =======
13.1.0
------
Add a handy method in odoo.py when writing scripts.
13.0.0 13.0.0
------ ------
......
...@@ -2,5 +2,5 @@ ...@@ -2,5 +2,5 @@
__author__ = "XCG Consulting" __author__ = "XCG Consulting"
# expose some useful functions # expose some useful functions
from .odoo import odoo_connect_parser, odoo_login # noqa: F401 from .odoo import odoo_connect, odoo_connect_parser, odoo_login # noqa: F401
from .parsing import logging_from_verbose # noqa: F401 from .parsing import logging_from_verbose # noqa: F401
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
import argparse import argparse
import getpass import getpass
import logging import logging
from typing import Optional from typing import Optional, Tuple
import odoorpc import odoorpc
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
port: int, port: int,
protocol: str, protocol: str,
timeout: int, timeout: int,
): ) -> Tuple[odoorpc.ODOO, Optional[int]]:
_logger.info( _logger.info(
"Connecting to Odoo on <%s://%s:%s> (%s DB)", "Connecting to Odoo on <%s://%s:%s> (%s DB)",
protocol, protocol,
...@@ -78,3 +78,19 @@ ...@@ -78,3 +78,19 @@
"-d", "--database", help="Odoo database", required=True "-d", "--database", help="Odoo database", required=True
) )
return parser return parser
def odoo_connect(
namespace: argparse.Namespace,
) -> Tuple[odoorpc.ODOO, Optional[int]]:
"""Return a connection and session id obtained from a namespace obtained
from parsing :func:odoo_connect_parser."""
return odoo_login(
login=namespace.login,
password=namespace.password,
port=namespace.port,
host=namespace.host,
protocol=namespace.protocol,
timeout=namespace.timeout,
database=namespace.database,
)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment