简体   繁体   English

如何将 div 从 html 打印到发票(网站)中的 qweb 报告? Odoo 14

[英]how to print div from html to qweb report in invoice (website) ? Odoo 14

In the 'report_invoice_document' report, I added:在“report_invoice_document”报告中,我添加了:

  <t t-if="report_type == 'html'">
      <div class="from_website" >
           <strong> Printed From Invoice</strong>
      </div>
  </t>

I want to get this div only when printing or downloding from website side.我只想在从网站端打印或下载时获取此 div。

How can I do it without modifying the content of the report generated from backend.如何在不修改从后端生成的报告内容的情况下做到这一点。 Any help please?有什么帮助吗? Thanks.谢谢。 在此处输入图像描述 在此处输入图像描述

You can use the website variable to check if the invoice report is printed from the website您可以使用website变量来检查发票报告是否从网站打印

website网站
the current website object, if any (this item can be present but None)当前网站 object,如果有(此项可以存在但无)

Try the following code:试试下面的代码:

<t t-if="website">
    <div class="from_website" >
        <strong> Printed From Website</strong>
    </div>
</t>

Edit (Report Preview)编辑(报告预览)

You can add an extra parameter to the report URL (inside the report_pdf_preview.js file ?variable_name= ) and alter the _render_template function to add a new report value based on the URL parameter then use it inside the template to hide text if the user uses the report preview.您可以向报告 URL 添加一个额外的参数(在 report_pdf_preview.js 文件?variable_name=内)并更改_render_template function 以添加基于 URL 参数的新报告值,然后在模板中使用它来隐藏文本(如果用户使用)报告预览。

Example:例子:

class IrActionsReport(models.Model):
    _inherit = 'ir.actions.report'
    
    def _render_template(self, template, values=None):
        values['pdf_preview'] = request.params.get('pdf_preview')
        return super(IrActionsReport, self)._render_template(template, values=values)

You can hide an element like following:您可以隐藏如下元素:

<div t-if="not pdf_preview and website">
  From website
</div>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM