Report MarkUp Language (RML)

Report Markup Language (RML)

What is RML?
  • XML based formatting
  • Cross-platform
  • Quite simple to learn and use 

Introduction

  • Page Layout Description
  • RML
  • RML2PDF
  • No Programming
  • Outputs PDF
Report Markup Language (RML) is used by OpenERP for formating .pdf reports. It’s an XML format and it can be generated from web applications, such as Django. Satchmo uses rml templates for shipping labels, invoices and packing slip.

One way to generate those templates it to write the RML file by hand. Various tools have been developed to simplify the process, such as using OpenOffice / OpenLibre to make the templates (see section below) and which is then transformed from an .sxw file to .rml using   SXW2RML  which in turn is transformed into a .pdf. 

./openerp_sxw2rml.py template.odt > template.rml

You can use python-trml2pdf to see the results:
apt-get install python-trml2pdf

and then
trml2pdf template.rml > template.pdf

Report Lab

Report Lab provide a free and commercial solutions for using RML

http://www.reportlab.com/accounts/register/complete/

To install these solution you can download test software version from their website -> https://www.reportlab.com/software/installation/. To run these tools there are some prerequisites as follows: 

  * Download and install Python (version 2.7, 2.6 OR 2.5 recommended)
  * Download and install Python Imaging Library for the relevant version of Python. This is required for the use of bitmap images in your PDFs.
  * To use Diagra, you will need to download and install the following:
  * Python MegaWidgets. A windows installer can be downloaded here; the Ubuntu package name is python-pmw.
  * On Linux, you also need python TkInter (ubuntu package python-tk).

For my installation installed: 

1. diag software fro windows -> https://www.reportlab.com/devnet/Pmw-1.3.2.win32.exe

2.. **reportlab-2.5.win32-py2.7.exe** -  is the free version of the above but has limited functionality -> https://www.reportlab.com/ftp/reportlab-2.5.win32-py2.7.exe

3. rlextra-2.5.win32-py2.7.exe** - is the commerical version of report lab -> https://www.reportlab.com/devnet/rlextra-2.5.win32-py2.7.exe
The .exe installer includes RML, Preppy, PageCatcher and the pyRXP XML parser  for evaluation purposes. 


It is recommend that Windows users also install the Python Windows Extensions, a useful set of modules which includes COM support, WinAPI calls, ODBC and the PythonWin IDE.


Editing RML files in OpenERP 7 directly

The location of files on the OpenERP 7 (deb installation) are: 
  • /usr/lib/pymodules/python2.7/openerp/addons/<module name>/<reports>/<report name>.rml

for example the purchase order form is located:
  • /usr/lib/pymodules/python2.7/openerp/addons/purchase/report/order.rml
The files are similar to JavaScript code and with some experience can be edited directly. Alternatively use the OpenOffice / OpenLibre plugin

You can edit these RML files directly on the filesystem, but it  will affect all databases on your system.

However, if you use OpenOffice to edit the RML then the binary file is stored in the database and only affects that database. Any changes to the RML however will have no further effects to your database where you've edited the report using OpenOffice.  

If you want to switch back to RML editing after you have edited in OpenOffice, you need to re-open the report in OpenOffice and save it as an SXW file. Then you need to convert it into RML (addons/base_report_designer/openerp_sxw2rm/openerp_sxw2rml.py <file.sxw> <file.rml>). Then delete the binary RML field in the database and copy the RML file back to the server.

If you then decide to edit back in OpenOffice you can do that, then just simply regenerate the RML, copy it back to the server and delete the RML in the database.

This way you can edit either the RML or via OpenOffice or any combination, you just have to remember where things get changed.

This can all be done on a production database with users actively producing reports - the instant you delete the RML from the database (ir_act_report_xml), the RML on disk will be used.

After you have edited the report the first time in OpenOffice it will be stored in database table ir_act_report_xml in fields:

  • report_rml_content_data (RML) and
  • report_sxw_content_data (SXW)

The report is only taken from file if those fields are empty, which is the case after a fresh install.


If you need to delete the binary data in the database then:

1.Open pgAdmin. check your report id in ir_act_report_xml. Remember to login to the database as follows:

/doc_static/7.0/_images/new_server_registration.png

(password is admin by default.)

2.Open a query.

SELECT id FROM ir_act_report_xml WHERE model = 'sale.order';

3.put the id (ir_act_report_xml.id) result into place of your_id

update ir_act_report_xml SET report_rml_content_data = NULL WHERE id = your_id;

4.Run and enjoy the rml edition. :-)

One more interesting tag: if you want to print out the creator of an entry (create_uid) or the last one who wrote on an entry (write_uid) you have to add something like this to the class your report refers to:


'create_uid': fields.many2one('res.users', 'User', readonly=1)
For example if you intended to update the purchase order with the creator's name, then edit the /addons/purchase/report/purchase_report.py file with the code depicted above.  


and then in your order.rml  file enter the following value,  to print out the corresponding name:
<para style="P1">[[ o.create_uid.name ]]</para>

If you forget the openerp master or database password this is stored in the  ~/.openerp_serverrc file or the openerp-server.config file

Refs & eBooks:
Comments