如何使用php中的xmlrpc在odoo中创建日记条目和项目?

时间:2016-08-05 17:09:30

标签: xml-rpc odoo-8

这是用于创建包含日记项目的日记帐分录的代码。

 //Journal entry creation
 function createJournalEntries($jId, $partnerId, $name, $amount, $ref, $periodId, $check, $date)
 {
    $dAccId = 8;
    $cAccId = 6;
    $name = 'tea';
    $debit = 20;
    $credit = 20;
    $amtCur = 0.00;
    $taxAcc = 15;
    $taxAmt = 2;

    $jlines = array (
                new xmlrpcval(
                array(
                    "name"              => new xmlrpcval($name, "string"),
                    "partner_id"    => new xmlrpcval($partnerId, "int"),
                    "account_id"        => new xmlrpcval($dAccId, "int"),
                    "debit"             => new xmlrpcval(20.00, "float"),
                    "credit"            => new xmlrpcval(0.00, "float")
                )
                ),
                new xmlrpcval(
                array (
                    "name"              => new xmlrpcval($name, "string"),
                    "partner_id"    => new xmlrpcval($partnerId, "int"),
                    "account_id"        => new xmlrpcval($dAccId, "int"),
                    "debit"             => new xmlrpcval(0.00, "float"),
                    "credit"            => new xmlrpcval(20.00, "float")
                )
                )
    );

    $val = array (
        "journal_id"    => new xmlrpcval($jId, "int"),
        "partner_id"    => new xmlrpcval($partnerId, "int"),
        "name"          => new xmlrpcval($name, "string"),
        "amount"        => new xmlrpcval($amount, "float"),
        "ref"           => new xmlrpcval($ref, "string"),
        "peroid_id"     => new xmlrpcval($periodId, "int"),
        "date"          => new xmlrpcval($date, "string"),
        "to_check"      => new xmlrpcval($check, "boolean"),
        "line_id"       => new xmlrpcval($jlines, "array"),
    );
    $module = 'account.move';
    $method = 'create';
    $valu= $this->create($module, $method, $val);

    return $valu;
}

这是创建的主要功能。

  //function for create
  public function create($module, $method, array $values = array()) {

    $this->client->setSSLVerifyPeer(0);


    if (strpos($this->userId, 'LOGIN FAIL:') === false) { 

    try {

       $msg = new xmlrpcmsg('execute');
       $msg->addParam(new xmlrpcval($this->dbname, "string"));
       $msg->addParam(new xmlrpcval($this->userId, "int"));
       $msg->addParam(new xmlrpcval($this->password, "string"));
       $msg->addParam(new xmlrpcval($module, "string"));
       $msg->addParam(new xmlrpcval($method, "string"));
       $msg->addParam(new xmlrpcval($values, "struct"));

       $response = $this->client->send($msg);

       if (!empty($response->faultString())) {

            return  "FAIL: in create:".$response->faultString();
            //return $userId;
        }

       return $response->value()->scalarval();

        } catch (Exception $e) {

            throw new Exception("Create Exception:". $e);
        }
    }else{
        return $this->userId;
    }
}

在这里,我无法通过日记帐分录获取日记项目。

xmlrpc返回错误,如对象错误

1 个答案:

答案 0 :(得分:0)

日记帐分录和项目创建

 /**Journal entry creation**/
 function createJournalEntries($jId, $partnerId, $name, $amount, $ref, $periodId, $check, $date)
 {

    $module = 'account.move';
    $method = 'create';

    $val = array (
        'journal_id'    => new xmlrpcval($jId, 'int'),
        'partner_id'    => new xmlrpcval($partnerId, 'int'),
        'name'          => new xmlrpcval($name, 'string'),
        'amount'        => new xmlrpcval($amount, 'float'),
        'ref'           => new xmlrpcval($ref, 'string'),
        'peroid_id'     => new xmlrpcval($periodId, 'int'),
        'date'          => new xmlrpcval($date, 'string'),
        'to_check'      => new xmlrpcval($check, 'boolean'),
    );

    $valu= $this->create($module, $method, $val);

    /**Journal itmes creation**/
    $module = 'account.move.line';
    $method = 'create';
    $name = 'TOMOTO';

    $line1 = array (
            'name'              => new xmlrpcval($name, 'string'),
            'account_id'        => new xmlrpcval(25, 'int'),
            'ref'               => new xmlrpcval($ref, 'string'),
            'debit'             => new xmlrpcval(10.50, 'double'),
            'credit'            => new xmlrpcval(0.00, 'double'),
            'move_id'           => new xmlrpcval($valu, 'int'),
            'date_created'      => new xmlrpcval($date, 'string'),
            'date'              => new xmlrpcval($date, 'string')
    );

    $this->create($module, $method, $line1);

    $line2 = array (
            'name'              => new xmlrpcval($name, 'string'),
            'account_id'        => new xmlrpcval(8, 'int'),
            'ref'               => new xmlrpcval($ref, 'string'),
            'debit'             => new xmlrpcval(0.00, 'double'),
            'credit'            => new xmlrpcval(10.50, 'double'),
            'move_id'           => new xmlrpcval($valu, 'int'),
            'date_created'      => new xmlrpcval($date, 'string'),
            'date'              => new xmlrpcval($date, 'string')
    );

    $this->create($module, $method, $line2);

    return $valu;
}