我正在尝试打印附件的条形码标签。我在文档页面的看板视图中添加了一个新按钮。我试图为选定的文档打印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]})
},
});
});
report.AbstractModel
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,
}
ir.attachment
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
未成功执行。
我该如何实现?
答案 0 :(得分:0)
我看不到您在代码中引用_get_report_values
的位置,也许就是问题所在。要记住的另一件事是,_function_name
只能在模型内部进行引用,get_report_values
会很简洁。
答案 1 :(得分: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);
},