0

我对 Openerp 7.0 有疑问。我想循环一个 one2many 字段。这是我的模型类:

class my_class(osv.osv):
        _name = "my.name"
        _inherit = 'mail.thread'
        _columns = {
                    'partners' : fields.one2many('my.other.class', 'other_id' , 'partner'),
        }
my_class()

class my_other_class(osv.osv)
       _name = 'my.other.class'
       _columns = {
             'type' : fields.char( .... ),
             ....
             'other_id' : fields.many2one('my.class')
      }
my_other_class()

和 XML 部分文件:

<t t-foreach="record.partners.raw_value" t-as="p">
        <div>
                Out:
                <t t-esc="p" />
                <t t-esc="p.type" />
                <t t-esc="p.cid" />
                <t t-esc="p.notification" />
        </div>
</t>

我有多个合作伙伴:

  • ID 类型通知
  • 1 客户真实
  • 2 安装程序真
  • 3 员工虚假

如果我运行代码,它只打印: Out: 12 Out: 13

12,13 是内部 ID

如何在我的 one2many 字段上正确循环?我为 Odoo 8 找到了许多解决方案,但它们在 Openerp 7 中不起作用:/

谢谢你,反松饼

4

1 回答 1

0

You should define a name column in your my.other.class model. If you don't need such a column, you should at least define a _rec_name variable to the column you want to be used instead of name: that's because when you write

<t t-esc="p" />

odoo tries to write the object, but no default is defined, then it writes the internal id.

In your case, try to explicit

<t t-esc="p.id" />

maybe there are some problem in odoo 7 and it doesn't show the other fields.

If this doesn't work you could also try instead:

<t t-esc="p.id +' '+p.type+' '+p.cid+' '+p.notification" />
于 2016-02-12T09:43:13.193 回答