Search code examples
odooqweb

Blank PDF report from wizard in Odoo


I'm using Odoo17 and I want to print PDF Report from Wizard. The Wizard works fine, when I click on the button that trigger the function to print the PDF it download a blank PDF. To keep things simple, I'm not gonna publish all the code. So basically here are my files :

wizard/wizard_view

<odoo>
   <record id="projet_edit_view_form" model="ir.ui.view">
       <field name='name'>projet.edit.form.view</field>
       <field name='model'>project.pdf.report</field>
       <field name="arch" type="xml">
           <form>
               <field name="info"/>
               <footer>
                   <button name="print_report" type="object" string="export PDF" class="btn btn-primary"/>
                   <button string="Cancel" class="btn-default" special="cancel"/>
               </footer>
           </form>
       </field>
   </record>
</odoo>

wizard/wizard_model

class ModelWizard (models.TransientModel):
   _name = 'project.pdf.report'
   _description='display printed informations'
   
   info= fields.Char()
   
   def print_report(self):
     print(self.env.context)
     data = {
           'model_id': self.id,
           'form': self.env.context
       }

     return self.env.ref('my_addon.action_report_Pdf').report_action(None, data=data)

Then I got my action file :

report/ir_actions_report

<?xml version="1.0" encoding="utf-8"?>
<odoo>
   <record id="action_report_Pdf" model="ir.actions.report">
       <field name="name">My PDF</field>
       <field name="model">project.pdf.report</field>
       <field name="report_type">qweb-pdf</field>
       <field name="report_name">my_addon.my_pdf</field>
       <field name="report_file">my_addon.my_pdf</field>
       <field name="print_report_name">'Name</field>
       <field name="binding_model_id" eval= "False"/>
       <field name="binding_type">report</field>
   </record>
</odoo>

And finally my template:

report/my_pdf

<?xml version="1.0" encoding="utf-8"?>
<odoo>
    <template id="my_pdf">
        <t t-call="web.html_container">
            <t t-foreach="docs" t-as="o">
                <t t-call="web.external_layout">
                    <div class="page">
                        <h2>Sample Report</h2>
                    </div>
                </t>
            </t>
        </t>
    </template>
</odoo>

I must have missed something. When the PDF is download the file got <field name="name"> name instead of <field name="print_report_name">. And page is blank, no header nor footer.

Could you help please ?

Thanks!!


Solution

  • You have set the report_action docids parameter to none and you probably didn't define a custom report parser to set the docs variable and in this case, Odoo will set docs to an empty record set

    You can use variables passed through data and avoid docs or define a custom report parser