Вы находитесь на странице: 1из 10

29/9/2015 QWeb Report in Odoo 8 | Zesty Beanz

Seleccionar idioma ​▼ Search

Call Us Free

Home » Blogs » anju's blog

QWeb Report in Odoo 8

Contact Form

Your Name Your Email Captcha 92990

Send Message

QWeb Report in Odoo 8


February 25, 2015 By anju

QWeb is the primary templating engine used by Odoo. It is an XML


templating engine and used mostly to generate HTML fragments and
pages.

It's implemented fully in javascript and rendered in the browser.

http://www.zbeanztech.com/blog/qweb-report 1/10
29/9/2015 QWeb Report in Odoo 8 | Zesty Beanz

Each template file


(XML files)
contains multiple
templates, where
template engine
usually have a 1:1
mapping between
template files and
templates.

The rationale behind using QWeb instead of a more popular template


syntax is that its extension mechanism is very similar to the openerp view
inheritance mechanism. Like openerp views a QWeb template is an xml
tree and therefore xpath or dom manipulations are easy to performs on it.

1. Creating a new XML file


The first step to create your own new report is to make a new XML file. This
file should be placed under yourModuleName/views and you can name it
as you wish. In this file you will define the template id’s and names, which
will later on be used by your Odoo to find the correct report.

The minimal code looks like this:

The template’s id must be the name specified in the report declaration; for
example account.report_invoice for the above report. Since this is a QWeb
template, you can access all the fields of the docs objects received by the
template. Calling external_layout will add the default header and footer on

http://www.zbeanztech.com/blog/qweb-report 2/10
29/9/2015 QWeb Report in Odoo 8 | Zesty Beanz

your report. The PDF body will be the content inside the <div class="page">.

There are some specific variables accessible in reports, mainly:


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.If you wish to translate reports (to
the language of a partner, for example), you need to define two templates:
The main report template
The translatable document
You can then call translate_doc from your main template to obtain the
translated document.

 It must be used as follow:

The name of the template id (from the first record) should be the same as
the name for the t-raw that handles translations. In the t-raw you need to
add the module name before this name with a dot. The main template calls

http://www.zbeanztech.com/blog/qweb-report 3/10
29/9/2015 QWeb Report in Odoo 8 | Zesty Beanz

translate_doc with partner_id.lang as a parameter, which means it uses a


custom report model to access a res.partner record.

user
res.user record for the user printing the report

res_company
record for the current user‘s company

2.Add the report to the XML file responsible for reports


Every module has a file that makes a reference to every single report in the
module. This is done by a item, which can be found in the XML file.
This file always has the same name structure. It starts with the name of
your module, an underscore and then report.xml. Its found in the first level
of the directory of your module.
The filename is always yourModuleName_report.xml. Now open up this file
and you will see a tag for every report that exists in this module.
The next step for us is to add a new tag for our own report. The code looks
like this:

3.Declare a paper format

Paper formats are records of report.paperformat and can contain the


following attributes:

name (mandatory)
only useful as a mnemonic/description of the report when looking for one
RVICESin a list
CASE STUDIES
of some sort NEWS BLOGS CONTACT US

http://www.zbeanztech.com/blog/qweb-report 4/10
29/9/2015 QWeb Report in Odoo 8 | Zesty Beanz

description
a small description of your format

format

either a predefined format (A0 to A9, B0 to B10, Legal, Letter, Tabloid,...) or


custom; A4 by default. You cannot use a non-custom format if you define
the page dimensions.

dpi
output DPI; 90 by default

margin_top, margin_bottom, margin_left, margin_right


margin sizes in mm

page_height, page_width
page dimensions in mm

orientation
Landscape or Portrait

header_line
boolean to display a header line

header_spacing
header spacing in mm

You have now everything to create reports

http://www.zbeanztech.com/blog/qweb-report 5/10
29/9/2015 QWeb Report in Odoo 8 | Zesty Beanz

