Skip to Content
Menú
This question has been flagged
1 Respondre
6555 Vistes

Hi, i am using odoo11.

I wanted to experiment with custom reports for accounting. So I added a special "print invoice griglia" in the print menubar by means of the following code:


<?xml version="1.0" encoding="utf-8"?>
<odoo>
    <data>        
        <report
            id="custom_invoice_griglia"
            model="account.invoice"
            string="Invoices griglia"
            report_type="qweb-pdf"
            name="custom_invoice.report_invoice_griglia"
            file="custom_invoice.report_invoice_griglia"
            attachment="(object.state in ('open','paid')) and ('INV'+(object.number or '').replace('/','')+'.pdf')"
            print_report_name="(object._get_printed_report_name())"
        />

         <template id="report_invoice_griglia"> <t t-call="web.html_container"> <t t-foreach="docs" t-as="o"> <t t-call="custom_invoice.report_invoice_griglia" t-lang="o.partner_id.lang"/> </t> </t> </template>
        <template id="report_invoice_griglia"> <t t-if="not o and doc"> <t t-set="o" t-value="doc"/> </t> <t t-if="o and 'company_id' in o"> <t t-set="company" t-value="o.company_id.sudo()"/> </t> <t t-if="not o or not 'company_id' in o"> <t t-set="company" t-value="res_company"/> </t> <t t-call="web.html_container"> <div class="article" style="margin-top:0px;padding-top:0px;"> Hello there </div> </t> </template> </data> </odoo>


And it sorta works: i effectively end up with a blank pdf file containing the "Hello there" string. The only problem is that there's a lot of blank space on top of the page, before the "hello there".

I tried to fix it by merely setting margin and padding of the 'page' tag to zero, but this does not appear to have any affect. I also noticed that if you remove the class="article" attribute, no page is generated and an empty pdf is outputted instead. 

So i tried to find some css rule for "article" by grepping:

grep -rl "\.article" *

but no result is found.

So where does the space at the top of a blank report come from? Is there a way to get rid of it? Thank you very much in advance for any help!

Avatar
Descartar
Autor Best Answer

Ok, maybe I managed to solve (parts of) my own problem. The key is to pass the desired value of data_report_margin_top (which i put in bold in the following snippet)

        <template id="report_invoice_griglia">
            <t t-if="not o and doc">
                <t t-set="o" t-value="doc"/>
            </t>

            <t t-if="o and 'company_id' in o">
                <t t-set="company" t-value="o.company_id.sudo()"/>
            </t>
            <t t-if="not o or not 'company_id' in o">
                <t t-set="company" t-value="res_company"/>
            </t>
            
            
            <t t-call="web.html_container">
              <t t-set="data_report_margin_top" t-value="1"/>
                <div class="article" style="position:absolute; top:0px; ">
                    <div style="background-color: red;">HELLO THERE</div>
                </div>
            </t>
  </template>


For some reason I have to pass 1 because it doesn't appear to work with zero...

In any case it's still a mystery why class="article" is necessary in order to get a non-empty pdf. Who knows?

Also, changing the other margins seems a little more complicated because the html_container doesn't have such fields as input values. Still trying to get it to work.

Cheers.


Avatar
Descartar
Related Posts Respostes Vistes Activitat
0
de set. 21
2021
4
d’oct. 20
9741
1
d’abr. 20
4340
0
de març 19
2325
1
d’ag. 18
5549