Search code examples
pythonxmlodoowkhtmltopdfodoo-8

Odoo How to make custom report, AttributeError


I'm trying to make a custom report. I used this documentation https://www.odoo.com/documentation/8.0/reference/reports.html and looked at the add-on "sale" to have an exemple of report. I wanted to do a first test so I used the minimal viable template of the documentation.

Here is my template

<?xml version="1.0" encoding="utf-8"?>
<openerp>
    <data>
            <template id="report_demand_document">
                    <t t-call="report.html_container">
                            <t t-foreach="docs" t-as="o">
                                    <t t-call="report.external_layout">
                                            <div class="page">
                                                    <h2>Propositions</h2>
                                                    <p>Vote du <span t-field="o.date"/></p>
                                            </div>  
                                    </t>
                            </t>
                    </t>
            </template>
    </data>
</openerp>

Here is the report call

<?xml version="1.0" encoding="utf-8"?>
<openerp>
    <data>
            <report
                    id="report_demand"
                    string="Propositions en cours"
                    model="report"
                    report_type="qweb-pdf"
                    name="report.report_demand"
                    file="report.report_demand"
                    attachment="'Propositions' + str(object.date) +'.pdf'"/>
    </data>
</openerp>

And I get this error :

AttributeError: 'report' object has no attribute '_check_wkhtmltopdf'

The full log if needed :

Traceback (most recent call last):
File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 540, in _handle_exception
    return super(JsonRequest, self)._handle_exception(exception)
File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 577, in dispatch
    result = self._call_function(**self.params)
File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 313, in _call_function
    return checked_call(self.db, *args, **kwargs)
File "/usr/lib/python2.7/dist-packages/openerp/service/model.py", line 118, in wrapper
    return f(dbname, *args, **kwargs)
File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 310, in checked_call
    return self.endpoint(*a, **kw)
File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 806, in __call__
    return self.method(*args, **kw)
File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 406, in response_wrap
    response = f(*args, **kw)
File "/usr/lib/python2.7/dist-packages/openerp/addons/report/controllers/main.py", line 143, in check_wkhtmltopdf
    return request.registry['report']._check_wkhtmltopdf()
AttributeError: 'report' object has no attribute '_check_wkhtmltopdf'

I searched for "_check_wkhtmltopdf" on google but found nothing about it in Odoo neither did I find any occurence of my error on it. What does that error mean? Do I have to install something? (I'm using Odoo-8)


Solution

  • If i see it correct, then you've overriden the Odoo model/class report, which handles all the stuff for rendering documents, etc.

    <report
        id="report_demand"
        string="Propositions en cours"
        model="report"
        report_type="qweb-pdf"
        name="report.report_demand"
        file="report.report_demand"
        attachment="'Propositions' + str(object.date) +'.pdf'"/>
    

    Here you define the report on model report. Other examples will show you values like sale.order or account.invoice on its report definitions.

    Please don't declare a new ORM model report. Just use another name like test.report or something like that.

    Let's talk about undoing this mistake: change the attribute _name on your test model and restart the server. And of course change your report definition to the new model name. Now update your module. That should do the trick.