跳至内容
菜单
此问题已终结
1 回复
9710 查看

Hello,

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!

形象
丢弃
最佳答案

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

<table>
    <tr>
        % for key,value in month_data(emp_id).iteritems():
            <td>
                ${value}
            </td>
        % endfor
    </tr>
</table>

-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']

        self.localcontext.update({
            '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

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

相关帖文 回复 查看 活动
1
7月 24
1256
1
3月 15
3576
0
3月 15
3460
0
3月 15
3965
1
3月 15
550