How to create Qweb report in odoo

Hello All,

         I would like to share with you how to create a Qweb report in odoo [OpenERP].let we go stap by stap to create Qweb report in odoo [OpenERP].

What is Qweb Report ??

Qweb Report is the newest version of the Odoo reporting Format and its uses the bootstrap css classes and Qweb Template Engine for Make Quick Report Design in Odoo.

About Bootstrap :

Bootstrap is a free collection of tools for creating websites and web applications.It contains HTML and CSS-based design templates for typography, forms, buttons, navigation and other interface components, as well as optional JavaScript extensions

Expressions used in Odoo report templates :

There are some magic variables used in the report rendering. The main ones are the following:
docs
        records for the current report
doc_ids
        list of ids for the docs records
doc_model
       model for the docs records
time
       a reference to time from the Python standard library

translate_doc 
 
a function to translate a part of a report. It must be used as follow:
<t t-foreach="doc_ids" t-as="doc_id">
<t t-raw="translate_doc(doc_id, doc_model, 'partner_id.lang', account.report_invoice_document')"/>
</t>
user
     res.user record for the user printing the report
res_company
      record the current user‘s company

Custom Report

A generic report use the default rendering context, containing the magic variables as explained before. If you want a new rendering context containing anything you want to process your data Odoo AbstractModel, a custom module is needed. These reports are called “particular report”.

For a particular report, you have to write an Odoo Model containing a render_html method. Classically, this method returns a call to the original QWeb render with a custom rendering context.


from openerp import api, models

class ParticularReport(models.AbstractModel):
_name = 'report.<<module.reportname>>'
@api.multi
def render_html(self, data=None):
report_obj = self.env['report']
report = report_obj._get_report_from_name('<<module.reportname>>')
docargs = {
'doc_ids': ids,
'doc_model': report.model,
'docs': self.env[report.model].browse(ids),
}
return report_obj.render('<<module.reportname>>', docargs)



Create Report  in Qweb odoo [OpenERP]

Steps to create in Following Ways ::

STEP 1 ::

Create View File For Rendring the Qweb in Odoo
the view file it self uses the the Bootstrap classes for designing the Qweb Report.

Create custom module in odoo and then  Navigate

YOUR MODULE NAME/View/yourview_file.xml

And also add the Entry of xml in the __openerp__.py file

STEP 2 ::

Create Python class for report in report Dir

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

class your_class_name(report_sxw.rml_parse):

def get_lines(self, user,objects):
lines=[]
for obj in objects:
if user.id==obj.user_id.id:
lines.append(obj)
return lines

What ever function Which You want to access in the Qweb Template which are define in the class

We must have to add the Entry in it constructor like this

def __init__(self, cr, uid, name, context):
super(your_class_name, self).__init__(cr, uid, name, context)
self.net_total=0.0
self.localcontext.update({
'time': time,
'get_lines': self.get_lines,

Add the Entry For the report class which is inherited the osv.AbstractModel object

class report_your_class_name(osv.AbstractModel):
_name = 'report.Your_Module_name.report_reportname'
_inherit = 'report.abstract_report'
_template = 'Your_Module_name.report_reportname'
_wrapped_report_class =your_class_name

Navigate :

YOUR MODULE NAME/report/reportclass.py

And also add the Entry in the __init__.py file


STEP 3 ::

Add the Menu Action for Print The Report
YOUR MODULE NAME/report_file.xml

<report
id="action_report_report_id"
string="String to Display in Menu"
model="your_model"
report_type="qweb-pdf"
name="your_module_name.report_your_reportid"
file="your_module_name.report_yourreportid"
/>
And also add the Entry of xml in the __openerp__.py file


Special function ::

Hear In odoo use the special widget for print the currency symbol,
add the company address,partner address and many more

like this..

<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>
hear t-field-options attribute use the widget to print the partner detail in Odoo
like name,address,street,country etc... 

Same things for the currency symbol

<td class="text-right">
<span t-field="o.amount_untaxed" t-field-options='{"widget": "monetary", "display_currency": "o.currency_id"}'/>
</td>


Thanks,
Mayur Maheshwari (OpenERP/odoo)
Skype: mayur_maheshwari1


15 comments:

  1. Hi,
    Thank you for the information. I am trying to understand how to add the customer's title e.g. Mr or Mrs in front of the name on the reports, but as it is done with a widget I don't understand how to do it -

    Do you have any thoughts?
    Many thanks
    Gill

    ReplyDelete
    Replies
    1. Mayur Maheshwari - Techno-Functional Consultant Odoo (Openerp): How To Create Qweb Report In Odoo >>>>> Download Now

      >>>>> Download Full

      Mayur Maheshwari - Techno-Functional Consultant Odoo (Openerp): How To Create Qweb Report In Odoo >>>>> Download LINK

      >>>>> Download Now

      Mayur Maheshwari - Techno-Functional Consultant Odoo (Openerp): How To Create Qweb Report In Odoo >>>>> Download Full

      >>>>> Download LINK sy

      Delete
  2. Hi, I am struggling to get this working and I really would like to learn how to do it. Do you happen to have the code of this module somewhere so I can study it better? Thanks SO much

    ReplyDelete
  3. How can I know what widgets are there to use ?

    ReplyDelete
  4. How can I know what widgets are there to use ?

    ReplyDelete
  5. HI. This guide was very helpful. However i would like to know if we can use our own custom css. Can we add it?

    ReplyDelete
  6. thinks for this support, clear & effective

    ReplyDelete
  7. When and how do you use the get_lines function in the QWeb view?

    ReplyDelete
  8. When and how do you use the get_lines function in the QWeb view?

    ReplyDelete
  9. Like RML can we use Frames in Qweb report

    ReplyDelete
  10. Great blog, this is a useful and informative blog. Post similar content in future.
    Best Odoo ERP Software Development Company

    ReplyDelete
  11. ReportMate extracts all the needed information for all Odoo Model fields and displays complex data in a single view. The first Odoo Professional Reporting App through which Customers can create powerful, richly formatted, dynamic reports in the Tree, List, Graph, and Pivot format.

    ReplyDelete
  12. Ksolves ReportMate is the app that is being talked about here! It is the first professional reporting app in Odoo through which you can create robust, lavishly formatted, dynamic reports in numerous formats such as the List, Graph, Tree, and Pivot. Know More: https://store.ksolves.com/shop/odoo-apps/reportmate-63

    ReplyDelete
  13. Great blog, this is a useful and informative blog. You can try checking out the Ksolves Odoo ReportMate,It can definitely help you with better financial reports. https://store.ksolves.com/shop/odoo-apps/reportmate-63

    ReplyDelete