我要打印属于特定客户端的所有报告。 我已经有自己的报告形式了。 我不知道如何为所有发票添加“ print_all”按钮以打印(或仅保存为pdf)
如果有人知道我在哪里可以找到类似的解决方案,请提供帮助。 如果我不够清楚,或者您需要更多信息,请告诉我。
答案 0 :(得分:1)
不需要打印所有与客户有关的报告,就可以编写自己的功能,在客户表格下有一个智能按钮“已开票”,这将打开客户特定的发票,您可以按@WaKo的回答进行打印。
答案 1 :(得分:0)
您可以在ListView中添加一个按钮,并使用JavaScript单独下载文件(调用python方法以将报告数据作为base64字符串获取)。
要添加按钮,您需要覆盖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 :
我包括了download.js以便能够从js调用download
函数。
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');
});
});
}
});
}
我使用了get_report_data
方法,该方法返回一个元组列表[(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)]