This question has been flagged
2 Replies
6747 Views

Someone please help me with render_qweb_pdf() from Odoo. I am a beginner in odoo as well as in XML,

My python code

@api.model
    def print_invoice(self):
        x = 'pawan'
        y = 18
        report = {
            "report": {
                "name": x,
                "roll": y
            }
        }
        # import pdb; pdb.set_trace()
        xx = self.env.ref('fnf_stock.stock_pdf').sudo(
        ).render_qweb_pdf(self.id, report)

        return xx

My XML code
<template id="stock_picking" name="stock_picking">
        <t t-call="web.html_container">
            <t t-as="o" t-foreach="docs">
                <!-- article class is very important to display content -->
                <div class="article">
                    <div class="row">
                            <t t-esc="report['name']"/>
                            <t t-esc="report['roll']"/>
                    </div>
                </div>
            </t>
        </t>
    </template>
Avatar
Discard
Author Best Answer

Hi Niyas,
I think I have used the same as you are suggesting,

<report file="fnf_stock.stock_picking" id="stock_pdf" model="stock.picking" name="fnf_stock.stock_picking" paperformat="fnf_stock.paperformat_mis_report" report_type="qweb-pdf" string="PDF stock"/>
<template id="stock_picking" name="stock_picking">
<t t-call="web.html_container">
<t t-as="o" t-foreach="docs">
<!-- article class is very important to display content -->
<div class="article">
<t t-esc="report['name']"/>
<t t-esc="report['roll']"/>
</div>
</t>
</t>
</template>


Avatar
Discard

try another way,

@api.multi

def print_quotation(self):

self.filtered(lambda s: s.state == 'draft').write({'state': 'sent'})

return self.env.ref('sale.action_report_saleorder')\

.with_context(discard_logo_check=True).report_action(self)

Best Answer

Hi,

In the render_qweb_pdf it seems you have to call the id given in the report tag not the template. See this example in account module,

<report
id="account_invoices"
model="account.move"
string="Invoices"
report_type="qweb-pdf"
name="account.report_invoice_with_payments"
file="account.report_invoice_with_payments"
attachment="(object.state == 'posted') and ((object.name or 'INV').replace('/','_')+'.pdf')"
print_report_name="(object._get_report_base_filename())"
groups="account.group_account_invoice"
/>

Then,

df = self.env.ref('account.account_invoices').render_qweb_pdf(self.id)[0]


Thanks

Avatar
Discard