blog image

Report in odoo

Generate report in pdf ,html or nay other formate, you need Qweb template enginee to create reports as well as web pages.

<?xml version="1.0" encoding="utf-8"?>
<odoo>
    <record id="action_report_school_student" model="ir.actions.report">
        <field name="name">Student Report Card</field>
        <field name="model">school.student</field>
        <field name="report_type">qweb-pdf</field>
        <field name="report_name">school.report_student_mark</field>
        <field name="report_file">school.report_student_mark</field>
        <field name="print_report_name">'Student Report'</field>
        <field name="binding_model_id" ref="school.model_school_student"/>
        <field name="binding_type">report</field>
       
    </record>

    <template id="report_student_mark">
        <t t-call="web.html_container">
            <t t-foreach="docs" t-as="o">
            <t t-set='values' t-value='o.get_report_value()'/>
                <t t-call="web.external_layout">
                    <div class="page">
                     <!-- style="page-break-before:always;" -->
                        <h2 align="center">Student Report Card</h2>
                        <div class="oe_structure"/>
                          <div class="row">
                            <div class="col-md-4">
                                <b>Name: </b> <span t-field="o.name"/>
                                <br/>
                                <b>Email: </b> <span t-field="o.email"/>
                                <br/>
                                <b>Department: </b> <span t-field="o.department_id.name"/>
                                <br/>
                                <b>Semester: </b> <span t-field="o.semester_id.name"/>
                                <br/>
                                <span>Subject Mark List</span>
                                <table class="table table-condensed" style="border: 2px solid black !important;">
                                    <thead>
                                        <tr>
                                            <th name="th_name" class="text-left">
                                                <span>Subject Name</span>
                                            </th>
                                            <th name="th_fullmark" class="text-left">
                                                <span>Full Mark</span>
                                            </th>
                                            <th name="th_passmark" class="text-left">
                                                <span>Pass Mark</span>
                                            </th>
                                            <th name="th_obtained" class="text-left">
                                                <span>Obtained Mark</span>
                                            </th>
                                        </tr>
                                    </thead>
                                    <t t-foreach="subject_lists" t-as="sub">
                                        <tr>
                                            <td>
                                                <t t-esc="sub['name']"/>
                                            </td>
                                            <td>
                                                <t t-esc="sub['full_mark']"/>
                                            </td>
                                            <td>
                                                <t t-esc="sub['pass_mark']"/>
                                            </td>
                                            <td>
                                                <t t-esc="sub['obtained_mark']"/>
                                            </td>
                                        </tr>
                                    </t>
                                </table>
                            </div>
                            </div>

                        <br />
                    </div>

                    <t t-out="values['first']"/>
                    <t t-out="values['second']"/>
                    <t t-out="values['third'][0]"/>


                    <!-- for watermark -->
                    <div style='position:absolute;text-align:center;z-index:-1;border:0;opacity:0.5;padding-top:-50px;padding-left:145px;'>
                    <img t-attf-src="data:image/png;base64,{{o.image}}" style="height:300px;width:300px;opacity:0.15;"/>
                    </div>
                </t>
            </t>
        </t>
    </template>

</odoo>



 

 

>t-field=''"# to show dynamic data in report,you cannot show variable data using t-field , it throw an error

>t-out="" # to show dynamic data in report, you can also show varibale value as well

>t-esc="" # it used to show varibale value in report for version less than 15 now it is replace by t-out

 


<!-- for many2one  -->
<span t-field="o.department_id.name"/>
<span t-field="o.semester_id.name"/>

<!-- for many2many  -->

<t t-foreach="o.country_ids" t-as="country">
    <t t-field="country.name"/>
</t>

<!-- for one2many  -->

<t t-foreach="o.subjects_ids" t-as="sub">
    Name:<t t-field="sub.name"/> and school is <t t-field='sub.school_id.name'/>
</t>

 

 

how to print report on button click

