Navigation

    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里面one2many字段怎么显示更多关联的字段?

    Odoo 新手求助
    4
    7
    4527
    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.
    • B
      BraidTim last edited by

      0_1495795679103_0561d962-f822-478b-9002-4a8ca5aac792-图片.png
      例如采购模块,新增产品这儿是从purchase.order通过关系one2many到purchase.order.line模块的
      但是在purchase.order的form输入的时候在view那儿怎么写才能增加purchase.order.line的字段,比如数量,单价等?
      我看purchase源文件似乎也没找到什么特殊表达,我试了试还是访问不到字段,请问有没有简单的实现例子?

      1 Reply Last reply Reply Quote 0
      • S
        Siyuan last edited by

        @BraidTim 在 form里面one2many字段怎么显示更多关联的字段? 中说:

        purchase.order

        xml 文件里面:

                                <field name="order_line">
                                    <tree string="Purchase Order Lines" editable="bottom">
                                        <field name="product_id" context="{'partner_id': parent.partner_id}"/>
                                        <field name="name"/>
                                        <field name="date_planned"/>
                                        <field name="company_id" groups="base.group_multi_company" options="{'no_create': True}"/>
                                        <field name="account_analytic_id" context="{'default_partner_id':parent.partner_id}" groups="purchase.group_analytic_accounting"/>
                                        <field name="product_qty"/>
                                        <field name="qty_received" invisible="not context.get('show_purchase', False)"/>
                                        <field name="qty_invoiced" invisible="not context.get('show_purchase', False)"/>
                                        <field name="product_uom" groups="product.group_uom"/>
                                        <field name="price_unit"/>
                                        <field name="taxes_id" widget="many2many_tags" domain="[('type_tax_use','=','purchase')]" context="{'default_type_tax_use': 'purchase'}"/>
                                        <field name="price_subtotal" widget="monetary"/>
                                    </tree>
        

        😑

        B 1 Reply Last reply Reply Quote 0
        • B
          BraidTim @Siyuan last edited by

          @Siyuan
          这个我也找到位置了,但是没看到那一句写出了关联purchase.order.line这个模块啊
          field name那儿写的是purchase.order模块里面字段吧?下面接tree分析的时候自动就是purchase.order.line的字段吗?我试了试好像还是说找不到字段,应该是还只是在purchase.order模块里面找我写的字段。

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

            @BraidTim 在 form里面one2many字段怎么显示更多关联的字段? 中说:

            @Siyuan
            这个我也找到位置了,但是没看到那一句写出了关联purchase.order.line这个模块啊
            field name那儿写的是purchase.order模块里面字段吧?下面接tree分析的时候自动就是purchase.order.line的字段吗?我试了试好像还是说找不到字段,应该是还只是在purchase.order模块里面找我写的字段。

            首先要理解字段的定义:

            class PurchaseOrder(models.Model):
                _name = "purchase.order"
            ...
            order_line = fields.One2many('purchase.order.line', 'order_id', string='Order Lines', states={'cancel': [('readonly', True)], 'done': [('readonly', True)]}, copy=True)
            

            这里就是purchase.order的order_line字段,这里就声明了和purchase.order.line的关系。然后在视图里面,order_line字段包含的字段就是purchase.order.line的字段

                                    <field name="order_line">
                                        <tree string="Purchase Order Lines" editable="bottom">
                                              <!--这里面是purchase.order.line的字段-->
                                            <field name="product_id" context="{'partner_id': parent.partner_id}"/>
                                            <field name="price_subtotal" widget="monetary"/>
                                        </tree>
            
            萧 1 Reply Last reply Reply Quote 1
            • 萧
              萧云飞 @Joshua last edited by

              @Joshua 👍

              1 Reply Last reply Reply Quote 0
              • B
                BraidTim last edited by

                @Joshua 在 form里面one2many字段怎么显示更多关联的字段? 中说:

                string="Purchase Order Lines" editable="bottom"
                谢谢大神解答,我仔细看了,原来之前写的 field XXX/ 直接关闭了标签才出错的
                然后出现了一个奇怪的问题,我xml写的

                <record model="ir.ui.view" id="meeu_v1.action_window_purchase_material">
                  <field name="name">meeuV1 purchase material form</field>
                  <field name="model">meeu_v1.purchase_material</field>
                  <field name="arch" type="xml">
                    <form>
                      <field name="supplier"/>
                	  <field name="purchase_material_list" >
                		<tree>
                			<field name="name"/>				
                		</tree>
                		</field>
                    </form>
                  </field>
                </record>
                
                <record model="ir.ui.view" id="meeu_v1.action_window_purchase_material">
                  <field name="name">meeuV1 purchase material</field>
                  <field name="model">meeu_v1.purchase_material</field>
                  <field name="arch" type="xml">
                    <tree>
                      <field name="supplier"/>
                	  <field name="purchase_material_list">
                		<tree>
                			<field name="price"/>				
                		</tree>
                		</field>
                    </tree>
                  </field>
                </record>
                

                然后结果
                0_1496226787570_51648f78-362b-4036-ba3c-2815ad6328bd-图片.png
                新建表单不是应该是form吗?怎么写在tree的字段反而出现在新建时候的视图里面?我在新建的时候点击开发者的编辑form视图也显示的
                0_1496228241486_232df405-5966-4377-aa11-107d04503b9c-图片.png
                显示的也是tree
                是不是有什么基础问题我没有注意到?

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

                  我看了下你的代码,你一共定义了2个meeu_v1.purchase_material的视图,一个是表单视图,一个是列表视图。但是列表视图里面是不能直接显示o2m对象里面的属性。所以你列表视图应该改为:

                  <record model="ir.ui.view" id="meeu_v1.action_window_purchase_material">
                    <field name="name">meeuV1 purchase material</field>
                    <field name="model">meeu_v1.purchase_material</field>
                    <field name="arch" type="xml">
                      <tree>
                        <field name="supplier"/>
                  	  <field name="purchase_material_list"/>
                      </tree>
                    </field>
                  </record>
                  
                  1 Reply Last reply Reply Quote 0
                  • First post
                    Last post