Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
1 ตอบกลับ
5068 มุมมอง

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

คำตอบที่ดีที่สุด

Try This one

@api.one

def load_defaults_two(self):

    self.ensure_one()

    part_two_company_objs = self.env['kpi.objectives.part'].search([])

    part_order_line = []

    self.part_order_line.unlink()

    for items in part_two_company_objs:

        part_order_line.append((0, 0, {'product_id': items.id,

                    'individual_score': 0,

                    'unit_price': 0,

                    'management_score': 0,})


    self.write({'part_order_line': part_order_line})

อวตาร
ละทิ้ง
ผู้เขียน

I have tried this but its not working out

Plus you shouldn't use @api.one, it is being phased out for @api.multi with self.ensure_one()

ผู้เขียน

Noted Yenthe

Related Posts ตอบกลับ มุมมอง กิจกรรม
1
พ.ย. 24
19968
How to install odoo 10 in ubuntu 20.04? แก้ไขแล้ว
1
ก.ย. 23
2864
3
พ.ค. 23
5463
7
เม.ย. 23
48771
Barcode scanner from mobile แก้ไขแล้ว
1
ธ.ค. 22
7675