1

我正在尝试打印附件的条形码标签。我在文档页面的看板视图中添加了一个新按钮。我试图为选定的文档打印 PDF 报告。这是代码。

*.js

odoo.define('documents.DocumentsInspector.inherit', function (require) 
{
"use strict";

var model = require('documents.DocumentsInspector');
var core = require('web.core');
var _t = core._t;
var qweb = core.qweb;
var BaseImport = require('base_import.import')
var rpc = require('web.rpc')

model.include({

 events: {
  'click .o_inspector_archive': '_onArchive',
  'click .o_inspector_delete': '_onDelete',
  'click .o_inspector_download': '_onDownload',
  'click .o_inspector_replace': '_onReplace',
  'click .o_inspector_lock': '_onLock',
  'click .o_inspector_share': '_onShare',
  'click .o_inspector_open_chatter': '_onOpenChatter',
  'click .o_inspector_tag_add': '_onTagInputClicked',
  'click .o_inspector_tag_remove': '_onRemoveTag',
  'click .o_inspector_trigger_rule': '_onTriggerRule',
  'click .o_inspector_object_name': '_onOpenResource',
  'click .o_preview_available': '_onOpenPreview',
  'click .o_document_pdf': '_onOpenPDF',
  'mouseover .o_inspector_trigger_hover': '_onMouseoverRule',
  'mouseout .o_inspector_trigger_hover': '_onMouseoutRule',
  'click .o_inspector_print': '_onBarcodePrint',
},


/**
 * @private
 */
_onBarcodePrint: function (ev) {

 var attachment_ids = [];
_.each(this.records,function(data){
  // console.log('data',data);
  attachment_ids.push(data.res_id)
}),

rpc.query({model: 'ir.attachment', method: 'print_barcode',args:[attachment_ids]})
 },
 });



});

报告.抽象模型

 class PrintDocumentBarcode(models.AbstractModel):
_name = 'report.ean13_attachment.report_documentbarcode'
_description = 'Document Barcodes'

@api.model
def _get_report_values(self, docids, data=None):

    if data.get('atids'):
        doc = self.env['ir.attachment'].browse(data.get('atids'))
    else:
        doc = self.env['ir.attachment'].browse(docids)

    return {
        'doc_ids': docids,
        'doc_model': self.env['ir.attachment'],
        'docs': doc,

    }

依附

def print_barcode(self):
    data = {}
    data['atids']=self.ids
    return self.env.ref('ean13_attachment.action_report_documentbarcode').with_context(landscape=True).report_action(self, data=data)

该函数print_barcode成功执行,但_get_report_values没有成功。

我怎样才能做到这一点?

4

2 回答 2

0

这是一个使用 odoo js 从自定义按钮打印 pdf 报告的示例。

events:{

    'click #mybutton': '_onClickPrint',
}


_onClickPrint: function(){
        var self = this;
        var reportname = 'sale.report_saleorder?docids=' +
                          this.userContext.activeids +
                          '&report_type=qweb-pdf&model_name=sale.order';
        var action = {
            'type': 'ir.actions.report',
            'report_type': 'qweb-pdf',
            'report_name': reportname,
            'report_file': 'sale.report_saleorder',
        };
        return this.do_action(action);
    },
于 2021-02-08T15:16:08.750 回答
0

我看不到您_get_report_values在代码中引用的位置,也许这​​就是问题所在。要记住的另一件事是,_function_name只能在模型内部引用,get_report_values会很简洁。

于 2019-01-09T08:08:09.703 回答