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

In the 'report_invoice_document' report, I added :

  <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 .

How can I do it without modifying the content of the report generated from backend. Any help please ? Thanks. enter image description here enter image description here



Solution 1:[1]

You can use the website variable to check if the invoice report is printed from the website

website
the current website object, if any (this item can be present but None)

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.

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>

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1