我想打印属于某个特定客户的所有报告。我已经有了自己的报表。我不知道如何添加"print_all“按钮打印(或只是保存到pdf)所有发票
如果有人知道我可以在哪里找到类似的解决方案,请帮助我。如果我说得不够清楚,或者你需要更多的信息,请让我知道。
发布于 2019-05-05 21:53:42
不需要编写自己的函数来打印所有与客户相关的报告,在客户表单下有一个智能按钮“开票”,这将打开客户特定的发票,您可以根据@WaKo的回答进行打印。
发布于 2019-05-08 20:06:13
您可以向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');
});
});
}
});}
我使用了返回元组列表[(invoice_data, name), ...]的get_report_data方法
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)]https://stackoverflow.com/questions/55968044
复制相似问题