【问题标题】:How to validate a Odoo delivery order with XMLRPC PHP?如何使用 XMLRPC PHP 验证 Odoo 交付订单?
【发布时间】:2017-05-30 11:15:52
【问题描述】:

如何使用 xmlrpc 将交货单设置为“完成”?

我正在使用

$client->write('stock.move', array(58), ['state' => "done"]);

它确实有效,但不会更新手头数量,只有预测数量会更新。

有没有办法从 PHP 调用 exec_workflow

【问题讨论】:

    标签: php xml-rpc odoo-9


    【解决方案1】:

    我最近在为 Odoo 11 开发 PHP XMLRPC 端点时遇到了同样的问题,我偶然发现了这篇文章和其他一些更早的文章,但没有一个回答的问题足够详细,可以为我提供一个工作解决方案。也就是说,这就是我最终解决您遇到的问题的方法(设置交货单状态或“完成”并更新现有数量)。

    我的解决方案需要两个 API 调用,而不是一个,您将需要 stock.picking id 和任何相关的 stock.move id。我还创建了一个名为 OdooXmlrpc 的简单类来处理对 Odoo 的 XMLRPC 调用。我假设您已经做了同样的事情,因为您的代码 sn-p 似乎正在调用您的 $client 对象上的方法。我将在下面包含我的类方法以供参考。

    现在是代码 sn-ps。使用 PHP,我做的第一件事是为拣货中的每个产品/项目设置 stock.move 的“quantity_done”字段,因为这是用于更新现有数量的字段。您不必为 stock.picking 或 stock.move 记录设置 state 字段,当我们调用第二个 execute_kw 函数时,Odoo 会设置它们。

    // first we update the stock.move qty done
    $update_move_data = array(array($move['id']), array('quantity_done' => $move['product_qty']));
    $update_move = $xmlrpc_client->write('stock.move', $update_move_data);
    

    或者将你的语法与一些虚拟数据一起使用

    $xmlrpc_client->write('stock.move', array(58), ['quantity_done' => 50]);
    

    接下来,我调用我在类中创建的名为“call_function”的通用方法来处理交货单传输。此类方法将接受 Odoo 模型和方法。理论上,我可以将此类方法用于任何 CRUD 操作,但我保留所有非基于 CRUD 的操作的用法,因为参数会有所不同 - 仍在进行中,但目前看来很有用。

    // next we process the picking so its gets marked as done and qty on hand gets adjusted
    $picking_do_transfer = $xmlrpc_client->call_function('stock.picking', 'do_transfer', array($picking['id']));
    

    就是这样!交货单状态现在是“完成”,并且系统中的现有数量应该已正确更新。

    请注意,使用这种“do_transfer”方法,Odoo 将自动为任何没有设置 quantity_done 值的项目/移动创建延期交货,我发现这非常有用。希望此回复对您和任何其他偶然发现它的用户有所帮助。

    我的 OdooXmlrpc 类方法供参考:

    /**
    * Write the records respective to the IDs and field value pairs provided
    *
    * @param        (string) $model, the Odoo model to be used in the call
    * @param        (array) $domain, a multi-dim array of record ids and a mapping of updated fields to values
    *
    * @return       (int) $ret, 1 when operation was successful
    */
    function write($model, $domain) {
        if (!isset($model) || !isset($domain)) {
            print "Missing params...";
            return;
        }
        // our odoo method
        $method = 'write';
        $ret = $this->client->execute_kw($this->database, $this->id, $this->password, $model, $method, $domain);
        return $ret;
    }
    
    /** !NOTE! EXPERIMENTAL: NOT SURE WORKS WITH ALL ODOO MODELS
    * Call the model function with IDs and/or field values to run/update with
    *
    * @param        (string) $model, the odoo model to be used in the call
    * @param        (array) $method, the name of the model method to call
    * @param        (array) $args, an array of id(s) or records to modify
    *
    * @return       (int) $ret, 1 when operation was successful
    */
    function call_function($model, $method, $args) {
        if (!isset($model) || !isset($method) || !isset($args)) {
            print "Missing params...";
            return;
        }
        $ret = $this->client->execute_kw($this->database, $this->id, $this->password, $model, $method, $args);
        return $ret;
    }
    

    【讨论】:

      【解决方案2】:

      你必须通过model namerecord idsignal name

      client->exec_workflow('stock.move', array(58), signal_name);
      

      来自odoo9 on github

      @http.route('/web/dataset/exec_workflow', type='json', auth="user")
      def exec_workflow(self, model, id, signal):
          return request.session.exec_workflow(model, id, signal)
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-05-07
        • 2021-11-25
        • 2017-09-02
        • 1970-01-01
        • 2020-11-14
        • 2017-07-22
        相关资源
        最近更新 更多