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

Dear,

I have many2one field that always saves null value on change of bom_id field, knowing that x.product_tmpl_id.id is not null

product_templ_id = fields.Many2one(
comodel_name='product.template', check_company=True, ondelete='cascade', store=True, readonly=False
)

@api.onchange('bom_id')
def _onchange_bom_id(self):
for rec in self:
lst = []
for x in rec.bom_id.bom_line_ids:
values = {
'product_templ_id': x.product_tmpl_id.id,
'company_id': rec.env.company.id,
'product_qty': x.product_qty,
}
lst.append(values)

rec.lines = [(5, 0, 0)]
if lst:
rec.lines = [(0, 0, x) for x in lst]
Awatar
Odrzuć
Najlepsza odpowiedź

Hi,

Seems you are writing to a readonly field from the onchange function, so you might have to set the force_save="1" attribute along with the field definition in the xml. Can you add this and see.

Reference: Write Value To Read-only Field From On-change Using Force Save Attribute

Thanks

Awatar
Odrzuć
Autor

Thank you dear it works