How to create new QWeb report with inheriting existing one

If you need to create a new QWeb report in Odoo that will be very similar to the existing one, you don’t need to rewrite the whole code from the existing report. Instead, you need to inherit it with flag primary=True and to make the changes that you want to see in the new report.
For Example, If you want to create a new report in the sale module, that is very similar to the existing one, the code should look like:

<openerp>
    <data>
 
        <template id="new_saleorder_report" inherit_id="sale.report_saleorder_document" primary="True">
           <Here goes your customization>
        </template>

    </data>
</openerp>
Share the knowledge!

3 Comments

  1. Art

    I’m trying to customize a report_invoice_document qweb report with the following code:

    Invoice_test_2

    and I was getting the following error:
    ValueError: Can’t validate view:
    Element ” cannot be located in parent view

    then I added attribute primary=”True” inside the tag and error was gone. So here are some questions:
    1) Why my error was gone and do I have to add “primary” attribute every time I inherit a report?
    2) It still prints out the original report without my customization, which is tag. I expected to see only “Invoice_test_2” in my printed customized report and nothing else. What am I doing wrong?

    1. admin

      Probably you have an error in the inherited view. I need to see the code in order to tell you exactly what is the issue. You can send it at info@odooninja.com

      When you add primary=”True”, you don’t change existing report but you are creating a new one. Actually, your report is not called at all, therefore, the error is gone.

Leave a Reply

Your email address will not be published. Required fields are marked *