1. A template (ir.ui.view record)


2. A report record (ir.actions.report.xml record)
3. And maybe a specific paper format (report.paperformat record)

Parser Class:
To create parser class you need to import report_sxw.rml_parse.
The methods you want to access in report must be updated in localcontext
in parser class.
Create another class which which inherits features of osv.AbstractModel
and it creates bond between parser class and template engine.
This new class have few parameters and each of the parameters have fixed
pattern so must follow it.
_name = ‘report.<module_name>.<report_name>’
_inherit = ‘report.abstract_report’
_template = ‘<module_name>.<report_name>’
_wrapped_report_class = <parser_class_name>

anju's blog Add new comment ShareThis

This means it uses a custom

Submitted by Philip Johnson (not verified) on Thu, 08/27/2015 - 07:23.

This means it uses a custom report model to access a res.partner record.

buy targeted twitter followers

reply

http://www.zbeanztech.com/blog/qweb-report 6/10
29/9/2015 QWeb Report in Odoo 8 | Zesty Beanz

Thanks for the detailed

Submitted by Keith Mattiso (not verified) on Thu, 07/02/2015 - 12:01.

Thanks for the detailed information about Web Report. It is good and I like
the way you make this tutorial in the help of people looking for these
results. Also rating of essay services is good for the help and support of the
students.

reply

Thanks Anju, This Post help

Submitted by Samba (not verified) on Mon, 06/22/2015 - 14:11.

Thanks Anju,
This Post help me allot. I need some more explanation on the pdf report
development. I have an issue
https://www.odoo.com/forum/help-1/question/how-can-i-change-report-
file-...

. I want to change the pdf report file name to sale.report_sale to "quotation


XXXX", here XXXX would be the quotation number. Is it posiible?

reply

http://www.zbeanztech.com/blog/qweb-report 7/10
29/9/2015 QWeb Report in Odoo 8 | Zesty Beanz

def print_report(self,cr,

Submitted by Anonymous (not verified) on Mon, 08/31/2015 - 04:55.

def print_report(self,cr, uid, ids, context=None):


if context is None:
context = {}
data = self.read(cr, uid, ids)[0]
self_browse = self.browse(cr, uid, ids)

datas = {
'ids': [data.get('id')],
'model': 'sale.order',
'form': data
}
return {
'type': 'ir.actions.report.xml',
'report_name': 'sale.order.report',
'datas': datas,
'name': 'Quotation ' + self_browse[0].name
}

reply

Very incomplete guide, not

Submitted by Nehemias (not verified) on Wed, 05/27/2015 - 17:35.

Very incomplete guide, not helpful. :(

reply

http://www.zbeanztech.com/blog/qweb-report 8/10
29/9/2015 QWeb Report in Odoo 8 | Zesty Beanz

Hi, If I modify the

Submitted by Carmelo Carrillo (not verified) on Tue, 04/07/2015 - 09:45.

Hi,

If I modify the account_report.xml for add a new invoice, how I do to view


this new record on odoo? Have I restart the odoo server?

Thank you.

reply

Yes. You have to restart and

Submitted by Anonymous (not verified) on Mon, 08/31/2015 - 04:35.

Yes. You have to restart and upgrade the module.

reply

Yes. You have to restart and

Submitted by Anonymous (not verified) on Mon, 08/31/2015 - 04:31.

Yes. You have to restart and upgrade the module.

reply
http://www.zbeanztech.com/blog/qweb-report 9/10
29/9/2015 QWeb Report in Odoo 8 | Zesty Beanz

+91 471 2700171


Support - Sales
contact@zbeanztech.com
24x7x365

Talk to u

Live Chat

Email Us

Good Support

Zesty Beanz. HOME ABOUT SERVICES BLOG CONTACT


© 2015 Zesty Beanz . All Rights Reserved. 2000 - 2015

http://www.zbeanztech.com/blog/qweb-report 10/10

Вам также может понравиться