I have got a python code which searches records from one model and writes them to a one to many field in another model the problem is that my code is printing the records twice as in it duplicates each record what might be the issue here is my code.Kindly Assist
@api.one
def load_defaults_two(self):
self.ensure_one()
part_two_company_objs = self.env['kpi.objectives.part'].search([])
for items in part_two_company_objs:
self.write({
'part_order_line': [(0, 0, {
'product_id': items.id,
'individual_score': 0,
'unit_price': 0,
'management_score': 0,
})],
})
Have you tried by writing directly on the foreign table?
remote_record_id = self.env['your.second.table'].create({
'product_id': items.id,
'individual_score': 0,
'unit_price': 0,
'management_score': 0,
})
self.part_order_line += remote_record_id