Odoo: how to inherit/extend an external report layout only for certain reports


Odoo proves to be extremely flexible when it comes to extending the various native system reports. One of the most classic operations during implementation is customizing one or more reports, which will be adapted to reflect the style desired by the customer.

In the customization of reports an important role is played by the so-called external layouts, which are responsible for rendering the footer and header of the report. It follows that changes to an external layout will impact all reports that call it. However, there may be situations where a modification is requested only for a specific report or, conversely, for all reports except one or a few others.

One possible solution could be to create a completely new external layout and inherit each individual report involved to call it in place of the standard one. However, if the changes do not require creating a new report, we would be faced with a huge waste of code. Let's see how to extend an external layout and exclude a specific report from the modification.

For example, let's say we need to modify the header of our reports, except for the purchase one, so that the company logo is slightly larger than the proposed dimensions.

<?xml version="1.0" encoding="UTF-8" ?>
<odoo>
<template id="new_external_layout" inherit_id="web.external_layout_standard">
<xpath expr="//img[@t-if='company.logo']" position="attributes">
<attribute name="style">max-height: 195px;</attribute>
</xpath>
</template>
</odoo>

If we now want to exclude our purchase order report from our report, the first thing we do is to identify the report name of that report (for those who do not know, just go to settings→ technical features→ report, search for the report in question and take the indicated value. Obviously, all this must be done in developer mode).

At this point, we can use the xmlid property directly in our qweb view to ensure that the modification is used for all reports except for the one in question. In terms of code, we will have:

<?xml version="1.0" encoding="UTF-8" ?>
<odoo>
<template id="new_external_layout" inherit_id="web.external_layout_standard">
<xpath expr="//img[@t-if='company.logo']" position="replace">
<t t-if="xmlid != 'purchase.report_purchaseorder'">
<img t-if="company.logo" t-att-src="image_data_uri(company.logo)" style="max-height: 195px;" alt="Logo"/>
</t>
<t t-else="">
<img t-if="company.logo" t-att-src="image_data_uri(company.logo)" style="max-height: 45px;" alt="Logo"/>
</t>
</xpath>
</template>
</odoo>
Odoo: how to inherit/extend an external report layout only for certain reports
Raffaele Del Gatto March 31, 2024
Share this post
Archive
Sign in to leave a comment
Why choose Odoo as your main ERP system: pro and cons of former OpenERP