Desarrollo de funciones para la conexión Drupal OpenERP vía web services

Registered by Gabriela Quilarque

Mediante web services (XML-RPC) se realizará la conexión Drupal Openerp, donde se efectuarán las funciones que invocarán los servicios de OpenERP como servidor.
Las funciones a invocar en OpenERP son:
--login
--create
--search
--read

Asimismo se realizarán pruebas de concepto para chequear el correcto funcionamiento de las funciones antes mencionadas.

Blueprint information

Status:
Complete
Approver:
Nhomar - Vauxoo
Priority:
Medium
Drafter:
Nhomar - Vauxoo
Direction:
Approved
Assignee:
Gabriela Quilarque
Definition:
Approved
Series goal:
None
Implementation:
Implemented
Milestone target:
None
Started by
Nhomar - Vauxoo
Completed by
Nhomar - Vauxoo

Related branches

Sprints

Whiteboard

@fecha 23-08
- Funciones Connect, Create, Search, Read, para la conexión Drupal- OpenERP implementadas con éxito en Drupal.

Las Funciones implementadas se muestran a continuación:

@gaby
----------------------
Cuando quieras hacer referencia a un metodo, coloca el link al archivo en el branch puedes explorarlo y referencias desdde que linea a que linea se encuentra, luego de probado
----------------------

//////////////////CONNECT
function connect($server_url,$name_db,$user,$password) {

    if(isset($_COOKIE["user_id"]) == true) {
       if($_COOKIE["user_id"]>0) {
       return $_COOKIE["user_id"];
       }
   }
   $sock = new xmlrpc_client($server_url.'common');
   $msg = new xmlrpcmsg('login');
   $msg->addParam(new xmlrpcval($name_db, "string"));
   $msg->addParam(new xmlrpcval($user, "string"));
   $msg->addParam(new xmlrpcval($password, "string"));
   $resp = $sock->send($msg);
   $val = $resp->value();
   $id = $val->scalarval();
   setcookie("user_id",$id,time()+3600);

   if($id > 0) {
       return $id;
   }else{
       return -1;
   }
 }

//////////////////CREATE
function create($server_url,$name_db,$user,$password)
{
    $bandera=3;
    $relation = "res.partner.function";
    $userId = -1;
    if($userId<=0) {
     $userId = connect($server_url,$name_db,$user,$password);
     }
    $server_url = $server_url.'object';
    $arrayVal = array(
    'name'=>new xmlrpcval('Registro Name', "string") ,
    'code'=>new xmlrpcval('rs123' , "string"),
    'ref'=>new xmlrpcval('r6'321 , "string")
     );
    $client = new xmlrpc_client($server_url);
    $msg = new xmlrpcmsg('execute');
    $msg->addParam(new xmlrpcval($name_db, "string"));
    $msg->addParam(new xmlrpcval($userId, "int"));
    $msg->addParam(new xmlrpcval($password, "string"));
    $msg->addParam(new xmlrpcval($relation, "string"));
    $msg->addParam(new xmlrpcval("create", "string"));
    $msg->addParam(new xmlrpcval($arrayVal, "struct"));
    $resp = $client->send($msg);
    if ($resp->faultCode())
    {
        $bandera = 0;
    }
    else
    {
        $bandera = 1;
    }
    return $bandera;
}

//////////////////SEARCH
function search($server_url,$name_db,$user,$password,$relation,$key)
{
     $userId = -1;
     if($userId<=0) {
        $userId = connect($server_url,$name_db,$user,$password);
     }
     $server_url = $server_url.'object';
     $client = new xmlrpc_client($server_url);
     $msg = new xmlrpcmsg('execute');
     $msg->addParam(new xmlrpcval($name_db, "string"));
     $msg->addParam(new xmlrpcval($userId, "int"));
     $msg->addParam(new xmlrpcval($password, "string"));
     $msg->addParam(new xmlrpcval($relation, "string"));
     $msg->addParam(new xmlrpcval("search", "string"));
     $msg->addParam(new xmlrpcval($key, "array"));
     $resp = $client->send($msg);
     $val = $resp->value();

     $id_array = php_xmlrpc_decode($val); //ooo
     $tamano = count($id_array);
     $ids = $val->scalarval();
    return $ids;
}

//////////////////READ
function read($server_url,$name_db,$user,$password,$relation,$id,$key)
{
    $userId = -1;
    if($userId<=0) {
     $uid = connect($server_url,$name_db,$user,$password);
     }

    $server_url = $server_url.'object';
    $sock= new xmlrpc_client($server_url);
    $msg=new xmlrpcmsg('execute');
    $msg->addParam(new xmlrpcval($name_db, "string"));
    $msg->addParam(new xmlrpcval($uid, "int"));
    $msg->addParam(new xmlrpcval($password, "string"));
    $msg->addParam(new xmlrpcval($relation, "string"));
    $msg->addParam(new xmlrpcval("read", "string"));
    $msg->addParam(new xmlrpcval($id, "array"));
    $msg->addParam(new xmlrpcval($key, "array"));
    $resp = $sock->send($msg);

    if ($resp->faultCode()) {
        drupal_set_message(t('Fallo en Read del registro'.'Error: '.$resp->faultString()."\n"));
    } else {
        $val=$resp->value();
        $ids=$val->scalarval();
        $id_array = php_xmlrpc_decode($val);
    }
    return $id_array;
}

(?)

Work Items

Dependency tree

* Blueprints in grey have been implemented.

This blueprint contains Public information 
Everyone can see this information.

Subscribers

No subscribers.