Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to create PDF report using python script in OpenERP(Odoo-8)

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 1.20k
    Comment on it

    In OpenERP first, create existing module and then inherits the account.invoice object in your own module and also create report file in your own module.

    Follow these step given belowas

    Step1- First create module like, test then create file in your module like, test.py and inherits the account.invoice object in your test.py file and pass this file in the __init__.py file.

    Using this code given below

    import time
    from openerp.report import report_sxw
    from openerp.osv import osv
    

     

    Step2- Then create another file like: test.xml file in your own module and pass this file in your __openerp__.py file.

    Using this file given below

    <?xml version="1.0" encoding="utf-8"?>
    <openerp>
        <data>  
          <report
                id="report_account_invoice_new"
                string="Invoice"
                model="account.invoice"
                report_type="qweb-pdf"
                name="test.account_invoice"
                file="test_invoice"
            />
    </data>
    </openerp>

     

    Step3- Then create another file like test_invoice.xml file. In this file we create templates of report and design.

    Using this code given below

    <openerp>
        <data>
            <template id="invoices_reports">
                <t t-call="report.external_layout">
                    <div class="page">
                        <div>
                            <div align="center" style="font-size: 20px;">INVOICE</div>
                            <br/>
                            <div align="center" style="font-size: 15px;"><span t-esc="o.payment_ids.journal_id.name"/></div>
                            <div class="row">
                                <div class="col-xs-6">
                                    <div style="font-size: 15px;">Invoice NO.<span t-field="o.number"/></div>
                                </div>
                                <div class="col-xs-5 col-xs-offset-1" >
                                    <div  style="font-size: 15px; margin-left: 1.0cm">Date: <span t-field="o.date_invoice"/></div>
                                </div>
                            </div>
                        </div>
                        <br/>
                        <br/>
                        <table class="table table-condensed" style="border: 1px solid black">
                            <thead>
                                <tr style="border: 1px solid black">
                                    <th style="border: 1px solid black; text-align: center; width : 2.0cm">SNo.</th>
                                    <th style="border: 1px solid black; text-align: center; width : 2.0cm">Code</th>
                                    <th style="border: 1px solid black; text-align: center; width : 9.0cm">Descirption</th>
                                    <th style="border: 1px solid black; text-align: center; width : 2.0cm">Qty</th>
                                    <th style="border: 1px solid black; text-align: center; width : 3.0cm">Unit / Pack size</th>
                                    <th style="border: 1px solid black; text-align: center; width : 3.0cm">Amount</th>
                                </tr>
                            </thead>
                            <tbody class="invoice_tbody">
                            <tr t-foreach="o.invoice_line" t-as="l">
                                <td style="border: 1px solid black; width : 2.0cm; text-align: center" >                               <span t-esc="l_index+1"/>
                                </td>
                                <td style="border: 1px solid black; width : 2.0cm; text-align: center">                              <span t-field="l.product_id.default_code"/>
                                </td>
                                <td  style="border: 1px solid black; width : 9.0cm; text-align: center">                               <span t-field="l.name"/>
                                </td>
                                <td  style="border: 1px solid black; width : 2.0cm; text-align: center">
                                    <span t-field="l.quantity"/>
                                </td>
                                <td  style="border: 1px solid black; width : 2.0cm; text-align: center">                                <span t-field="l.qty_char"/>
                                </td>
                                <td  style="border: 1px solid black; width : 3.0cm; text-align: center">                                <span t-field="l.price_unit"/>
                                </td>
                                <td  style="border: 1px solid black; width : 3.0cm; text-align: center">                              <span t-field="l.price_subtotal"/>
                                </td>
                            </tr>
                            <tr style="height: 0.8cm">
                                <td style="border: 1px solid black; width : 2.0cm; text-align: center" >
                                </td>
                                <td style="border: 1px solid black; width : 2.0cm; text-align: center">
                                </td>
                                <td  style="border: 1px solid black; width : 9.0cm; text-align: center">
                                </td>
                                <td  style="border: 1px solid black; width : 2.0cm; text-align: center">
                               </td>
                                <td  style="border: 1px solid black; width : 3.0cm; text-align: center">
                               </td>
                                <td  style="border: 1px solid black; width : 3.0cm; text-align: center">
                                </td>
                                <td  style="border: 1px solid black; width : 3.0cm; text-align: center">
                                </td>
                            </tr>
                            <tr style="height: 0.8cm">
                                <td style="border: 1px solid black; width : 2.0cm; text-align: center" >
                                </td>
                                <td style="border: 1px solid black; width : 2.0cm; text-align: center">
                                </td>
                                <td  style="border: 1px solid black; width : 9.0cm; text-align: center">
                                </td>
                                <td  style="border: 1px solid black; width : 9.0cm; text-align: center">
                                </td>
                                <td  style="border: 1px solid black; width : 2.0cm; text-align: center">
                                </td>
                                <td  style="border: 1px solid black; width : 3.0cm; text-align: center">
    
                                </td>
                                <td  style="border: 1px solid black; width : 3.0cm; text-align: center">
                                </td>
                            </tr>
                            </tbody>
                        </table>
                            <div class="col-xs-6">
                                <table class="table table-condensed" style="border: 1px solid white;">
                                    <tr style="border: 1px solid black">
                                        <td style="border: 1px solid white; width : 2.0cm">
                                            <strong>Amount Paid</strong></td>
                                        <td style="border: 1px solid white; width : 2.0cm">
                                            <span t-feild="o.amount_total"/>
                                        </td>
                                    </tr>
                                    <tr style="border: 1px solid white;">
                                        <td style="border: 1px solid white;; width : 2.0cm">
                                            <strong>Payment Detail</strong></td>
                                        <td style="border: 1px solid white; width : 2.0cm">
                                            <span t-field="o.payment_term"/>
                                        </td>
                                    </tr>
                                    <tr style="border: 1px solid white;">
                                        <td style="border: 1px solid white; width : 2.0cm;">
                                            <strong>Balance</strong></td>
                                        <td style="border: 1px solid white; width : 2.0cm;">
                                            <span t-field="o.residual"/>
                                        </td>
                                    </tr>
                                </table>
                            </div>
                            <div class="col-xs-5 col-xs-offset-1" >
                                <table class="table table-condensed" style="border: 1px solid black; margin-left: 0.5cm">
                                    <tr style="border: 1px solid black">
                                        <td style="border: 1px solid black; width : 1.0cm; text-align: center"><strong>Total</strong></td>
                                        <td  style="border: 1px solid black; width : 1.0cm; text-align: center">
                                            <span t-field="o.amount_untaxed" t-field-options='{"widget": "monetary", "display_currency": "o.currency_id"}'/>
                                        </td>
                                    </tr>
                                    <tr style="border: 1px solid black">
                                        <td style="border: 1px solid black; width : 1.0cm; text-align: center">Discount</td>
                                        <td style="border: 1px solid black; width : 1.0cm; text-align: center">
                                            <span t-field="o.amount_tax" t-field-options='{"widget": "monetary", "display_currency": "o.currency_id"}'/>
                                        </td>
                                    </tr>
                                    <tr style="border: 1px solid black">
                                        <td style="border: 1px solid black; width : 1.0cm; text-align: center"><strong>Total Bill Amount</strong></td>
                                        <td style="border: 1px solid black; width : 1.0cm; text-align: center">
                                             <span t-esc="o.amount_untaxed*o.discount/100" t-field-options='{"widget": "monetary", "display_currency": "o.currency_id"}'/>
                                        </td>
                                    </tr>
                                </table>
                            </div>
                    </div>
                </t>
            </template>
            <template id="external_layout_footer" inherit_id="report.external_layout_footer">
            </template>
            <template id="report_header_new" inherit_id="report.external_layout_header">
                <xpath expr="//div[@class='header']" position="replace"/>
            </template>
            <template id="report_invoices">
                <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', 'test.invoices_reports')"/>
                    </t>
                </t>
            </template>
        </data>
    </openerp>
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: