简体   繁体   English

计算字段作为Odoo 10中的列表

[英]Computed field as a list in Odoo 10

I have a code that fetches some information on the Internet and returns it as a Python list. 我有一个代码,可以在Internet上获取一些信息并将其作为Python列表返回。 I want to display (without saving in the database) in Odoo tree view. 我想在Odoo树视图中显示(不保存在数据库中)。

For this, I created a computed field as follow: 为此,我创建了一个计算字段如下:

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

When the tree view is rendered it display a single row with all the data in it. 渲染树视图时,它会显示一行,其中包含所有数据。 This is not the way I want. 这不是我想要的方式。

I want to display each single data in the list in its own row. 我想在列表中显示每个单独的数据。 I believe for this to happen I must not use fields.Char() as the field type. 我相信要发生这种情况我不能使用fields.Char()作为字段类型。 So, what field type is there for me to use or any other solution? 那么,我可以使用哪种字段类型或任何其他解决方案?

To show it in the tree you must insert the data in a table i mean you need to insert data row by row use a TransienModel for this because odoo will delete the rocords after some times. 要在树中显示它,你必须在表中插入数据我的意思是你需要逐行插入数据使用TransienModel,因为odoo将在一段时间后删除rocords。

tree view will always execute a selecct on your table (Model) to fetch data if you insert all your result in one field this means you inserted the records in one record. 如果将所有结果插入到一个字段中,则树视图将始终在您的表(模型)上执行选择以获取数据,这意味着您将记录插入到一​​个记录中。

so try this logic may help you: 所以尝试这个逻辑可以帮助你:

fetch your data. 获取您的数据。

insert your data using odoo create method or insert into using cursor (self.env.cr) for performance because create method will do a lot of uneeded work. 使用odoo create方法插入数据或插入使用cursor(self.env.cr)来提高性能,因为create方法会做很多不必要的工作。

then open a tree view with a special domain to show only the inserted records. 然后打开一个带有特殊域的树视图,仅显示插入的记录。

@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': []
   }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM