Many2one值在Odoo 9中显示自定义字段值

时间:2016-10-20 05:04:50

标签: odoo-9

我尝试创建一个简单的Many2one字段,但我需要添加自定义列的字段值。

我的代码:

class Partner(osv.Model):

_inherit = 'res.partner'
_rec_name = 'code'

# Add a new column to the res.partner model, by default partners are not
_columns = {
    'code': fields.char('code', index=True),
  }

def name_get(self, cr, uid, ids, context=None):
    if context is None:
        context = {}
    if isinstance(ids, (int, long)):
        ids = [ids]
    res = []
    for record in self.browse(cr, uid, ids, context=context):
        name = record.code
        if record.parent_id and not record.is_company:
            name = "%s, %s" % (record.parent_name, name)
        if context.get('show_address_only'):
            name = self._display_address(cr, uid, record, without_company=True, context=context)
        if context.get('show_address'):
            name = name + "\n" + self._display_address(cr, uid, record, without_company=True, context=context)
        if context.get('show_email') and record.email:
            name = "%s <%s>" % (name, record.email)
        res.append((record.id, name))
    return res


class cst_order(osv.Model):
_name = 'cst.order'
_description = 'CST Orders'
_rec_name = 'code'

_columns = {
    'name_ref': fields.many2one('res.partner', ' Code Name',  required=True,),
    'address_change': fields.boolean('Change Address', ),
}

在我的“name_ref”字段中,我需要一个“代码”而不是“名称”的值 使用_rec_namename_get,但它始终只显示客户名称,而不是我的代码引用。 请有人帮我解决这个问题。

1 个答案:

答案 0 :(得分:0)

did you make sure that your code work well may be is not calling your code at all because of some thing you missed if you overrid the name_get than it should display what you want.did you put the python model in the ini.py see if the framework is calling the new method use debug tools