Skip ke Konten
Menu
Pertanyaan ini telah diberikan tanda
2 Replies
4478 Tampilan

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
Buang
Jawaban Terbai

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
Buang
Jawaban Terbai

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
Buang