Skip to Content
Menu
This question has been flagged
2 Replies
3744 Views

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
Discard
Best Answer

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
Discard
Best Answer

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
Discard