This question has been flagged
1 Reply
3725 Views

Hello,

I am very new with OpenERP and I been trying to make a report to work. Finally I discover that context.get('active_ids', []) was returning nothing and thats part of the reason my report was not working.

Is there anyway I can pass "custom" ids to datas. Lets say I know the ID in the database and its 22 how can I give it to datas to test if it works?

I tried appending 22 but I keep getting an error like the following:

except_osv: (u'<LongTable@0x7F191831AAB8 0 rows x unknown cols>... must have at least a row and column

My code looks like the following

def print_report(self,cr,uid,ids,context):
    if context is None:
        context = {}

    datas = {'ids': context.get('active_ids', [])}
    datas['model'] = 'sim.prov'
    res = self.read(cr, uid, ids, context=context)
    res = res and res[0] or {}
    datas['form'] = res
    return {
        'type': 'ir.actions.report.xml',
        'report_name': 'sim.prov',
        'datas': datas,
    }

Any tip much appreciated

Avatar
Discard
Best Answer

In your example datas is a dictionary {}, 'ids' inside datas is a list [], if you want to append ids to the ids list do this:

datas = {'ids': context.get('active_ids', [])+[22,21]}

I would not recommend to use constant id numbers in the code, you could use the search function or other alternatives, but that is your decision.

Avatar
Discard
Author

Thanks, yes this is just for testing proposes. Unfortunately when I add you code I still get the "must have at least a row and column" error. I checked 1000 times if the table with that name (sim.prov) has records and it does. I am not sure what I am doing wrong. Anyway thanks for the help!

Author

OH I found the error was referring to the RML file and not to the .py file...its odd but as soon as I added a table to the RML file everything is working! Thanks for the inspiration!