如何使用值[ODOO 12]更新One2many列表 [英] how to update One2many list with value [ODOO 12]

查看:68
本文介绍了如何使用值[ODOO 12]更新One2many列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我添加了一种方法来对老师的课程进行研究,然后他在院子里添加课程(该课程有几堂课,每堂课只有一位老师)我的问题是,当我单击该按钮时,它不会更新表格,他在每次单击下方都添加了另一行

I added a method that does a research of the teacher in the lessons then he added in the yard (the course several lesson, each lesson a single teacher) my problem is when I click on the button it does not the table update, he has added another line below each click

这是我的代码

    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 

我发现了

(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

推荐答案

首先放入

self.teacher_ids = [(6, 0, [])]

然后使用

self.write({'teacher_ids' : teacher_list})

它将起作用:

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

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

这篇关于如何使用值[ODOO 12]更新One2many列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