跳转至内容
  • 版块
  • 标签
  • 热门
  • 用户
  • 群组
皮肤
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • 默认(Flatly)
  • 不使用皮肤
折叠

Odoo 中文社区

  1. 主页
  2. 版块
  3. Odoo 开发与实施交流
  4. Odoo 10 JAVA api?

Odoo 10 JAVA api?

已定时 已固定 已锁定 已移动 Odoo 开发与实施交流
9 帖子 2 发布者 5.0k 浏览
  • 从旧到新
  • 从新到旧
  • 最多赞同
登录后回复
此主题已被删除。只有拥有主题管理权限的用户可以查看。
  • T 离线
    T 离线
    tetsu
    写于 最后由 编辑
    #1

    各位好,我想请问一下有没有java能用的api?我查了一下好像很多人都直接写sql,感觉这样也许会出现数据不一致的问题,不知道还有没有别的好办法?我的版本是odoo 10,谢谢各位。

    1 条回复 最后回复
    0
    • digitalsatoriD 离线
      digitalsatoriD 离线
      digitalsatori 管理员
      写于 最后由 编辑
      #2

      看这里:https://www.odoo.com/documentation/10.0/api_integration.html

      【上海先安科技】(tony AT openerp.cn)

      1 条回复 最后回复
      0
      • T 离线
        T 离线
        tetsu
        写于 最后由 编辑
        #3

        感谢回复!这个我看过了,感觉还是在做数据库table的操作,我想知道有没有类似business function这种封装好的方法可以调用,比如我想建立一个sales order,直接把所需的参数传进去之后就直接可以在相应的数据库table里插入数据(sales,inventory还有invoice之类),不用再自己做数据库级别的操作了,我是odoo新手,多谢各位大神指点。

        1 条回复 最后回复
        0
        • digitalsatoriD 离线
          digitalsatoriD 离线
          digitalsatori 管理员
          写于 最后由 编辑
          #4

          你理解错了,除了基本的对象的CRUD操作,Odoo所有的业务逻辑都可以通过xml-rpc/json-rpc来调用,包括报表,工作流等。如果你愿意完全可以用java写一个自己的客户端。

          【上海先安科技】(tony AT openerp.cn)

          1 条回复 最后回复
          0
          • T 离线
            T 离线
            tetsu
            写于 最后由 编辑
            #5

            能否提供一个xml-rpc/json-rpc调用odoo业务逻辑的例子呢?比如生成一个最简单的sales order?

            因为我有Oracle JD Edwards的开发经验,Oracle提供很多business functions来实现业务逻辑,不知道odoo是不是也提供类似的function,不用自己写table IO。

            谢谢!

            1 条回复 最后回复
            0
            • digitalsatoriD 离线
              digitalsatoriD 离线
              digitalsatori 管理员
              写于 最后由 digitalsatori 编辑
              #6
              #创建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 用来确认订单,对象上所有的非私有函数都可以远程调用),或者改变调用函数中所传递的参数,这样就可以执行你希望执行的任何操作了。

              希望对你有帮助。

              【上海先安科技】(tony AT openerp.cn)

              1 条回复 最后回复
              0
              • T 离线
                T 离线
                tetsu
                写于 最后由 编辑
                #7

                代码调通了,非常感谢

                1 条回复 最后回复
                0
                • T 离线
                  T 离线
                  tetsu
                  写于 最后由 编辑
                  #8

                  再向您请教一个问题,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);
                  }
                  })
                  ));

                  digitalsatoriD 1 条回复 最后回复
                  0
                  • digitalsatoriD 离线
                    digitalsatoriD 离线
                    digitalsatori 管理员
                    在 回复了 tetsu 最后由 digitalsatori 编辑
                    #9

                    @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 provided value dict.

                    (1, id, values)
                    updates an existing record of id id with the values in values. Can not be used in :meth:~.create.

                    (2, id, _)
                    removes the record of id id from the set, then deletes it (from the database). Can not be used in :meth:~.create.

                    (3, id, _)
                    removes the record of id id 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 id id to the set. Can not be used on :class:~odoo.fields.One2many.

                    (5, _, _)
                    removes all records from the set, equivalent to using the command 3 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 the ids list, equivalent to using the command 5 followed by a command 4 for each id in ids.

                    Note: Values marked as _ in the list above are ignored and can be anything, generally 0 or False.

                    【上海先安科技】(tony AT openerp.cn)

                    1 条回复 最后回复
                    0

                    • 登录

                    • 没有帐号? 注册

                    • 登录或注册以进行搜索。
                    • 第一个帖子
                      最后一个帖子
                    0
                    • 版块
                    • 标签
                    • 热门
                    • 用户
                    • 群组