Ir al contenido
Menú
Se marcó esta pregunta
2 Respuestas
4448 Vistas

I've defined a related field like

vat= fields.Char(related='partner_id.vat', readonly="False")

then in form definition 

<field name="vat" force_save="True" readonly="False"/>

When I enter edit mode on the form, I can modify the value, but when I hit "save", the value goes back to the old value.


Which is the correct way to do it ?


Avatar
Descartar
Mejor respuesta

Hi..,
By default, the value of the related field is not stored in the database. If you want to store it you need to define attribute store with value True.


class YourModel(models.Model):

    _name = 'your.model'

    

    partner_id = fields.Many2one('res.partner')

    vat= fields.Char(related='partner_id.vat', store="True")

Avatar
Descartar
Mejor respuesta

Hi
Please try the following code,

vat= fields.Char(related='partner_id.vat',store=True,readonly=False)

To store the edited value in a related field, you need to store it.

Hope it helps

Avatar
Descartar