简体   繁体   中英

How to add a print a custom report from button in Odoo v11?

I created a custom report in the accounting module a while ago a custom report .. that works quite well .. now what I would like to do is add a button in the header as the one that has by default but that is related to my custom report

<report
    id="account_invoices"
    model="account.invoice"
    string="Factura pre-impresa"
    report_type="qweb-pdf"
    name="custom_report_module.report_custom_template"
    file="custom_report_module.report_custom_template"
    attachment_use="True"
    attachment="(object.state in ('open','paid')) and
        ('INV'+(object.number or '').replace('/','')+'.pdf')"
/>

This is what I call my report that appears in the drop-down list, after which I try to add the button but it just doesn't work for me

<record id="my_invoice_tree_inherit" model="ir.ui.view">
        <field name="name">account.invoice.form</field>
        <field name="model">account.invoice</field>
        <field name="inherit_id" ref="account.invoice_form"/>
        <field name="arch" type="xml">
            <button name="invoice_print" position="after">
                <button name="print_bank_statement" string="Print Statement" type="object" help="Print in Pdf"/>
            </button>
        </field>

    </record>

Some help???

If you take a look to other buttons with methods that print some reports in Odoo v11, they look like this:

@api.multi
def print_quotation(self):
    self.filtered(lambda s: s.state == 'draft').write({'state': 'sent'})
    return self.env.ref('sale.action_report_saleorder').report_action(self)

So, in your case, if you do not want to run any python operation you can simplify running this:

@api.multi
def print_bank_statement(self):
    return self.env.ref('module_name.account_invoices').report_action(self)

Also, you can call the XML ID of the report directly without calling any python code like this:

<button name="%(account_invoices)d" string="Print" type="action" />

Be sure you are using the right button type here: type="action"

And as @Amal says, check that the form reference, from where you are inheriting, is the correct one

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM