Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
2 Odpowiedzi
4511 Widoki

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 ?


Awatar
Odrzuć
Najlepsza odpowiedź

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

Awatar
Odrzuć
Najlepsza odpowiedź

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

Awatar
Odrzuć