تخطي للذهاب إلى المحتوى
القائمة
لقد تم الإبلاغ عن هذا السؤال
1 الرد
4322 أدوات العرض

my need is to make a table update ie when I click to apply 'get_teachers' it does a search and add the teachers in the One2many, in my case he does the research but he does not suppress the recent records 

I need replace previous references 

    teacher_ids = fields.One2many('school.teacher', 'course_id', string='Teacher')

    def get_teachers (self):
        lesson = self.env['school.lesson'].search([])

        teacher_list = []  
        for rec in lesson:
            if rec.course_id.id == self.id:
                print(rec.teacher_id.name)

                teacher_list.append([0,0,{
                                    'teacher_name':  rec.teacher_id.id,  
                                    'lesson_id': rec.id,
                                }])
        print('teacher_list',teacher_list)
        self.write({'teacher_ids' : teacher_list})
        return 

I found that

(6, 0, [IDs])          replace the list of linked IDs (like using (5) then (4,ID) for each ID in the list of IDs)

but I do not know how used in my method

الصورة الرمزية
إهمال
أفضل إجابة

add this line before self.write({'teacher_ids' : teacher_list})

self.teacher_ids = False

الصورة الرمزية
إهمال
المنشورات ذات الصلة الردود أدوات العرض النشاط
2
فبراير 20
12110
3
أكتوبر 23
8536
1
سبتمبر 23
3215
1
مايو 23
2180
2
أبريل 23
2692