我想通过点击网站上的打印按钮来打印报告。
但它显示出一些错误:
文件"/home/priya/workspace/ODOO11/odoo-11.0/odoo/http.py",行829,在调度r= self._call_function(**self.params)文件"/home/priya/workspace/ODOO11/odoo-11.0/odoo/http.py",第342行,在_call_function返回checked_call(self.db,*args,**kwargs)文件"/home/priya/workspace/ODOO11/odoo-11.0/odoo/service/model.py",中第97行,在包装器返回f(dbname,*args,**kwargs)文件"/home/priya/workspace/ODOO11/odoo-11.0/odoo/http.py",第335行,在checked_call result = self.endpoint(*a,**kw)文件"/home/priya/workspace/ODOO11/odoo-11.0/odoo/http.py",第936行中,在call返回self.method(*args )中,**kw)文件"/home/priya/workspace/ODOO11/odoo-11.0/odoo/http.py",第515行,在response_wrap response = f(*args,**kw)文件"/home/priya/repo/rp-group/rpg_quotation/controllers/web_page.py",行1442中,update_quotation res =self.print_quotation_software_report(数据,( int(quotation_id))文件"/home/priya/repo/rp-group/rpg_quotation/controllers/web_page.py",行2699,以print_quotation_software_report pdf = request.env.ref('rpg_quotation.rpg_quotation_software_setwise__report').report_action(self,data=data,config=False)文件"/home/priya/workspace/ODOO11/odoo-11.0/odoo/addons/base/ir/ir_actions_report.py",行703,在report_action context = dict(self.env.context,active_ids=active_ids)中
UnboundLocalError: local variable 'active_ids' referenced before assignment我的js密码:
$(document).on('click', Quotation.elements.print_quotation_software_selector, function() {
var self = $(this);
var data = {
'xpath': null,
'cmd': 'print_quotation_software_report'
};
Quotation.methods.xhr(data, function(r) {
});
});我的Python代码:
def print_quotation_software_report(self,data,quotation_id):
order_id = quotation_id
if quotation_id:
pdf = request.env.ref('rpg_quotation.rpg_quotation_software_setwise__report').report_action(self, data=data, config=False)
pdfhttpheaders = [('Content-Type', 'application/pdf'), ('Content-Length', len(pdf))]
return request.make_response(pdf, headers=pdfhttpheaders)这里,
rpg_quotation是模块名,rpg_quotation_software_setwise__report是报表id。
发布于 2019-06-28 13:54:32
你可以试试这个
像这样按下按钮打印报告,
<a t-attf-href="'/report/pdf/account.report_invoice/%s' % i.id">
<button type="button" class="btn btn-primary btn-md o_website_form_send">Print Invoice</button>
在i.id中,我有发票的id。这是格式,report/type_of_the_report/module_name.template_name/id
若要从控制器打印报表,
@http.route('/school/card', methods=['POST', 'GET'], csrf=False, type='http', auth="user", website=True)
def print_id(self, **kw):
student_id = kw['stud_id']
if student_id:
pdf = request.env['report'].sudo().get_pdf([student_id], 'module_name.report_name', data=None)
pdfhttpheaders = [('Content-Type', 'application/pdf'), ('Content-Length', len(pdf))]
return request.make_response(pdf, headers=pdfhttpheaders)
else:
return request.redirect('/')发布于 2018-10-16 07:49:25
可能是因为您将self作为docids位置参数的值传递给report_action方法调用,而不是quotation_id来删除实际错误。
但是report_action方法调用不会返回pdf文件数据。您需要将其更改为:
pdf = request.env.ref('rpg_quotation.rpg_quotation_software_setwise__report').sudo().render_qweb_pdf([quotation_id])[0]见以下例子:
https://stackoverflow.com/questions/52829692
复制相似问题