2

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???

Hernan Chaparro
  • 161
  • 1
  • 2
  • 9

1 Answers1

2

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

ChesuCR
  • 9,352
  • 5
  • 51
  • 114
  • Add `` but does not generate any action. I understand that this does not depend on what is written in my models.py – Hernan Chaparro Aug 13 '19 at 15:25
  • Actually the action is the `report` element. If you choose that option that does not depend on the python code (you do not need ti write anything in the `models` folder. Keep in mind that you cannot have spaces between character as you have written in your comment – ChesuCR Aug 21 '19 at 12:12