Skip to Content
Menu
You need to be registered to interact with the community.
This question has been flagged
1 Odgovori
2828 Prikazi

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]
Avatar
Opusti
Best Answer

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

Avatar
Opusti
Avtor

Thank you dear it works