qweb report introduction

Before start of introduction, odoo (former openerp) is open source, the source code is the best tutorial.

Eg, you can check point_of_sale module to check out how to write qweb report.

qweb report introduction

openerp v7 use webkit and rml, openerp v6 uses rml.
qweb report is the new report engine of odoo V8, webkit and rml is depreciated from v8.

qweb is also rendering engine for odoo web server. Thus, odoo standardise the web engine.

Guide line

This article talks about

  • qweb report introduction
  • how to create a qweb report

qweb report

main elements

** report registration in database
** report translation registration in database (optional)
** report layout in database
** customize rendering functions (optional) 

Qweb introduction

In general ,

  1. developer write xml code to create actions, report record, views, web layout.

  2. when installing modules, there actions, reports, views is saved in database.

  3. user click a button, open a new windows, it trigger the actions and Web javascript API. Web javascript will

    • find the view id and read layout code from databass render it into web
    • find record id and read record value from database render it into web
  4. when print report , odoo will trigger wkhtmltopdf library to render web into pdf document.

odoo qweb introduction

grammer

  • data
    t-field, t-esc

  • loop, condition

    
        

    ok

how to create a qweb report

0. moduel structure

module
    | report
        |   customize_report.py
    | views
        |   report_layout_view.xml
    | report.xml
    | __init__.py
    | __openerp__.py
    | ...

1. create a report

  • if no 2nd step, the value of file and name 2nd step.
  • if 2nd step, the value of should be the template id in 2nd step

2. create a report translation (optional)


create report layout

odoo is using bootstrap for web layout

http://www.w3cschool.cc/bootstrap/bootstrap-grid-system.html



create customize report rending function

There are two ways to registrating

method 1

odoo use this way to reuse the code of v7.

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

class sale_report_xxx(report_sxw.rml_parse):
    def _print_test(self):
        return "good"

    def __init__(self, cr, uid, name, context):
        super(sale_report_libiya, self).__init__(cr, uid, name, context=context)
        self.localcontext.update({
            'time': time,
            'cr':cr,
            'uid': uid,
            'curr_rec': self.curr_rec,
            'compute_currency': self.compute_currency,
            'print_test': self._print_test,
            'print_test2': "good2",
            'other_methods'self._other_methods,
        })

class report_pos_details(osv.AbstractModel):
    _name = 'report.sale_webkit_report_libiya.report_sale_order_xxx'
    _inherit = 'report.abstract_report'
    _template = 'module.report_sale_order_xxx'
    _wrapped_report_class = sale_report_xxx

Method 2

code taken from odoo documentation

from openerp import api, models


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

tips

website editor

After this module installed, website manager can edit report online once report type is set in backend to html.

After the online edit, the report can be changed back to pdf to print pdf document later.

Refs

  • odoo documentation
  • bootstrap grid

Elico Corp (shenzhen) is hiring

你可能感兴趣的:(qweb report introduction)