首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何打印所有发票?Odoo-10

如何打印所有发票?Odoo-10
EN

Stack Overflow用户
提问于 2019-05-03 18:33:44
回答 2查看 572关注 0票数 0

我想打印属于某个特定客户的所有报告。我已经有了自己的报表。我不知道如何添加"print_all“按钮打印(或只是保存到pdf)所有发票

如果有人知道我可以在哪里找到类似的解决方案,请帮助我。如果我说得不够清楚,或者你需要更多的信息,请让我知道。

EN

回答 2

Stack Overflow用户

发布于 2019-05-05 21:53:42

不需要编写自己的函数来打印所有与客户相关的报告,在客户表单下有一个智能按钮“开票”,这将打开客户特定的发票,您可以根据@WaKo的回答进行打印。

票数 1
EN

Stack Overflow用户

发布于 2019-05-08 20:06:13

您可以向ListView添加一个按钮,并使用JavaScript单独下载文件(调用python方法以获取base64字符串形式的报告数据)。

要添加按钮,您需要覆盖ListView Qweb模板。

Qweb

代码语言:javascript
复制
<?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函数。

代码语言:javascript
复制
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

代码语言:javascript
复制
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)]
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55968044

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档