Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

How can I pass customs ids to 'datas'

By
Yakito
on 7/3/13, 4:49 PM 1,233 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

0

Felipe

--Felipe--
962
| 5 3 8
Bogotá, Colombia
--Felipe--
Informatics engineer Industrial engineer
Felipe
On 7/3/13, 5:03 PM

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!

Yakito
on 7/3/13, 5:13 PM

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!

Yakito
on 7/3/13, 5:20 PM

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

0 follower(s)

Stats

Asked: 7/3/13, 4:49 PM
Seen: 1233 times
Last updated: 3/16/15, 8:10 AM