首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在odoo11网站上打印报表?

如何在odoo11网站上打印报表?
EN

Stack Overflow用户
提问于 2018-10-16 07:04:17
回答 2查看 2.2K关注 0票数 0

我想通过点击网站上的打印按钮来打印报告。

但它显示出一些错误:

文件"/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)中

代码语言:javascript
复制
UnboundLocalError: local variable 'active_ids' referenced before assignment

我的js密码:

代码语言:javascript
复制
$(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代码:

代码语言:javascript
复制
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。

EN

回答 2

Stack Overflow用户

发布于 2019-06-28 13:54:32

你可以试试这个

像这样按下按钮打印报告,

代码语言:javascript
复制
<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

若要从控制器打印报表,

代码语言:javascript
复制
@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('/')
票数 1
EN

Stack Overflow用户

发布于 2018-10-16 07:49:25

可能是因为您将self作为docids位置参数的值传递给report_action方法调用,而不是quotation_id来删除实际错误。

但是report_action方法调用不会返回pdf文件数据。您需要将其更改为:

代码语言:javascript
复制
pdf = request.env.ref('rpg_quotation.rpg_quotation_software_setwise__report').sudo().render_qweb_pdf([quotation_id])[0]

见以下例子:

https://github.com/odoo/odoo/blob/b29b545fe8464610ce04ac8be11e0356962d10d9/addons/sale/controllers/portal.py#L196

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52829692

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档