This question has been flagged
2 Replies
9421 Views

Hi everybody

I've set up a second report for invoices. I want an alternative report option in the print dropdown so I created a second report in the account module.

I've added a report in account_report.xml under /addons/account/ like this:

        <report 
            id="account_invoices"
            model="account.invoice"
            string="Invoices"
            report_type="qweb-pdf"
            name="account.report_invoice"
            file="account.report_invoice"
            attachment_use="True"
            attachment="(object.state in ('open','paid')) and ('INV'+(object.number or '').replace('/','')+'.pdf')"
        />

    <!--Custom report link->
        <report 
            id="account_aangetekend"
            model="account.invoice"
            string="Aangetekende zending"
            report_type="qweb-pdf"
            name="account.report_aangetekend"
            file="account.report_aangetekend"
        />

Then I added an XML file, named report_aangetekend.xml with 95% the same code as the 'normal' report (coming from report_invoice.xml). I've only changed the names and added one field.

<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<template id="report_aangetekend_document">
    <t t-call="report.external_layout">
        <div class="page">
            <div class="row">
                <div class="col-xs-5 col-xs-offset-7">
                    <address t-field="o.partner_id"
                        t-field-options='{"widget": "contact", "fields": ["address", "name"], "no_marker": true}' />
                    <span t-field="o.partner_id.vat"/>
                </div>
            </div>
<p>TEST</p>
<!--Lots of other, irrelevant code here-->
</div>
</t>
</template>

<template id="report_aangetekend">
    <t t-call="report.html_container">
        <t t-foreach="doc_ids" t-as="doc_id">
            <t t-raw="translate_doc(doc_id, doc_model, 'partner_id.lang', 'account.report_aangetekend_document')"/>
        </t>
    </t>
</template>
</data>
</openerp>

The report works, is showing up and I can print it. There is however a strange effect.
If I now create a new invoice (in draft modus) and choose the two different print options I'll get two different report prints, so far so good, as you can see here.


If I now make a second invoice, validate this and then print out the two different reports I'll get the same report twice. Both coming from the file report_invoice.xml (addons/account/views/). As you can see here:


Is there a reason why my custom report is not being printed in validated state but it is in draft? Do I have to define something more elsewhere or what am I missing?

With kind regards
Yenthe
 

Avatar
Discard
Best Answer

Probably your report is printed from an attachment in both cases. If standard invoice state is ('open','paid') the attachment is generated, in state 'draft' no attachment.

Avatar
Discard
Author

@zbik that is correct, at the moment I have both set to attachment_use="True" but even if I only set one or none I still don't get the wished result. Could you give me some more details about what is wrong/how to fix it?

Do you have removed the old attachment? In my opinion, if attachment_use="False", should work.

My solution: https://www.odoo.com/forum/help-1/question/how-we-inherit-invoice-report-to-change-the-attachment-attribute-on-odoo-v8-69628

Author

@zbik even if I set both attachment_use="False" there is no difference. When the invoice is validated both versions will print the original sadly. Any more ideas / solutions?

Erase attachment="(object.state in ('open','paid')) and ('INV'+(object.number or '').replace('/','')+'.pdf')". Your code xml (deleted all attachment lines) normally working on my tmp system. I think this is an Odoo error with attachment_use="False", if attachment='xxx' not empty.

Author Best Answer

I've found the solution and it was very simple. I just had to set both records to attachment_use="True" and had to give them both a different name.
I have no idea why the two different names fixed it though. Those two files are added as an attachment and that seems to do the trick.

Final code:

        <report 
            id="account_invoices"
            model="account.invoice"
            string="Invoices"
            report_type="qweb-pdf"
            name="account.report_invoice"
        attachment_use="True"
            attachment="(object.state in ('open','paid')) and ('INV'+(object.number or '').replace('/','')+'.pdf')"
            file="account.report_invoice"
        />

    <!--Custom-->
        <report 
            id="account_aangetekend"
            model="account.invoice"
            string="Aangetekende zending"
            report_type="qweb-pdf"
            name="account.report_aangetekend"
            attachment_use="True"
           <!--This one has to have a different name then the other one. The magic happens here.-->
            attachment="(object.state in ('open','paid')) and ('INV2'+(object.number or '').replace('/','')+'.pdf')"
            file="account.report_aangetekend"
        />

If you don't want any files attached under attachments there is a second solution:

        <report 
            id="account_invoices"
            model="account.invoice"
            string="Invoices"
            report_type="qweb-pdf"
            name="account.report_invoice"
        attachment_use="True"
            attachment="(object.state in ('open','paid')) and ('INV'+(object.number or '').replace('/','')+'.pdf')"
            file="account.report_invoice"
        />

    <!--Custom-->
        <report 
            id="account_aangetekend"
            model="account.invoice"
            string="Aangetekende zending"
            report_type="qweb-pdf"
            name="account.report_aangetekend"
           <!--No attachment -->
            attachment_use="False"
            file="account.report_aangetekend"
        />

Avatar
Discard