Search code examples
htmlodooqwebodoo-14

'base.document.layout' object has no attribute 'header' odoo14 - trying to display custom fields in report


with a custom module, I have added the two fields header and footer to every res.company object. These are fields of the type binary.

I now want to display them in my document layout in qweb. Unfortunately, odoo tells me

'base.document.layout' object has no attribute 'header'

This is what my layout looks like

<?xml version="1.0"?>
<t t-name="web.external_layout_boxed">
        <div t-attf-class="header o_company_#{company.id}_layout" t-att-style="report_header_style">
            <div class="o_boxed_header">
            <div class="row mb8">
                <div class="col-6">
<!--HERE-->         <img t-if="company.logo" t-att-src="image_data_uri(company.header)" alt="brief_header"/>
                </div>
                <div class="col-6 text-right mb4">
                    <h4 class="mt0" t-field="company.report_header"/>
                    <div name="company_address" class="float-right mb4">
                        <span class="company_address" t-field="company.partner_id" t-options="{&quot;widget&quot;: &quot;contact&quot;, &quot;fields&quot;: [&quot;address&quot;, &quot;name&quot;], &quot;no_marker&quot;: true}"/>
                    </div>
                </div>
            </div>
            </div>
        </div>

        <div t-attf-class="article o_report_layout_boxed o_company_#{company.id}_layout" t-att-data-oe-model="o and o._name" t-att-data-oe-id="o and o.id" t-att-data-oe-lang="o and o.env.context.get('lang')">
            <div class="pt-5">
                <t t-call="web.address_layout"/>
            </div>
            <t t-raw="0"/>
        </div>

        <img t-if="company.logo" t-att-src="image_data_uri(company.footer)" alt="brief_footer"/>
    </t>

as you can see I am trying to access the header with company.header

the pictures appended show you that the fields exist on the type.

you can see that the fields exist on the model res.company

fields list for res.company

What am I doing wrong? How can I correctly display the uploaded images in the external_layout_boxed?


Solution

  • When rendering the document, the company variable is set to wizard object not to the user company. Odoo will try to access header and footer in base.document.layout model.

    To fix that issue, alter the document layout model like following:

    class BaseDocumentLayout(models.TransientModel):
        _inherit = 'base.document.layout'
        
        header = fields.Binary(related="company_id.header")
        footer = fields.Binary(related="company_id.footer")
    

    You can find an example in l10n_de module where they created a new report layout and altered base.document.layout to use new fields like street, city or bank_ids