4
votes

I have a code that fetches some information on the Internet and returns it as a Python list. I want to display (without saving in the database) in Odoo tree view.

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. So, what field type is there for me to use or any other solution?

1

1 Answers

2
votes

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.

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.

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