如何使用 XMLRPC PHP 验证 Odoo 交付订单? [英] How to validate a Odoo delivery order with XMLRPC PHP?
问题描述
如何使用 xmlrpc 将交货单设置为完成"?
How can I set delivery order to state "done" with xmlrpc?
我正在使用
$client->write('stock.move', array(58), ['state' => "done"]);
它确实有效,但它不会更新手头数量,只会更新预测数量.
It does work but it does not update on hand quantity, only forecast quantity is getting updated.
有没有办法从 PHP 调用 exec_workflow
?
Is there any way to call exec_workflow
from PHP?
推荐答案
我最近在处理 Odoo 11 的 PHP XMLRPC 端点时遇到了同样的问题,我偶然发现了这篇文章和其他一些更老的文章,但都没有他们以足够的细节回答了这个问题,可以为我提供一个可行的解决方案.也就是说,这就是我为解决您遇到的问题而最终采取的措施(设置交货订单状态或完成"并更新现有数量).
I recently encountered the same issue when working on a PHP XMLRPC endpoint for Odoo 11 and I stumbled across this post and a few other even older posts, but none of them answered the question with enough detail that could provide me with a working solution. That said, here is what I ended up doing to solve the problem you were having (set the delivery order state or "done" and update the quantity-on-hand).
我的解决方案需要两个 API 调用而不是一个,您将需要 stock.picking
id 和任何相关的 stock.move id(s).我还创建了一个名为 OdooXmlrpc 的简单类来处理对 Odoo 的 XMLRPC 调用.我假设您已经做了同样的事情,因为您的代码片段似乎正在调用 $client 对象上的方法.我将在下面包含我的类方法以供参考.
My solution requires two API calls instead of just one, and you will need the stock.picking
id and any related stock.move id(s). I also created a simple class called OdooXmlrpc to handle the XMLRPC calls to Odoo. I am assuming you have done the same thing since your code snippet appears to be calling methods on your $client object. I’ll include my class methods below for reference.
现在是代码片段.使用 PHP,我做的第一件事是为拣配中的每个产品/项目设置 stock.move 的quantity_done"字段,因为这是用于更新现有数量的字段.您不必为 stock.picking 或 stock.move
记录设置 state 字段,Odoo 将在我们调用第二个 execute_kw 函数时设置它们.
Now for the code snippets. Using PHP, the first thing I did was set the ‘quantity_done’ field of the stock.move for each product/item in the picking because that is the field used for the quantity-on-hand update. You do not have to set the state field for the stock.picking or the stock.move
records, Odoo will set those when we call the second execute_kw function.
// 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);
或者将你的语法与一些虚拟数据一起使用
Or using your syntax with some dummy data
$xmlrpc_client->write('stock.move', array(58), ['quantity_done' => 50]);
接下来,我调用在我的类中创建的名为call_function"的通用方法来处理交货单转移.这个类方法将接受一个 Odoo 模型和方法.理论上,我可以将这个类方法用于任何 CRUD 操作,但我保留所有非基于 CRUD 的操作的用法,因为参数会有所不同 - 仍在进行中,但似乎很有用,目前有效.
Next, I call a generic method that I created in my class called 'call_function' to process the delivery order transfer. This class method will accept an Odoo model and method. In theory, I could use this class method for any CRUD operations, but I reserve the usage for all non-CRUD based operations since params will vary – still a work in progress but seems useful and works for now.
// 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']));
就是这样!交货单状态现在是完成",在手数量应该在系统中正确更新.
That’s it! the delivery order state is now "done," and the quantity-on-hand should have updated correctly in the system.
注意使用这个do_transfer"方法,Odoo 将自动为任何没有设置quantity_done 值的项目/移动创建延期交货,我发现这非常有用.希望此回复对您和任何其他偶然发现的用户有所帮助.
Note that using this "do_transfer" method, Odoo will create a backorder automatically for any item/move that did not have a quantity_done value set, which I found to be very useful. Hope this response helps you and any other users that stumble across it.
我的 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;
}
这篇关于如何使用 XMLRPC PHP 验证 Odoo 交付订单?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!