Skip to Content
Menu
This question has been flagged
4 Replies
13488 Rodiniai

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)
Portretas
Atmesti
Best Answer

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>

Portretas
Atmesti
Autorius

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

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

Best Answer

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)

Portretas
Atmesti
Related Posts Replies Rodiniai Veikla
1
geg. 22
4307
1
rugp. 19
4231
1
gruod. 21
6657
0
spal. 21
3293
1
spal. 21
4115