如何存储和显示多个相关数据字段Odoo

时间:2017-12-20 12:21:56

标签: python openerp odoo-10

我有书和作者模型。我在作者模型中创建了Many2many字段。当点击作者的名字时,我想显示该作者的书籍。在我的代码中,我只能看到上次出版的书。但是我希望看到每本书。我怎样才能做到这一点?

Author.py

_name = 'about.author'
_inherits = {'res.partner': 'partner_id'}

# Relation with Book
book_ids = fields.Many2many(
'about.book'
)

book_names = fields.Char('Books of The Author', related='book_ids.name',store=True,multi=True)

Author.xml

 <?xml version="1.0" encoding="UTF-8"?>
<odoo>
   <data>
      <!-- Views -->
      <record model="ir.ui.view" id="about_author_form_view">
         <field name="name">about.author.form</field>
         <field name="model">about.author</field>
         <field name="inherit_id" ref="base.view_partner_form" />
         <field name="arch" type="xml">
            <data>
               <xpath expr="//field[@name='category_id']" position="after">
                  <field name="is_book_author" />
               </xpath>
            </data>
         </field>

      </record>
      <!-- Action -->
      <record model="ir.actions.act_window" id="about_author_list_action" >
         <field name="name">Author</field>
         <field name="book_names" >Author Books</field>
         <field name="res_model">about.author</field>
         <field name="view_mode">tree,form</field>

      </record>
      <!-- Menu -->
      <menuitem id="author_menu" name="Authors" parent="top_menu" action="about_author_list_action" />
   </data>
</odoo>

1 个答案:

答案 0 :(得分:0)

操作移动<field name="book_names" >Author Books</field>视图的记录标记内解决了问题。现在,我可以看到作者的所有书籍。