【问题标题】:How to print all invoice? Odoo-10如何打印所有发票? Odoo-10
【发布时间】:2019-05-03 10:33:44
【问题描述】:

我想打印属于特定客户的所有报告。 我已经有了自己的报告形式。 我不知道如何添加“print_all”按钮以打印(或仅保存为 pdf)所有发票

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

【问题讨论】:

  • 在列表视图中选择所有发票并点击打印按钮。
  • 感谢您的建议,但我必须单独打印所有发票。例如,如果用户“some_name”有 55 张发票,我需要 55 个 pdf 文档。

标签: report odoo odoo-10


【解决方案1】:

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

【讨论】:

  • 感谢您的建议,但我必须单独打印所有发票。例如,如果用户“some_name”有 55 张发票,我需要 55 个 pdf 文档。
【解决方案2】:

您可以在 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)]

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多