Odoo Help


custom report parser with custom method from an other model [v9 enterprise]

Pascal Bergmann
on 11/4/16, 6:54 PM 247 views

I'm trying to make a custom report parser following Axel Mendoza's post here (https://www.odoo.com/de_DE/forum/hilfe-1/question/how-to-define-a-custom-methods-functions-to-be-used-in-a-qweb-report-how-to-define-and-use-a-report-parser-92244).

It's not quite working for me, and i'd appreciate help  and advice on this. I am using odoo 9 enterprise.

What i want to achieve: on a custom website with events (from event.event), i want to print a pdf file with a registration form.  In this form, i am using data that come from a custom function that has been added to a model inheriting 'website'.

I'm getting this error:

"old_api() takes at least 3 arguments (2 given)" while evaluating"event_details('o.id')['product_ver_nr']"

I am not sure how

Structure of module:

|--controllers                                                                                                                                                                --main.py
     --event_fax.xml                                                                                                                                                  |--models                                                                                                                                                                    --report_parser.py


Each web page shows only one event and its id is shown in the url. I wrote an own controller in the main.py from the folder controllers to get the id of the event on the current page.

This is the content of the report in even_fax.xml:

<report id="fax_event" model="event.event" string="Anmeldeformular" report_type="qweb-pdf" name="tra_event.event_fax" file="tra_event.event_fax" />                                                                                                                                                                                                                                                <template id="tra_event.event_fax">                                                                                                                 <t t-name="tra_event.event_fax"> <div class="page"> <t t-foreach="docs" t-as="o">                           Seminar: <span t-field="o.name"/>                                                                                                                   <br/> Sem.-Nr.: <span t-esc="event_details('o.id')['product_ver_nr']"/>                                                        </t></div></t>

in this case, 'o' is the content of event.event, and i am able to print a report accessing only the standard odoo fields in event.event. It means that if i comment out the line <span t-esc="event_details('o.id')['product_ver_nr']"/>,  the report is printed. If i don't comment it out, i get the error mentionned above.

This is the controller(in main.py):

@http.route(['/event/print/<event_id>'], type='http', auth="public", website=True) def event_print(self, event_id, **post):
        cr, uid, context = request.cr, SUPERUSER_ID, request.context if event_id:
        pdf = request.registry['report'].get_pdf(cr, uid, [int(event_id)], 'tra_event.event_fax',         data=None, context=context) pdfhttpheaders = [('Content-Type', 'application/pdf'), ('Content-Length', len(pdf))] return request.make_response(pdf, headers=pdfhttpheaders) else:
            return request.redirect('/event') return request.redirect('#')

and this is the parser (in report_parser.py):

from openerp.report import report_sxwfrom openerp import api, models
class registrationform_report_parser(report_sxw.rml_parse):
 def __init__(self, cr, uid, name, context):
       super(registrationform_report_parser, self).__init__(cr, uid, name, context=context)      self.localcontext.update({ 'event_details': self._get_event_details, })

def _get_event_details(self, event_id):     

       data = self.pool.get('website').get_event_details(event_id) return data

Firstly, i'm not sure how to call my custom function get_event_details from the file website.py in the folder models in my custom module. Is that the only part where i did a mistake, or did i do something wrong somewhere else in the code?

Pascal Bergmann
On 11/5/16, 10:22 AM

the function get_event_details is defined as new api with the decorator @api.models, i think that's what's causing the problem. so, how do i call my method properly?

if i just put an own dictionary named data in the parser and return it, i can access its elements in the report with  <span t-esc="event_details(o.id)['key']/>.  It means that the parser is working correctly and the problem lays within the calling of the method "get_event_details". Do someone know how to call a method written in new api from the parser?

i got it, i forgot to write "self.cr, self.uid" while calling the function:

def _get_event_details(self, event_id):

data = self.pool.get('website').get_event_details(self.cr, self.uid, event_id)

return data

Auditum AG, Pascal Bergmann
on 11/7/16, 3:10 AM

About This Community

This platform 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.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)


Asked: 11/4/16, 6:54 PM
Seen: 247 times
Last updated: 11/5/16, 10:22 AM