2017-07-15 97 views
4

我有一个代码可以在Internet上获取一些信息并将其作为Python列表返回。我想在Odoo树视图中显示(不保存在数据库中)。作为Odoo 10中的列表计算的字段

对于这一点,我创建了一个计算字段如下:

created_time = fields.Char(compute='_compute_created_time') 

@api.multi 
def _compute_created_time(self): 
    my_data = self.my_internet_data() 
    created_time_list = [] 

    for created_times in my_data: 
     created_time_list.append(created_times['created_time']) 

    self.created_time = created_time_list 

当树视图被呈现,就可以显示单个行与它的所有数据。这不是我想要的。

我想显示列表中的每一个单独的数据在自己的行。我相信为此发生,我不能使用fields.Char()作为字段类型。那么,我使用哪种字段类型或者其他解决方案?

回答

2

到树显示它您需要在表格 我的意思是,你需要插入的行进行数据行使用TransienModel这个 因为odoo将一些次后删除rocords插入数据。

树视图会一直执行你的桌子上(模型)一个selecct如果插入所有的结果在一个领域,这意味着你在一个记录插入 记录来获取数据 。

所以试试这个逻辑可能会帮助你:

获取你的数据。

插入数据使用odoo创建方法或插入到使用游标(self.env.cr)的性能,因为创建方法会做很多不必要的工作。

然后打开一个带有特殊域的树视图,只显示插入的记录。

@api.multi 
def show_result(self): 
    #1- fetch data 
    #2- insert data. 
    #3- return window action 
    return { 
     'type': 'ir.actions.act_window', 
     'name': '...' 
     'res_model': 'your.transienModel.name', 
     .. 
     .. 
     .. 
     # special filter here to show only the inserted recrods 
     # like date or search parameters. 
     'domain': [] 
    } 
+0

谢谢你。只是使用create方法创建每个记录并运行良好。 –

+0

但这就是我建议的 – Cherif

+0

是的。解决方案基于你的答案。 –