تخطي للذهاب إلى المحتوى
القائمة
لقد تم الإبلاغ عن هذا السؤال
4 الردود
13523 أدوات العرض

According to the documentation, it is possible to assign the result of a function as default value of a field. But is it possible to assign the value of another field of the same model as default value?

Example:

display_name = fields.Char(string='Display Name', default=name, translate=True)
الصورة الرمزية
إهمال
أفضل إجابة

Hi,

you can use

@api.onchange('<field whose value to be taken>')

def onchange_func(self):

if self.<field value to be taken>:

self.  <field to which you need value> = self.<field  whose value to be taken>

الصورة الرمزية
إهمال
الكاتب

Thanks for your reply. How would my field definition look like then:

display_name = fields.Char(default=onchange_func(name)) ?

أفضل إجابة

You can achieve that by this one-liner, note though that the value of the other field should be created afore:


display_name = fields.Char(string='Display Name', default=lambda self: self.name, translate=True)

الصورة الرمزية
إهمال
المنشورات ذات الصلة الردود أدوات العرض النشاط
1
مايو 22
4342
1
أغسطس 19
4259
1
ديسمبر 21
6690
0
أكتوبر 21
3312
1
أكتوبر 21
4137