Skip to content
  • Categories
  • Tags
  • Popular
  • Users
  • Groups
Skins
  • Light
  • Brite
  • 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

  • Default (Flatly)
  • No Skin
Collapse

Odoo 中文社区

  1. Home
  2. Categories
  3. Odoo 新手求助
  4. form里面one2many字段怎么显示更多关联的字段?

form里面one2many字段怎么显示更多关联的字段?

Scheduled Pinned Locked Moved Odoo 新手求助
7 Posts 4 Posters 7.5k Views
  • 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 Offline
    B Offline
    BraidTim
    wrote on last edited by
    #1

    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
    0
    • S Offline
      S Offline
      Siyuan
      wrote on last edited by
      #2

      @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
      0
      • S Siyuan

        @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 Offline
        B Offline
        BraidTim
        wrote on last edited by
        #3

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

        1 Reply Last reply
        0
        • JoshuaJ Offline
          JoshuaJ Offline
          Joshua
          管理员
          wrote on last edited by
          #4

          @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>
          

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

          萧 1 Reply Last reply
          1
          • JoshuaJ Joshua

            @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>
            
            萧 Offline
            萧 Offline
            萧云飞
            wrote on last edited by
            #5

            @Joshua 👍

            1 Reply Last reply
            0
            • B Offline
              B Offline
              BraidTim
              wrote on last edited by
              #6

              @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
              0
              • JoshuaJ Offline
                JoshuaJ Offline
                Joshua
                管理员
                wrote on last edited by
                #7

                我看了下你的代码,你一共定义了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>
                

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

                1 Reply Last reply
                0

                Hello! It looks like you're interested in this conversation, but you don't have an account yet.

                Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

                With your input, this post could be even better 💗

                Register Login
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Tags
                • Popular
                • Users
                • Groups