我正在尝试打印附件的条形码标签。我在文档页面的看板视图中添加了一个新按钮。我试图为选定的文档打印 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
没有成功。
我怎样才能做到这一点?