Odoo 10 JAVA api?
-
你理解错了,除了基本的对象的CRUD操作,Odoo所有的业务逻辑都可以通过xml-rpc/json-rpc来调用,包括报表,工作流等。如果你愿意完全可以用java写一个自己的客户端。
-
#创建rpc客户端对象models,所有的api调用都要通过models,url是你的Odoo host地址 final XmlRpcClient models = new XmlRpcClient() {{ setConfig(new XmlRpcClientConfigImpl() {{ setServerURL(new URL(String.format("%s/xmlrpc/2/object", url))); }}); }}; #所有的远程函数调用都是通过 `execute_kw`调用接口 , 后面都是其调用参数,而实际的 #效果是execute_kw将远程客户端的调用分派(dispatch)并最终执行对象为"sale.order"的“create”函数,并将之后的列表作为参数传递给create函数 final Integer id = (Integer)models.execute("execute_kw", asList( db, uid, password, "sale.order", "create", asList(new HashMap() {{ put("partner_id", 1); }}) ));
请参见代码中的说明,上面的java代码远程创建了一个空的销售订单。你可以改变操作对象(当前是‘sale.order'),改变调用的函数(比如用
action_confirm
用来确认订单,对象上所有的非私有函数都可以远程调用),或者改变调用函数中所传递的参数,这样就可以执行你希望执行的任何操作了。希望对你有帮助。
-
再向您请教一个问题,order_line里面的信息我应该怎么送进去呢?比如我想建一个有两个item的order,按下面的格式送进去好像不对,谢谢
final Integer id = (Integer) models.execute("execute_kw", asList(
db, Integer.parseInt(uid), password,
"sale.order", "create",
asList(new HashMap() {
{
put("origin", 0);
put("message_follower_ids", 0);
put("order_line", asList(new HashMap() {
{
put("product_id",7);
put("product_uom",7);
put("price_unit",100);
put("product_uom_qty",1);
}
{
put("product_id",4);
put("product_uom",1);
put("price_unit",50);
put("product_uom_qty",1);
}
}));
put("partner_id", 1);
put("carrier_id", 1);
put("team_id", 1);
put("client_order_ref", 0);
}
})
)); -
@tetsu
代码中的说明,应该能看得懂吧:~odoo.fields.One2many
and~odoo.fields.Many2many
use a special "commands" format to manipulate the set of records stored in/associated with the field.This format is a list of triplets executed sequentially, where each triplet is a command to execute on the set of records. Not all commands apply in all situations. Possible commands are:
(0, _, values)
adds a new record created from the providedvalue
dict.(1, id, values)
updates an existing record of idid
with the values invalues
. Can not be used in :meth:~.create
.(2, id, _)
removes the record of idid
from the set, then deletes it (from the database). Can not be used in :meth:~.create
.(3, id, _)
removes the record of idid
from the set, but does not delete it. Can not be used on~odoo.fields.One2many
. Can not be used in :meth:~.create
.(4, id, _)
adds an existing record of idid
to the set. Can not be used on :class:~odoo.fields.One2many
.(5, _, _)
removes all records from the set, equivalent to using the command3
on every record explicitly. Can not be used on :class:~odoo.fields.One2many
. Can not be used in :meth:~.create
.(6, _, ids)
replaces all existing records in the set by theids
list, equivalent to using the command5
followed by a command4
for eachid
inids
.Note: Values marked as
_
in the list above are ignored and can be anything, generally0
orFalse
.