Anda dapat menambahkan tombol ke ListView dan menggunakan JavaScript untuk mengunduh file secara terpisah (panggil metode python untuk mendapatkan data laporan sebagai string base64).
Untuk menambahkan tombol, Anda perlu mengganti template ListView Qweb.
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:
Saya menyertakan download.js agar dapat menelepon download
fungsi dari 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');
});
});
}
});
}
Saya menggunakan metode get_report_data
yang mengembalikan daftar tupel [(invoice_data, name), ...]
Piton
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)]
person
Kenly
schedule
08.05.2019