0

Good day to all. Trying to make custom ODOO 11 report to save it to pdf. Report template(w/out any values, just for test purposes)

<?xml version="1.0" encoding="utf-8"?>
<odoo>
    <data>
        <template id="contract_template">
            <t t-call="web.html_container">
                <div class="article">
                    <h2>Report title</h2>
                    <p>Report 01</p>
                </div>
            </t>
        </template>
    </data>
</odoo>

If I call this template from XML like this:

<report
   id="custom_template_1"
   model="res.partner.contract.wizard"
   string="Contract"
   report_type="qweb-pdf"
   name="client_contracts.contract_template"
   file="client_contracts.contract_template"
   menu="False"
/>

And add button to view it works fine - it generate report. But when I'm trying to generate this report with python code:

    def get_pdf_contract(self):
        context = self._generate_context()
        return self.env.ref('client_contracts.contract_template').report_action(self, data=context)

And add button to view:

<button string="Test pdf x" type="object" name="get_pdf_contract" />

When I press this button there is an error:

AttributeError: 'ir.ui.view' object has no attribute 'report_action'

Anyone can give me helping hand with that? Thanx for any help.

Jignasha Royala
  • 1,032
  • 10
  • 27
Asher
  • 39
  • 1
  • 7

3 Answers3

1

Found solution. For anyone, who get same error/trouble - solution. Just skip the

return self.env.ref('client_contracts.contract_template').report_action(self, data=context)

part, and replace it with

return {'type': 'ir.actions.report','report_name': 'client_contracts.contract_template','report_type':"qweb-pdf",'data': context,}

where context - previously generated dict of values, that need to be passed to template. client_contract - name of module, conrtact_template - name of template

Asher
  • 39
  • 1
  • 7
0

replace

return self.env.ref('client_contracts.contract_template').report_action(self, data=context) 

with

return self.env.ref('client_contracts.custom_template_1').report_action(self, data=context) 

means

return self.env.ref('module.report id').report_action(self,data=context)
Zoe
  • 27,060
  • 21
  • 118
  • 148
Liya
  • 1
0

The solution to this stack overflow question link, works fine.

To note: the report_id referenced below should refer to the report where you have declared name of report and type and file ... and not the template_id.

return self.env.ref('module_name.report_id').report_action(self, data=context)

Eric
  • 940
  • 12
  • 27