How to create a Purchase Bill Qweb report in odoo 14

A purchase invoice is an invoice that is used in conjunction with a purchase order. It is used to indicate how much money the buyer owes to the seller. Purchase invoices are also commonly known as bills, statements or sales invoices.

This blog will provide insight on How to create a purchase bill  qweb report in odoo 14

How a Purchase Bill report can print in odoo ?

1: Under report add new file named “report.xml”

Under “report.xml” add :
syntax as follws

    <report id="report_id"
          model="module.name"
          string="report related name"
          report_type="qweb-pdf"
          name="custom_module_name.body_template_id"
          file="custom_module_name.body_template_id"/>

in practical:

<report id="purchase_bill_report_id"
          model="account.move"
          string="Purchase Report"
          report_type="qweb-pdf"
          name="odoo_training.purchase_order_body_format"
          file="odoo_training.purchase_order_body_format"/>

-> Here name and file should be custom addon name . body template id from corresponding xml file

2: You can create an xml file inside the report directory

syntax as follows:

 

<?xml version="1.0" encoding="UTF-8" ?>

<odoo>
    <template id="report_header_template_id">
        <t t-call="web.html_container">
            <t t-if="not o" t-set="o" t-value="doc"/>
            <t t-if="not company">
                <!--  Multicompany  -->
                <t t-if="company_id">
                    <t t-set="company" t-value="company_id"/>
                </t>
                <t t-elif="o and 'company_id' in o">
                    <t t-set="company" t-value="o.company_id.sudo()"/>
                </t>
                <t t-else="else">
                    <t t-set="company" t-value="res_company"/>
                </t>
            </t>
            <div class="header" t-att-style="report_header_style">
                <div class="row">
                </div>
            </div>
            <div class="col-9 text-right" t-field="company.report_header" name="moto">
                <div 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 class="article" 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')">
                <t t-raw="0"/>
            </div>
            <div class="footer o_background_footer">
                <div>
                    <div t-field="company.report_footer"/>
                    <div t-if="report_type == 'pdf'" class="text-muted">
                        <hr style="width:100%;" color="red"/>
                        <div class="row">
                            <div class="col-6" style="text-align:right;">
                                Page:
                                <span class="page"/>
                                /
                                <span class="topage"/>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </t>
    </template>
<template id="report_body_template">
    <t t-call="web.html_container">
        <t t-foreach="docs" t-as="o">
            <t t-call="module_name.report_header_template_id">
                <div class="page">
</div>
                </t>
            </t>
        </t>
    </template>
</odoo>

-> here you have to change header template_id, body template_id and under body template_id change this one also <t t-call=”module_name.header_template_id”>

In practical case:

<?xml version="1.0" encoding="UTF-8" ?>

<odoo>
    <template id="purchase_order_header_format">
        <t t-call="web.html_container">
            <t t-if="not o" t-set="o" t-value="doc"/>
            <t t-if="not company">
                <!--  Multicompany  -->
                <t t-if="company_id">
                    <t t-set="company" t-value="company_id"/>
                </t>
                <t t-elif="o and 'company_id' in o">
                    <t t-set="company" t-value="o.company_id.sudo()"/>
                </t>
                <t t-else="else">
                    <t t-set="company" t-value="res_company"/>


                </t>
            </t>
            <div class="header" t-att-style="report_header_style">
                <div class="row">
                </div>
            </div>
            <div class="col-9 text-right" t-field="company.report_header" name="moto">
                <div 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 class="article" 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')">
                <t t-raw="0"/>
            </div>
            <div class="footer o_background_footer">
                <div>
                    <div t-field="company.report_footer"/>
                    <div t-if="report_type == 'pdf'" class="text-muted">
                        <hr style="width:100%;" color="red"/>
                        <div class="row">
                            <div class="col-6" style="text-align:right;">
                                Page:
                                <span class="page"/>
                                /
                                <span class="topage"/>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </t>
    </template>
    <template id="purchase_order_body_format">
        <t t-call="web.html_container">
            <t t-foreach="docs" t-as="o">
                <t t-call="odoo_training.purchase_order_header_format">
                    <div class="page">
                        <div class="col-12">
                            <h5 style="text-align:left">Vendor Bill</h5>
                            <h2 style="text-align:left"><t t-esc="o.name"/> </h2>
                        </div>
                    <table style="border:1px solid black;width:100%">
                        <tr>
                            <td>Vendor</td>
                            <td><t t-esc="o.partner_id.name"/></td>
                            <td>Bill Date</td>
                            <td><t t-esc="o.invoice_date"/></td>
                        </tr>
                        <tr>
                            <td> Bill Reference</td>
                            <td><t t-esc="o.ref"/> </td>
                            <td>Accounting Date</td>
                            <td><t t-esc="o.date"/> </td>
                        </tr>
                        <tr>
                            <td>Payment Reference</td>
                            <td><t t-esc="o.payment_reference"/> </td>
                            <td>Due Date</td>
                            <td><t t-esc="o.invoice_date_due"/> </td>
                        </tr>
                        <tr>
                            <td>Recepient Bank</td>
                            <td><t t-esc="o.partner_bank_id.id"/> </td>
                            <td>Journal</td>
                            <td><t t-esc="o.journal_id.name"/> </td>
                        </tr>
                        
                   </table>
                        <table style="border:1px solid black;width:100%">
                            <tr>
                                <td style="border:1px solid black">Product</td>
                                <td style="border:1px solid black">Label</td>
                                <td style="border:1px solid black">Account</td>
                                <td style="border:1px solid black">Quantity</td>
                                <td style="border:1px solid black">UOM</td>
                                <td style="border:1px solid black">Price</td>
                                <td style="border:1px solid black">Tax</td>
                                <td style="border:1px solid black"> SubTotal</td>
                            </tr>
                            <t t-foreach="o.invoice_line_ids" t-as="one_to_many">
                                <tr>
                                    <td style="border:1px solid black"><t t-esc="one_to_many.product_id.name"/> </td>
                                    <td style="border:1px solid black"><t t-esc="one_to_many.name"/> </td>
                                    <td style="border:1px solid black"><t t-esc="one_to_many.account_id.name"/> </td>
                                    <td style="border:1px solid black"><t t-esc="one_to_many.quantity"/> </td>
                                    <td style="border:1px solid black"><t t-esc="one_to_many.product_uom_id.name"/> </td>
                                    <td style="border:1px solid black"><t t-esc="one_to_many.price_unit"/></td>
                                    <td style="border:1px solid black"><t t-esc="one_to_many.tax_ids.name"/></td>
                                    <td style="border:1px solid black"><t t-esc="one_to_many.price_subtotal"/></td>
                                </tr>
                            </t>
                        </table>
                        <h6 style="text-align:right">Total <t t-esc="o.amount_total"/> </h6>
                        <h6 style="text-align:right">Amount Due <t t-esc="o.amount_residual"/> </h6>
                    </div>
                </t>
            </t>
        </t>
    </template>
</odoo> 


* Do not forget to Change Header template id  and
 body template id  
under body template id, please change <t t-call="module_name.headet template id" in corresponding xml file,

                          The Print Show Like This


 These xml files  you need to add in __manifest__.py file. 
To know more about us

		

Leave a Reply

Your email address will not be published.