Dejan Dakovic
Dejan Dakovic

Reputation: 155

How to print all invoice? Odoo-10

I want to print all the reports that belong to a particular client. I already have my own form of report. I do not know how to add "print_all" button for print(or just save to pdf) all invoices

If someone knows where I can look for similar solutions, please help. If I was not clear enough or if you needed more informatino, please let me know.

Upvotes: 0

Views: 865

Answers (2)

Kenly
Kenly

Reputation: 26678

You can add a button to the ListView and use JavaScript to download files separately (call a python method to get report data as base64 string).

To add the button you need to override the ListView Qweb template.

Qweb:

<?xml version="1.0" encoding="UTF-8"?>
<templates id="sync_template" xml:space="preserve">
    <t t-extend="ListView.buttons">
       <t t-jquery="button.oe_list_add" t-operation="after">
            <t t-if="widget.model == 'account.invoice'">
                  <button class="btn btn-sm btn-default oe_print_all" type="button">Print All</button>
            </t>
       </t>
    </t>
</templates>

JavaScript:
I included download.js to be able to call download function from js.

openerp.print_all = function(instance) {

 instance.web.ListView.include({
    load_list: function(data) {
        this._super(data);
        if (this.$buttons) {
            this.$buttons.find('.oe_print_all').off().click(this.proxy('print_all')) ;
        }
    },

    print_all: function () {
        var report_obj = new instance.web.Model("report")
        var dataset = this.dataset;
        new instance.web.Model("account.invoice")
        .call("get_report_data", [this.groups.get_selection().ids])
        .done(function (datas) {

            console.log(datas);

            $.each(datas, function( index, data ) {
                download('data:application/pdf;base64,' + data[0], "Invoice_" + data[1] + '.pdf','application/pdf');
            });
        });
    }
 });

}

I used get_report_data method wich returns a list of tuples [(invoice_data, name), ...]

Python

class AccountInvoice(models.Model):
    _inherit = "account.invoice"

    @api.model
    def get_report_data(self, ids):
        report_obj = self.env['report']
        return [(base64.b64encode(report_obj.get_pdf(invoice, "account.report_invoice")),
                 invoice.number.replace('/', '-') if invoice.number else '')
                for invoice in self.browse(ids)]

Upvotes: 0

Bhavesh Kagathara
Bhavesh Kagathara

Reputation: 96

There is no need to write your own function in order to print all report related to customer, under customer form there is smart button "invoiced", this will open the customer specific invoices and you can print as answered by @WaKo.

Upvotes: 1

Related Questions