跳转至内容
  • 版块
  • 标签
  • 热门
  • 用户
  • 群组
皮肤
  • 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. One2many 明细搜索的问题

One2many 明细搜索的问题

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

    系统自带的模块sales包含了一个one2many类型的order line订单明细,现在有一个需求,就是在sales的主界面上方的搜索区域可以来搜索order line明细的内容。
    仿sales和order line做了一个自己的类,如下:

    <br />#这个类定义常用的产品名称,如手机,电脑,平板等<br />class other_class(osv.osv):<br />&nbsp; &nbsp; _name = &#039;detail.class&#039;<br />&nbsp; &nbsp; _columns = {<br />&nbsp; &nbsp; &nbsp; &nbsp; &#039;name&#039;: fields.char(&#039;产品名称&#039;),<br />&nbsp; &nbsp; }<br /><br />#这个类是订单明细,其中name字段是many2one,可以选择设置好的产品名称<br />class detail_class(osv.osv):<br />&nbsp; &nbsp; _name = &#039;detail.class&#039;<br />&nbsp; &nbsp; _columns = {<br />&nbsp; &nbsp; &nbsp; &nbsp; &#039;name&#039;: fields.many2one(&#039;other.class&#039;,&#039;产品&#039;),<br />&nbsp; &nbsp; &nbsp; &nbsp; &#039;qty&#039;:fields.char(&#039;数量&#039;),<br />&nbsp; &nbsp; &nbsp; &nbsp; &#039;detail_id&#039;: fields.many2one(&#039;main.class&#039;, &#039;产品&#039;, ondelete=&#039;cascade&#039;, select=True, readonly=True),&nbsp; &nbsp; &nbsp; &nbsp; <br />&nbsp; &nbsp; }<br />&nbsp; &nbsp; _order = &#039;name&#039;<br />detail_class()<br /><br />#这个类是订单类,包含一个明细项,用来显示这个订单中所包含的产品<br />class main_class()<br />&nbsp; &nbsp; _columns={<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &#039;detail_line&#039;: fields.one2many(&#039;detail.class&#039;, &#039;detail_id&#039;, &#039;产品&#039;),<br />&nbsp; &nbsp; &nbsp; }<br />main_class()<br /><br />#这里是xml代码,用来在main class界面顶部的搜索区域定义一个可以搜索产品明细的字段<br /> &lt;record id=&quot;view_main_class_filter_extend&quot; model=&quot;ir.ui.view&quot;&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;field name=&quot;name&quot;&gt;main.class.select1&lt;/field&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;field name=&quot;model&quot;&gt;main.class&lt;/field&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;field name=&quot;type&quot;&gt;search&lt;/field&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;field name=&quot;arch&quot; type=&quot;xml&quot;&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  &lt;field name=&quot;detail_line&quot; string=&quot;产品&quot;/&gt;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;/field&gt;<br />&lt;/record&gt;<br />
    


    如上述代码所示,最终在main class顶部搜索区域,出现一个编辑框,如果在其中输入“手机”,则可以搜索出所有包含“手机”这个产品明细的订单。这是一个比较简化的实现。
    现在我还有一个进一步的需求,即我希望搜索区域出现的不是一个编辑框(char),而是一个下拉列表框(selection),而且这个下拉列表框中显示的是我在other.class中定义的产品名称。也就是说,我已经定义了诸如“手机,电脑,平板”等产品名称,而用户搜索的时候,直接可以在下拉框中选择,而不是手工输入“手机”,请问这样应该如何来做呢?

    1 条回复 最后回复
    0
    • mrshellyM 离线
      mrshellyM 离线
      mrshelly
      写于 最后由 编辑
      #2

      强制 search view 的 field 的 widget 为 "selection" 即可.

      个人推荐 many2one
      因为 many2one 即可以选择, 又可以输入.

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

        非常感谢,不过直接改成selection,下拉框里面出来的是other_class.id 而不是name,看来我需要修改一下name search 了。

        1 条回复 最后回复
        0

        • 登录

        • 没有帐号? 注册

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