Odoo Help


Is it possible to generate reports with dynamic columns?

on 7/18/13, 3:04 PM 3,290 views


This is another of mine "is it possible" rather than "how to" questions. I need to understand the possibilities and limitations of reports before embarking into the creation of a custom module.

For this I need to understand if it is possible to create reports with X number of columns. X will come from the amenities a hotel have. So it will change depending on the hotel selected from a wizard before generating the report.

Lets say Hotel XYZ has 5 amenities I need a report with 5 columns where I will show the payments each guest made for each amenity, then Hotel YYY will have 10 amenities and I need to do the same but for all 10 amenities.

Will it be possible to code a report (I am currently using the OpenOffice plugin but any thing that work would be fine) flexible enough to do this with OpenERP?

Thanks for any tip!


Timo Talvitie, Vizucom Oy

--Timo Talvitie, Vizucom Oy--
| 5 4 7
Tampere, Finland
--Timo Talvitie, Vizucom Oy--

Lead developer at Vizucom.

Timo Talvitie, Vizucom Oy
On 7/18/13, 4:57 PM

At least the Mako reports should be flexible enough for your needs. With them you can create HTML tables and use for loops to format the rows and columns to fit your dataset. Even though you're working with HTML and CSS to format and style the data, the result will still be a PDF file.

If you want to see a basic example of how the Mako reports work, you can download a very nice module called sale_order_webkit, it's made by camptocamp and is available at v6apps.openerp.com/addon/6581

The example deals with pulling data from a single model, but if you're working with a complex dataset and need data from many tables, you can also directly query the database with cr.execute and pass the result to be formatted with Mako. We tried this direct query approach with some timesheet-related data and it worked very well.

Edit: here's a small code snippet from a .mako file

        % for key,value in month_data(emp_id).iteritems():
        % endfor

-emp_id and month_data are attached to the report parser on the fly with self.localcontext.update(), after which they are accessible by the .mako template

class TimesheetReportParser(report_sxw.rml_parse):
    def __init__(self, cr, uid, name, context):
        super(TimesheetReportParser, self).__init__(cr, uid, name, context=context)
        emp_id = context['active_id']

            'emp_id': emp_id, 
            'month_data': self._fetch_hours,

-emp_id is the employee ID of the person whose timesheet report is currently being generated

-month_data's contents are provided by a _fetch_hours() function that is also defined inside the parser class, it does a cr.execute() and returns a dictionary of values related to the current employee. Those values are then printed out in a for loop in the .mako file

Thanks a lot! I will be testing Mako reports right now. So basically they work in the same way as building a website? That is very interesting. Thanks again

on 7/18/13, 7:33 PM

As far as the formatting goes, pretty much yes. I added a quick example of the .mako side to show the basic idea.

Vizucom Oy, Timo Talvitie, Vizucom Oy
on 7/19/13, 3:55 AM

About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)


Asked: 7/18/13, 3:04 PM
Seen: 3290 times
Last updated: 3/16/15, 8:10 AM