我的自定义模型中有以下字段,名为accounting_heads.elementary_head
sub_heads = fields.Many2one('accounting_heads.sub_heads',domain = "[('heads', '=', heads)]", string= 'Sub Heads')尽管与Many2one模型有一个accounting_heads.sub_heads关系,但它显示的是accounting_heads.accounting_heads模型的记录。
为什么?
以下是我的模特:
from odoo import models, fields, api
class accounting_heads(models.Model):
_name = 'accounting_heads.accounting_heads'
_rec_name = 'heads'
heads = fields.Char()
class sub_heads(models.Model):
_name = 'accounting_heads.sub_heads'
_inherit = 'accounting_heads.accounting_heads'
heads = fields.Many2one('accounting_heads.accounting_heads', string= 'Heads')
sub_heads= fields.Char(string ='Sub Heads')
class elementary_heads(models.Model):
_name = 'accounting_heads.elementary_head'
_inherits = {'accounting_heads.accounting_heads': 'heads',
'accounting_heads.sub_heads' : 'sub_heads',
}
heads = fields.Many2one('accounting_heads.accounting_heads', string='Heads')
sub_heads = fields.Many2one('accounting_heads.sub_heads',domain = "[('heads', '=', heads)]", string= 'Sub Heads')
elementary_heads = fields.Char(string = 'Elementary Head')以下是我的观点:
<record model="ir.ui.view" id="accounting_heads.elementary_form">
<field name="name">Form</field>
<field name="model">accounting_heads.elementary_head</field>
<field name="arch" type="xml">
<form >
<field name="heads" string="Head"/>
<field name="sub_heads" string="Sub Head"/>
<field name="elementary_heads" string="Elementary Head"/>
</form>
</field>
</record>发布于 2018-12-21 10:32:49
我猜问题在于您没有在name模型中创建任何字段sub_heads,因此Many2one字段sub_heads的显示名称默认为heads字段的值。
尝试在accounting_heads.sub_heads模型/类中添加以下代码:
@api.multi
def name_get(self):
result = []
for sub_head in self:
result.append((sub_head.id, sub_head.display_name))
return result
@api.multi
@api.depends('sub_heads')
def _compute_display_name(self):
for sub_head in self:
sub_head.display_name = sub_head.sub_heads其他更快的选项是在相同的模型/类中添加以下一行:
_rec_name = 'sub_heads'https://stackoverflow.com/questions/53879650
复制相似问题