Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

Why is my custom invoice report only being printed in the draft state and not in invoice state?

By
Yenthe
on 12/19/14, 8:34 AM 1,933 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
 

0

zbik

--zbik--
5941
| 6 4 7
Lodz, Poland
--zbik--


zbik
On 12/19/14, 9:11 AM

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.

@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?

Yenthe
on 12/19/14, 10:09 AM

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

zbik
on 12/19/14, 10:18 AM

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

zbik
on 12/19/14, 10:22 AM

@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?

Yenthe
on 12/19/14, 10:42 AM

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.

zbik
on 12/19/14, 11:18 AM
0

Yenthe

--Yenthe--
6676
| 7 7 8
Turnhout, Belgium
--Yenthe--

My Odoo blog: http://www.odoo.yenthevg.com/

My Twitter: https://twitter.com/Yenthe666

Yenthe
On 12/19/14, 11:13 AM

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"
        />

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 12/19/14, 8:34 AM
Seen: 1933 times
Last updated: 3/16/15, 8:10 AM