@api.multi
def print_report(self):
     return self.env.ref('module_name.report_record_id').report_action(self)

 

extra in odoo report

<template id="template_id" name="template_name">
<t t-set="count" t-value="1"/>
<!-- set variable and value  -->
<span  t-esc="count"/>
<!-- fetch value varibale  -->

<t t-foreach="">
 <span t-esc='count'/>

 <t t-set='count' t-value='count+1'/>
</t>
</template>

 

How to make customised Header by using paper formate

    <record id="action_report_school_student" model="report.paperformat">
        <field name="name">Student Report Card</field>
        <field name="default" eval="True"/>
        <field name="format">A4</field>
        <field name="page_height">0</field>
        <field name="page_width">0</field>
        <field name="orientation">portrait</field>
        <field name="margin_top">5</field>
        <field name="margin_bottom">5</field>
        <field name="margin_left">5</field>
        <field name="margin_right">5</field>
        <field name="header_line" eval="False"/>
        <field name="header_spacing">0</field>
        <field name="dpi">90</field>     
    </record>

 

 

How to remove print btn and rename 

<report 
id="",
model="",
paperformat="model_name.id_of_report",
menu="False" ,  # to rename or not shown
print_report_name="Staff Report",
/>

 

How to print multiple Record in single by coreect formate or mass print

<t t-foreach="docs">
<div class='page' style='page_break_before:always;'>
<div style='width:100%'>

 

How to call python function at the time of printing report

<template id="template_id" name="template_name">
<t t-set="values" t-value="o.get_value_in_report()"/>
<!-- set variable and value  -->
<span  t-esc="values"/>
<span  t-esc="values['record1']"/>
<span  t-esc="values['record2']"/>
<span  t-esc="values['students][0]"/>
<!-- fetch value varibale  -->
</template>


    def get_value_in_report(self):
        dict={
            "record1":"",
            "record2":"",
            "students":[1,2,3,45,6]
            
        }
        # return dictionary as to call in xml
        return dict 

 

Excel report in Odoo

 

ir.actions.report

ir.actions.server

ir.actions.act_window

ir.actions.client

ir.actions.url

<field name="context">{'res_partner_search_mode':'customer'}</filed>

 

else part also need to be define in cimputed field, u need to loop record  for cumputed field.

in search view you can also add filter_domain as filter_domain="['|', ('name','ilike',self),('address','ilike',self)]"

 

 

 

Archive options and Ribbons

 

to show the archive and unarchive option in tree and form view you need to define the active attribute in model as 

active=fields.Boolean(default=True)

then archived and unarchive option will automatically shown in tree view. if you want to show archive option in form view then you need to define active field in form view

<field name="active" invisible="1"/>

 

      <widget name="web_ribbon" title="archived" bg_color="bg-danger"
            attrs="{'invisible':[('active','=',True)]}"/>

 

 

 

 

 

 

 

 

 

 

 

 

 


About author

author image

Amrit Panta

Python developer, content writer



3 Comments

Amanda Martines 5 days ago

Exercitation photo booth stumptown tote bag Banksy, elit small batch freegan sed. Craft beer elit seitan exercitation, photo booth et 8-bit kale chips proident chillwave deep v laborum. Aliquip veniam delectus, Marfa eiusmod Pinterest in do umami readymade swag. Selfies iPhone Kickstarter, drinking vinegar jean.

Reply

Baltej Singh 5 days ago

Drinking vinegar stumptown yr pop-up artisan sunt. Deep v cliche lomo biodiesel Neutra selfies. Shorts fixie consequat flexitarian four loko tempor duis single-origin coffee. Banksy, elit small.

Reply

Marie Johnson 5 days ago

Kickstarter seitan retro. Drinking vinegar stumptown yr pop-up artisan sunt. Deep v cliche lomo biodiesel Neutra selfies. Shorts fixie consequat flexitarian four loko tempor duis single-origin coffee. Banksy, elit small.

Reply

Leave a Reply

Scroll to Top