跳转至内容
  • 版块
  • 标签
  • 热门
  • 用户
  • 群组
皮肤
  • 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 开发与实施交流
12 帖子 2 发布者 6.2k 浏览
  • 从旧到新
  • 从新到旧
  • 最多赞同
登录后回复
此主题已被删除。只有拥有主题管理权限的用户可以查看。
  • J 离线
    J 离线
    jerry79
    写于 最后由 编辑
    #1

    目前想实现一个功能,点击按钮弹出一个新窗口,教程上的例子,在xml文件的button name那里指定action,不太符合我的要求,我希望做到的是如下:
    py文件:

    <br />def button_event()<br />&nbsp; &nbsp; status=XX&nbsp;  <br />&nbsp; &nbsp; if status=true<br />&nbsp; &nbsp; &nbsp;  XXX<br />&nbsp; &nbsp; else<br />&nbsp; &nbsp; &nbsp;  pop_window()&nbsp; &nbsp; &nbsp; <br />
    



    XML文件

    <br />&lt;record model=&quot;ir.actions.act_window&quot; id=&quot;action_my_action&quot;&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;field name=&quot;name&quot;&gt;My Action&lt;/field&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;field name=&quot;res_model&quot;&gt;my.class&lt;/field&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;field name=&quot;view_type&quot;&gt;form&lt;/field&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;field name=&quot;view_mode&quot;&gt;form&lt;/field&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;field name=&quot;view_id&quot; ref=&quot;view_my_action&quot;/&gt;<br />&lt;/record&gt;<br /><br />&lt;button name=&quot;button_event&quot; string=&quot;Event&quot;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; states=&quot;draft,open&quot; type=&quot;object&quot;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; icon=&quot;gtk-media-pause&quot; /&gt;<br />
    



    如上述代码,点击button的时候,触发的是button_event函数,这个函数中有一个判断,满足条件才会弹出一个窗口,否则做其他的事情,而弹出窗口的函数pop_window(),现在遇到了问题,我要弹出的是view_my_action这个view,所用的代码如下:

    <br />data_obj = self.pool.get(&#039;ir.model.data&#039;)<br />data_id = data_obj._get_id(cr, uid, &#039;my.class&#039;, &#039;action_my_action&#039;)<br />
    


    则系统提示:No references to my.class.action_my_action
    请问在pop_window函数中,如何才能与action_my_action或者view_my_action关联使之能够弹出呢?
    非常感谢!

    1 条回复 最后回复
    0
    • digitalsatoriD 离线
      digitalsatoriD 离线
      digitalsatori 管理员
      写于 最后由 编辑
      #2
      data_id = data_obj._get_id(cr, uid, &#039;my.class&#039;, &#039;action_my_action&#039;)
      


      上面的代码中‘my.class'的位置应该是你的模块的名字,而不是model name

      另外,你本意可能是使用 [tt]get_object_reference[/tt]函数,该函数返回的是指定xml_id所对应的资源对象的model(即数据库表)和res_id(表中的记录号)

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

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

        非常感谢digitalsatori,那行代码改成模块名字后,没有提示错误了,但是那个该死的窗口死活也不出来,请再帮忙看看是什么问题。非常感谢。

        <br />def pop_window(self, cr, uid, ids, context=None):<br />&nbsp;  mod_obj = self.pool.get(&#039;ir.model.data&#039;) <br />&nbsp;  form_res = mod_obj.get_object_reference(cr, uid, &#039;my_module_name&#039;, &#039;action_my_action&#039;) <br />&nbsp;  form_id = form_res and form_res[1] or False<br />&nbsp;  value = {<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &#039;name&#039;: _(&#039;Name&#039;),<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &#039;view_type&#039;: &#039;form&#039;,<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &#039;view_mode&#039;: &#039;form&#039;,<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &#039;res_model&#039;: &#039;my.class&#039;,<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &#039;views&#039;: [(form_id, &#039;form&#039;)],<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &#039;type&#039;: &#039;ir.actions.act_window&#039;,<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  }<br />&nbsp;  return value<br /><br />def button_event(self, cr, uid, ids, *args):<br />&nbsp;  self.pop_window(cr, uid, ids, None)<br />
        
        1 条回复 最后回复
        0
        • digitalsatoriD 离线
          digitalsatoriD 离线
          digitalsatori 管理员
          写于 最后由 编辑
          #4

          你的form_res取到的是一个action id, 事实上你希望得到的是一个view id, 改成如下:

          form_res = mod_obj.get_object_reference(cr, uid, &#039;my_module_name&#039;, &#039;view_my_action&#039;)
          



          并且在返回字典中添加:

          &#039;target&#039;: &#039;new&#039;
          

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

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

            非常感谢,但是这样做也还是弹不出来窗口,我把我的思路再梳理一下,麻烦请帮忙看看是否还有其他地方出错了,非常感谢。
            新建一个模块,文件夹名称:my_module_name,其中有my_module_name.py 和 my_module_name_view.xml

            py文件:my_class类中有button_event和pop_window两个函数,其中button_event函数需要调用pop_window。在pop_window函数中,关联了xml定义的view_my_action这个form,希望能弹出这个form的窗口。

            <br />class my_class(osv.osv):<br />&nbsp; &nbsp; _name=&quot;my.class&quot;<br />&nbsp; &nbsp; _columns={<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  &#039;name&#039;: fields.char(&#039;名称&#039;, size=128, required=True), <br />&nbsp; &nbsp; }<br /><br />&nbsp;  def pop_window(self, cr, uid, ids, context=None):<br />&nbsp; &nbsp; &nbsp; mod_obj = self.pool.get(&#039;ir.model.data&#039;) <br />&nbsp; &nbsp; &nbsp; form_res = mod_obj.get_object_reference(cr, uid, &#039;my_module_name&#039;, &#039;view_my_action&#039;) <br />&nbsp; &nbsp; &nbsp; form_id = form_res and form_res[1] or False<br />&nbsp; &nbsp; &nbsp; value = {<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &#039;name&#039;: _(&#039;Name&#039;),<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &#039;view_type&#039;: &#039;form&#039;,<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &#039;view_mode&#039;: &#039;form&#039;,<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &#039;res_model&#039;: &#039;my.class&#039;,<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &#039;views&#039;: [(form_id, &#039;form&#039;)],<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &#039;type&#039;: &#039;ir.actions.act_window&#039;,<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &#039;target&#039;: &#039;new&#039;,<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  }<br />&nbsp; &nbsp; &nbsp; return value<br />&nbsp; &nbsp; <br />&nbsp; &nbsp; def button_event(self, cr, uid, ids, *args):<br />&nbsp; &nbsp; &nbsp; &nbsp; self.pop_window(cr, uid, ids, None)<br />my_class()<br />
            



            XML文件:有my_class_form_view和view_my_action这两个form,其中my_class_form_view是主form,上面有一个button,关联函数button_event,希望通过这个按钮,能弹出view_my_action这个form。

            <br />&lt;record id=&quot;view_my_action&quot; model=&quot;ir.ui.view&quot;&gt;<br />&nbsp; &nbsp; &lt;field name=&quot;name&quot;&gt;my.class.form1&lt;/field&gt;<br />&nbsp; &nbsp; &lt;field name=&quot;model&quot;&gt;my.class&lt;/field&gt;<br />&nbsp; &nbsp; &lt;field name=&quot;type&quot;&gt;form&lt;/field&gt;<br />&nbsp; &nbsp; &lt;field name=&quot;arch&quot; type=&quot;xml&quot;&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;form string=&quot;Button Action&quot;&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;field name=&quot;name&quot;/&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;/form&gt;<br />&nbsp; &nbsp; &lt;/field&gt;<br />&lt;/record&gt;<br /><br />&lt;record id=&quot;my_class_form_view&quot; model=&quot;ir.ui.view&quot;&gt;<br />&nbsp; &nbsp; &lt;field name=&quot;name&quot;&gt;my.class.form&lt;/field&gt;<br />&nbsp; &nbsp; &lt;field name=&quot;model&quot;&gt;my.class&lt;/field&gt;<br />&nbsp; &nbsp; &lt;field name=&quot;type&quot;&gt;form&lt;/field&gt;<br />&nbsp; &nbsp; &lt;field name=&quot;arch&quot; type=&quot;xml&quot;&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;form string=&quot;弹窗&quot;&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;button name=&quot;button_event&quot; string=&quot;pop&quot;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; states=&quot;open,draft,pending&quot; type=&quot;object&quot;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; icon=&quot;gtk-go-up&quot; /&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;/form&gt;<br />&nbsp;  &lt;/field&gt;<br />&lt;/record&gt;<br />
            
            1 条回复 最后回复
            0
            • digitalsatoriD 离线
              digitalsatoriD 离线
              digitalsatori 管理员
              写于 最后由 编辑
              #6

              定义了my.class Model定义_columns了吗, 另外 'target': 'new' 加 了吗?
              有什么错误信息?

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

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

                定义了columens了,target:new也增加了,没有错误信息。程序里面设置的是点了这个按钮,弹出窗口,然后state,也就是阶段变成变成下一阶段。现在阶段变了,但是窗口没有弹出来。

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

                  这样交流有点累,每次只挤一点信息给我。不知道你在上面贴的那个

                   &#039;target&#039;: new
                  

                  , 和你实际的代码是否一致,应该是[quote]'target':'new'[/quote]

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

                  1 条回复 最后回复
                  0
                  • J 离线
                    J 离线
                    jerry79
                    写于 最后由 编辑
                    #9

                    非常抱歉,我已经把4楼的代码重新核对过了,现在应该没有问题了。
                    另外,我又做了测试,发现如果在xml的button那里直接调用pop_window是可以弹出窗口的,调用button_event却不行,那么应该说明是button_event里面的调用代码:self.pop_window(cr, uid, ids, None) 这句出了问题。
                    请问是否这样的调用是不允许的,或者语法上有其他错误吗?
                    非常感谢!

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

                      试试这样:

                      def button_event(self, cr, uid, ids, *args):<br />&nbsp; &nbsp; return self.pop_window(cr, uid, ids, None)<br />
                      

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

                      1 条回复 最后回复
                      0
                      • J 离线
                        J 离线
                        jerry79
                        写于 最后由 编辑
                        #11

                        非常感谢,这样做可以了。

                        1 条回复 最后回复
                        0

                        • 登录

                        • 没有帐号? 注册

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