Odoo 中文社区

    • 注册
    • 登录
    • 搜索
    • 版块
    • 标签
    • 热门
    • 用户
    • 群组

    Odoo中文社区可以通过以下两个域名访问:shine-it.net , odoo.net.cn

    由于系统升迁的原因,本论坛部分较早期的内容存在格式和链接损坏失效的问题,并非本论坛系统本身的缺陷,望谅解

    本社区没有维护任何QQ群讨论组,任何与本社区同名的QQ群讨论组的言论与本社区无关!

    开发人员可以登录gitter讨论组: http://gitter.im/odoo-china/Talk, 需要github账号

    如果您登录系统碰到问题,请在微信公众号留言:

    [分享]view xml 中的 button 调用web客户端事件

    Odoo 开发与实施交流
    4
    6
    9910
    正在加载更多帖子
    • 从旧到新
    • 从新到旧
    • 最多赞同
    回复
    • 在新帖中回复
    登录后回复
    此主题已被删除。只有拥有主题管理权限的用户可以查看。
    • mrshelly
      mrshelly 最后由 编辑

      最近写一个模块 需要 在客户端干点事.
      按常规的方法, 应该是写个 客户端模块. 在 客户端 init, start, render 去渲染个按钮出来干事.暂时还不太理解WEB模块如何很好地同服务器端通讯.

      所以, 还是使用传统的OE server 模块来干这事.
      OE 提供 ir.actions.client (客户端事件) 来让服务端与 客户端进行事件交互.

      所以, 只需要在 view xml 中. 添加个 button 并调用服务端事件, 然后 服务端返回一个 ir.actions.client 事件给客户端即可. 不知道哪位大大有更好的办法

      <br />....<br />&nbsp; &nbsp; &nbsp; &nbsp;  &lt;button name=&quot;act_start&quot; type=&quot;object&quot; string=&quot;Start&quot;/&gt;<br />....<br />
      



      然后 在对象中定义该对象 act_start  方法

      <br />....<br />&nbsp; &nbsp; def act_start(self, cr, uid, ids, context=None):<br />&nbsp; &nbsp; &nbsp; &nbsp; ret = {<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &#039;type&#039;: &#039;ir.actions.client&#039;,<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &#039;tag&#039;: &#039;my_sample.bt_start&#039;,<br />&nbsp; &nbsp; &nbsp; &nbsp; }<br />&nbsp; &nbsp; &nbsp; &nbsp; return ret<br />....<br />
      



      然后 在 模块JS文件中, 去定义JS部分的对象

      <br />....<br />openerp.my_sample = function (instance) {<br />&nbsp; &nbsp; instance.web.client_actions.add(&#039;my_sample.bt_start&#039;, &#039;instance.my_sample .btn_start&#039;);<br />&nbsp; &nbsp; instance.my_sample.btn_start = function(parent, action){<br />&nbsp; &nbsp; &nbsp; &nbsp; var self = this;<br />&nbsp; &nbsp; &nbsp; &nbsp; alert(&#039;test&#039;);<br />&nbsp; &nbsp; &nbsp; &nbsp; // and do something...<br />&nbsp; &nbsp; &nbsp; &nbsp; return false;<br />&nbsp; &nbsp; };<br />};<br />....<br />
      



      这时候. 不出异常. 点击 按钮即可调用 btn_start 方法了...

      1 条回复 最后回复 回复 引用 0
      • R
        rufeng1199 最后由 编辑

        我也在关注  tag的作用,oe在这部分完全没介绍啊

        1 条回复 最后回复 回复 引用 0
        • L
          l315276651 最后由 编辑

          [quote author=l315276651 link=topic=14690.msg28138#msg28138 date=1401933677]
          目前我也遇到了这样的问题 ,
          我是通过 添加 html的input标签
          然后用js调用Python方法,
          但感觉很怪 ,你这样的方式 不错 ,只是有一个问题,
          怎么传递参数呢 如 ids
          [/quote]

          目前我也遇到了这样的问题 ,
          我是通过 添加 html的input标签
          然后用js调用Python方法,
          但感觉很怪 ,你这样的方式 不错 ,只是有一个问题,
          怎么传递参数呢 如 ids

          =============================================
          传递参数已经解决,代码如下

          instance.my_sample.btn_start = function(parent, action){<br />&nbsp; &nbsp; &nbsp; &nbsp; var self = this;<br />&nbsp; &nbsp; &nbsp; &nbsp; //id<br />&nbsp; &nbsp; &nbsp; &nbsp; action.context.active_id<br />&nbsp; &nbsp; &nbsp; &nbsp; //ids<br />&nbsp; &nbsp; &nbsp; &nbsp; action.context.active_ids<br />&nbsp; &nbsp; &nbsp; &nbsp; //_name<br />&nbsp; &nbsp; &nbsp; &nbsp; action.context.active_model<br />&nbsp; &nbsp; &nbsp; &nbsp; // 更多参数 请查看相关文档 或 用js调试 自行发掘<br />&nbsp; &nbsp; &nbsp; &nbsp; alert(&#039;test&#039;);<br />&nbsp; &nbsp; &nbsp; &nbsp; // and do something...<br />&nbsp; &nbsp; &nbsp; &nbsp; return false;<br />&nbsp; &nbsp; };
          


          =============================================
          自定义参数 传递方式 :

          <br />def act_start(self, cr, uid, ids, context=None):<br />&nbsp; &nbsp; &nbsp; &nbsp; context={}<br />&nbsp; &nbsp; &nbsp; &nbsp; context[&quot;key&quot;]=&quot;value&quot;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />&nbsp; &nbsp; &nbsp; &nbsp; ret = {<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &#039;type&#039;: &#039;ir.actions.client&#039;,<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &#039;tag&#039;: &#039;lcd_video.btnPerview&#039;,<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &#039;context&#039;:context,<br />&nbsp; &nbsp; &nbsp; &nbsp; }<br />&nbsp; &nbsp; &nbsp; &nbsp; return ret<br />
          
          1 条回复 最后回复 回复 引用 0
          • mrshelly
            mrshelly 最后由 编辑

            赞.................

            1 条回复 最后回复 回复 引用 0
            • D
              d_yang 最后由 编辑

              我是在wizard执行的最后一步来执行client action的。
              client action return false, wizard不会关闭的。

              可以

              <br /> return {&#039;type&#039;: &#039;ir.actions.act_window_close&#039;};<br />
              


              problem solved.

              1 条回复 最后回复 回复 引用 0
              • First post
                Last post