在 Odoo 11 中输入 _rec_name 两个字段的组合
Put in _rec_name a combination of two fields in Odoo 11
您好,我有以下型号:
# -*- coding: utf-8 -*-
from odoo import models, fields, api
class myclass(models.Model):
_name = 'myproject.myclass'
_rec_name = 'field1'
field1= fields.Char('Field1', size=64, required=True)
field2= fields.Char('Field2', size=64, required=True)
field3= fields.Char('Field3', size=64, required=True)
def name_get(self, cr, uid, ids, context=None):
res = []
fields= self.browse(cr, uid, ids, context)
for field in fields:
res.append((field .id, field.field1+ ' ' + field.field2))
return res
问题是 Odoo 只打印 _rec_name
中的字段,即 'field1'
.
我在以下地方测试解决方案:
您应该坚持新的 API 并尝试坚持一些编码准则。两个非常明显的东西是 class 名称和变量名称 field
,它是业务对象记录而不是字段。
class MyClass(models.Model):
_name = 'myproject.myclass'
_rec_name = 'field1'
field1 = fields.Char('Field1', size=64, required=True)
field2 = fields.Char('Field2', size=64, required=True)
field3 = fields.Char('Field3', size=64, required=True)
@api.multi
def name_get(self):
res = []
for record in self:
res.append((record.id, "%s %s" % (record.field1, record.field2)))
return res
您好,我有以下型号:
# -*- coding: utf-8 -*-
from odoo import models, fields, api
class myclass(models.Model):
_name = 'myproject.myclass'
_rec_name = 'field1'
field1= fields.Char('Field1', size=64, required=True)
field2= fields.Char('Field2', size=64, required=True)
field3= fields.Char('Field3', size=64, required=True)
def name_get(self, cr, uid, ids, context=None):
res = []
fields= self.browse(cr, uid, ids, context)
for field in fields:
res.append((field .id, field.field1+ ' ' + field.field2))
return res
问题是 Odoo 只打印 _rec_name
中的字段,即 'field1'
.
我在以下地方测试解决方案:
您应该坚持新的 API 并尝试坚持一些编码准则。两个非常明显的东西是 class 名称和变量名称 field
,它是业务对象记录而不是字段。
class MyClass(models.Model):
_name = 'myproject.myclass'
_rec_name = 'field1'
field1 = fields.Char('Field1', size=64, required=True)
field2 = fields.Char('Field2', size=64, required=True)
field3 = fields.Char('Field3', size=64, required=True)
@api.multi
def name_get(self):
res = []
for record in self:
res.append((record.id, "%s %s" % (record.field1, record.field2)))
return res