Odoo Help


[9.0]Field attribute default: how to assign the value of another field as default?

Ermin Trevisan
on 11/16/16, 6:09 AM 635 views

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?


display_name = fields.Char(string='Display Name', default=name, translate=True)
On 11/16/16, 7:42 AM


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)) ?

Ermin Trevisan
on 11/16/16, 8:51 AM
On 8/22/17, 11:55 AM

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)

About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)


Asked: 11/16/16, 6:09 AM
Seen: 635 times
Last updated: 8/22/17, 11:55 AM