I assumed that the read method returns a list of dictionaries (records) which are then directly displayed by the list view or form view but that does not seem to be the case. I have this very simple python object defined as follows:
class time_periods(osv.osv):
def read(self, cr, uid, ids, fields=None, context=None, load='_classic_read'):
res = super(time_periods, self).read(cr, uid, ids, fields=fields, context=context, load='_classic_read')
#res is empty at this point since the underlying table is empty
#I want to display completely new data (same fields though) in the list view
res = [{'name': 'Test', 'id':1}, {'name': 'Test 2', 'id':2}]
print res
return res
_name = 'time.periods'
_columns = {
'name': fields.char('Name', size=50),
}
time_periods()
currently the corresponding table in the OpenERP database is empty but I assumed that the hardcoded list(res) would act as records retrieved from the database however the list view still renders enpty.
As an experiment, I created a record with id = 2, name = "Test"
in the database and the tree view showed one record but with name = "Test 2"
as defined in the list(res).
The idea is to replace the list(res) with data retrived from an external database through xmlrpc call.
So, how does the read method work exactly?
Thank You.
EDIT
Just to make my problem clearer, the time_periods table in the OpenERP database is empty so the super call to the read method returns an empty list. What I want to do is display data (from another database but with same fields as the python object) in OpenERP even when the local database is empty. So, essentially I want to intercept the data source of the list view and attach my own data in it not simply make changes to existing data since there is no data.
Try to format your code, I think that you're replaced the content of res, use two variables res1 and res2 and display them with print :)
use res.get(NAME_OF_FIELD) to get values from res
It doesn't matter that I override the content of res since res is an empty list by default (the table is empty) I want to display new records entirely at run time despite there being no data in the OpenERP database.
Hope this will helps: https://learnopenerp.blogspot.com/2021/09/restrict-user-to-access-differnt-records-by-changing-id-in-url-odoo.html