【问题标题】:How to print report from website in odoo11?如何在odoo11中从网站打印报告?
【发布时间】:2018-10-16 07:04:17
【问题描述】:

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

但它显示了一些错误:

文件“/home/priya/workspace/ODOO11/odoo-11.0/odoo/http.py”,第 829 行,在调度中 r = self._call_function(**self.params) _call_function 中的文件“/home/priya/workspace/ODOO11/odoo-11.0/odoo/http.py”,第 342 行 返回检查调用(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中 结果 = self.endpoint(*a, **kw) 调用中的文件“/home/priya/workspace/ODOO11/odoo-11.0/odoo/http.py”,第 936 行 返回 self.method(*args, **kw) 文件“/home/priya/workspace/ODOO11/odoo-11.0/odoo/http.py”,第 515 行,在 response_wrap 响应 = 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。

【问题讨论】:

    标签: odoo-11


    【解决方案1】:

    你可以试试这个

    通过给这样的按钮一个href来打印报告,

    <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。 这是格式, 报告/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('/')
    

    【讨论】:

      【解决方案2】:

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

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

      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

      【讨论】:

      • 我的 Xml 代码:
      • 我已经编辑了我的答案,以便为您提供 pdf 渲染的解决方案
      • 文件“/home/priya/repo/rp-group/rpg_quotation/controllers/web_page.py”,第 2700 行,在 print_quotation_software_report pdf 中,_ = request.env.ref('rpg_quotation.rpg_quotation_software_setwise__report' ).sudo().render_qweb_pdf([order_id])[0] ValueError: 要解压的值太多
      • 如果我将 python 代码编写为: def print_quotation_software_report(self,data,quotation_id): order_id = quote_id if order_id: pdf, _ = request.env.ref('rpg_quotation.rpg_quotation_software_setwise__report').sudo( ).render_qweb_pdf([order_id]) pdfhttpheaders = [('Content-Type', 'application/pdf'), ('Content-Length', u'%s' % len(pdf))] return json.dumps({ 'pdf': pdf, 'pdfhttpheaders':pdfhttpheaders}) else: return request.redirect('/') 那么错误来了:
      • 2018-10-17 12:15:28,662 10814 信息 RP_19_9 odoo.addons.base.ir.ir_attachment:_read_file 读取 /home/priya/.local/share/Odoo/filestore/RP_19_9/57 /57d4fef2c45d2462337a4e8f2c63d82b6e064d85 Traceback(最近一次调用最后):文件“/home/priya/workspace/ODOO11/odoo-11.0/odoo/addons/base/ir/ir_attachment.py”,第 101 行,在 _file_read r = base64.b64encode(open (full_path,'rb').read()) IOError: [Errno 2] No such file or directory: u'/home/priya/.local/share/Odoo/filestore/RP_19_9/57/57d4fef2c45d2462337a4e8f2c63d82b6e064d85'
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-03-28
      相关资源
      最近更新 更多