Odoo 中文社区

    • Register
    • Login
    • Search
    • Categories
    • Tags
    • Popular
    • Users
    • Groups

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

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

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

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

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

    【分享】在form里嵌套tree列表

    Odoo 开发与实施交流
    6
    8
    5172
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • 阿
      阿狸 last edited by

      公司打算让我把日常品质报表整合在OE里,但是form视图不符合公司报表格式,tree视图符合但是tree视图下不可编辑,经过@乌鲁木齐-兰迪的提示,可以用form里嵌套tree视图实现。效果图见附件。
      具体实现方法是:在form视图中插入一个tree视图代码格式如下:

      &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  &lt;form string=&quot;报表表单&quot; version=&quot;7.0&quot;&gt;<br />					&lt;group&gt;<br />						&lt;field name=&quot;name&quot;/&gt;<br />					&lt;/group&gt;<br />					&lt;field name=&quot;smt_qcbaobiao&quot;&gt;<br />						&lt;tree string=&quot;smt_qc&quot; editable=&quot;bottom&quot;&gt;<br />							&lt;field name=&quot;date&quot;/&gt;<br />							&lt;field name=&quot;inspector&quot;/&gt;<br />							&lt;field name=&quot;banbie&quot;/&gt;<br />							&lt;field name=&quot;class&quot;/&gt;<br />							&lt;field name=&quot;model&quot;/&gt;<br />							&lt;field name=&quot;component_number&quot;/&gt;<br />						&lt;/tree&gt;<br />					&lt;/field&gt;<br />				&lt;/form&gt;<br />
      


      可以看到,在form里插入了tree视图。经武汉-茶隼提示,要嵌套tree,必须先把tree嵌套在field里,而且field字段是many2one类型的。上式中用了<field name="smt_qcbaobiao">这个命令定义的,这样视图部分就解决了。
      而定义smt_qcbaobiao字段的代码如下:

      class lc_baobiao_smtceshi(osv.osv):<br />&nbsp; &nbsp; _name = &#039;lc.baobiao.smtceshi&#039;<br />&nbsp; &nbsp; _columns = {<br />&nbsp; &nbsp; &nbsp; &nbsp; &#039;name&#039;:fields.char( u&#039;月份&#039;,size=64,select=True),<br />		&#039;smtceshi_qcbaobiao&#039;:fields.one2many(&#039;lc.baobiao.smtceshishuju&#039;,&#039;smtceshi_qcbaobiao_id&#039;,&#039;smtceshi_qc&#039;),<br />				}<br />lc_baobiao_smtceshi()
      


      用到了one2many,对应的many2one代码如下:

      class lc_baobiao_smtceshishuju(osv.osv):<br />&nbsp; &nbsp; _name = &#039;lc.baobiao.smtceshishuju&#039;<br />&nbsp; &nbsp; _columns = {<br />		&#039;date&#039;:fields.char(u&#039;日期&#039;,size=64,select=True),<br />		&#039;inspector&#039;:fields.char(u&#039;检查员&#039;,size=64,select=True),<br />		&#039;banbie&#039;:fields.char(u&#039;班别&#039;,size=64,select=True),<br />		&#039;class&#039;:fields.char(u&#039;线别&#039;,size=64,select=True),<br />		&#039;model&#039;:fields.char(u&#039;产品型号&#039;,size=64,select=True),<br />	<br />		&#039;smtceshi_qcbaobiao_id&#039;:fields.many2one(&#039;lc.baobiao.smtceshi&#039;,&#039;Invoice Reference&#039;,ondelete=&#039;cascade&#039;,select=True),<br />				}<br />lc_baobiao_smtceshishuju()
      


      至此,算是完成了。 😎
      谢谢期间对我提供技术支持的 @重庆-mrshelly @石家庄-老刘 @广州-步科 @@上海-开阖Jeff @上海-gavin @乌鲁木齐-兰迪 @武汉-茶隼等等。。。谢谢你们!

      另外有个问题要问下,为何要嵌套tree,必须先把tree嵌套在field里,而且field字段必须是many2one类型的。希望解答或补充、改正,谢谢!

      1 Reply Last reply Reply Quote 0
      • X
        xhair last edited by

        我的理解是因为定义的tree的数据来源于嵌入这个tree的字段,也就是说这个字段对应的数据必须是一个集,并且是可以根据这个字段检索出这个tree要显示出的数据集的。

        1 Reply Last reply Reply Quote 0
        • mrshelly
          mrshelly last edited by

          嗯. 这种在 form 视图里 出现 子表的情况 在OE 中灰常常见. 如 常用的 
          purchase.order  采购订单 form 中, 就有  purchase.order.line  的子表 的情况...


          赞.... 学习开发的速度很快.... 👍

          1 Reply Last reply Reply Quote 0
          • Joshua
            Joshua 管理员 last edited by

            谢谢分享,from视图还可以嵌套kanban视图,详情看客户界面。

            【上海先安科技】(joshua AT openerp.cn),欢迎关注公众号:openerp_cn

            1 Reply Last reply Reply Quote 0
            • 阿
              阿狸 last edited by

              [quote author=xhair link=topic=16381.msg28001#msg28001 date=1399965918]
              我的理解是因为定义的tree的数据来源于嵌入这个tree的字段,也就是说这个字段对应的数据必须是一个集,并且是可以根据这个字段检索出这个tree要显示出的数据集的。
              [/quote]
              谢谢解答,另问下嵌套中的那个tree视图中的数据,如上例中的<field name="date"/>想要同时显示在普通的tree中,能直接引用吗?我好像失败了

              1 Reply Last reply Reply Quote 0
              • ieitzyb
                ieitzyb last edited by

                我也用得上,直接填表的感脚

                http://www.OuduPLM.com/ 苏州欧度软件,专注服装行业(鳴謝:37signals,Trello,ProcessON,重庆慧积,上海开阖)

                1 Reply Last reply Reply Quote 0
                • C
                  ccdos last edited by

                  [quote author=阿狸 link=topic=16381.msg28005#msg28005 date=1399975924]要写个函数字段了,确定显示哪一行的date
                  [quote author=xhair link=topic=16381.msg28001#msg28001 date=1399965918]
                  我的理解是因为定义的tree的数据来源于嵌入这个tree的字段,也就是说这个字段对应的数据必须是一个集,并且是可以根据这个字段检索出这个tree要显示出的数据集的。
                  [/quote]
                  谢谢解答,另问下嵌套中的那个tree视图中的数据,如上例中的<field name="date"/>想要同时显示在普通的tree中,能直接引用吗?我好像失败了
                  [/quote]

                  1 Reply Last reply Reply Quote 0
                  • First post
                    Last post