diff --git a/README.rst b/README.rst index 9935dcf..e573025 100644 --- a/README.rst +++ b/README.rst @@ -24,7 +24,7 @@ Modest PHP class to manage OpenERP Json query. Code maturity ------------- -Early working alpha. Comments welcome. Although it was tested against OpenERP version 6.1 and 7.0. +Early working alpha. Comments welcome. Although it was tested against OpenERP version 6.1, 7.0 and 8.0. Features @@ -35,6 +35,7 @@ Features - Ability to resume an open session (and thus login in openerp) with a saved ``session_id`` and HTTP ``cookie_id`` (without ``$login`` and ``$password``) +- Backwards compatiblity for Odoo 7.0 and prior with the legacy mode Usage diff --git a/src/OpenERP.php b/src/OpenERP.php index 4dc3da3..20e9bd9 100644 --- a/src/OpenERP.php +++ b/src/OpenERP.php @@ -20,7 +20,8 @@ class OpenERP { var $urls = array('read' => "/web/dataset/search_read", 'authenticate' => "/web/session/authenticate", 'get_session_info' => "/web/session/get_session_info", - 'destroy' => "/web/session/destroy"); + 'destroy' => "/web/session/destroy", + 'get_version_info' => "/web/webclient/version_info"); function __construct($url, $db) { $this->base = $url; @@ -34,17 +35,29 @@ function __construct($url, $db) { */ public function login($login, $password) { $this->cookie = False; // will ask for a new cookie. - $req = $this->authenticate(array( - 'base_location' => $this->base, - 'db' => $this->db, - 'login' => $login, - 'password' => $password, - 'session_id' => "", - )); + $data = array( + 'base_location' => $this->base, + 'db' => $this->db, + 'login' => $login, + 'password' => $password + ); + + $req = $this->authenticate($data); $this->session_id = $req['session_id']; $this->authenticated = $req["uid"] !== False; $this->uid = $req["uid"]; - + + //Get Odoo version + $req = $this->get_version_info(); + if (floatval($req["server_serie"]) <= 7.0) + { + $this->legacy = true; + } + else + { + $this->legacy = false; + } + return $this->authenticated; } @@ -101,7 +114,7 @@ function __call($method, $params) { $params = array(); else $params = $params[0]; - if (!array_key_exists("session_id", $params) && isset($this->session_id)) + if ($this->legacy == true && !array_key_exists("session_id", $params) && isset($this->session_id)) $params["session_id"] = $this->session_id; return $this->json($this->base . $url, $params); }