跳至内容
菜单
此问题已终结
1 回复
4605 查看

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

形象
丢弃
最佳答案

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.

形象
丢弃
编写者

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!

编写者

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!

相关帖文 回复 查看 活动
1
10月 23
2281
10
5月 15
17680
1
9月 20
4497
0
6月 19
2551
0
10月 24
1743