Hi I have the following model:
# -*- 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
The problem is that Odoo only print the field in _rec_name
, ie, 'field1'
.
I test solutions in:
concatenate firstname and lastname and fill into name field in odoo
You should stick to the new API and also try to stick to some coding guidelines. Two very obvious things are the class name and the variable name field
which is a business object record and not a 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