Перейти к содержимому
Меню
Чтобы взаимодействовать с сообществом, необходимо зарегистрироваться.
Этот вопрос был отмечен
2 Ответы
4516 Представления

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 ?


Аватар
Отменить
Лучший ответ

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

Аватар
Отменить
Лучший ответ

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

Аватар
Отменить