Pular para o conteúdo
Menu
Esta pergunta foi sinalizada
4 Respostas
13539 Visualizações

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)
Avatar
Cancelar
Melhor resposta

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>

Avatar
Cancelar
Autor

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

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

Melhor resposta

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)

Avatar
Cancelar
Publicações relacionadas Respostas Visualizações Atividade
1
mai. 22
4345
1
ago. 19
4260
1
dez. 21
6707
0
out. 21
3315
1
out. 21
4153