0
我應該怎麼添加到顯示USER_ID和貓正確我應該添加什麼來正確顯示字段的值?
@api.model
def create(self, vals):
record=super(test, self).create(vals)
if vals['total'] > 0:
vals['date'] = fields.Datetime.now()
self.env['journal'].create({
'user_id': record.patient_id,
'cat': record.cat,})
....
.....
樹視圖(日誌):爲test.user(6,)
貓顯示爲cat1
USER_ID
EDITS:
class test(models.Model):
_name = 'test'
cat = fields.Selection(
required=True,
related='test_type_cat.name',
store=True,
)
user_id = fields.Many2one('res.users', string='user', readonly=True,)
.....
@api.model
def create(self, vals):
record=super(test, self).create(vals)
if vals['total'] > 0:
vals['date'] = fields.Datetime.now()
self.env['journal'].create({
'patient_id': record.patient_id.name,
'cat': record.cat,
'user_id': record.user_id.name,
})
record.total = 0
return record
爲什麼它與.NAME工作,而不是.ID? for m2o field should I pass the integer value?如果是這種情況,爲什麼它在.name這裏工作?那麼m2m和o2m呢?
是貓的類型是選擇 – Borealis
'user_id':record.patient_id.id,'而不是'test.user(6,)'它顯示'1'但是'user_id':record.patient_id.name ,'顯示正確的名稱 – Borealis
您是否聲明瞭user_id m2o字段或char? – Cherif