3a2roub
3a2roub

Reputation: 573

openerp reporting syntax

I've been struggling trying to mimic in openerp a report found in Tryton for the module Health GNU. In their report folder lies a report.odt file very similar to any sxw report found in openerp, with a few exceptions that is. For instance, instead of openERP's:

[[repeatIn(objects,'test')]]

we have an opening and closing tag of for making the previous exmaple as such:

<FOR EACH="TEST IN OBJECTS"> .... </FOR>

How can I mimic the following in a traditional sxw report:

<for each="case in test.critearea">
<if test="case.excluded==0"> #this is outside the table
...values in table... #table starts here
</if>
<for>
which basically excludes an entire row when matched.
using familiar syntax such as [[ case.excluded==False ]] didnt work.

Upvotes: 2

Views: 1381

Answers (4)

Mario
Mario

Reputation: 81

You can iterate on a list generated by a function defined on report's related .py file.

Just look for examples on the addons, there are plenty of them, like:

account/report/account_aged_partner_balance.rml: [[ repeatIn(get_lines(data['form']), 'partner') ]]

Upvotes: 2

Phil Frost
Phil Frost

Reputation: 3966

Since the contents of [[...]] are just python code, you could use list comprehesions to filter out things before the iteration. So instead of this:

[[repeatIn(cases,'case')]]

try this:

[[repeatIn([c for c in cases where not case.excluded], 'case'])

or you could use the builtin filter():

[[repeatIn(filter(lambda c: not c.excluded, cases), 'case'])]]

Upvotes: 1

simahawk
simahawk

Reputation: 2431

tryton report system is based on relatorio lib and uses odt/ods as you discovered. if you want to use something similar you have to use Aeroo (formerly report_openoffice). It's not compatible with RML stuff.

This approach is much more sane that openerp's internal one and will boost you 'report productivity' a lot. You may also consider using report_webkit that allows you to write report in HTML.

Upvotes: 4

3a2roub
3a2roub

Reputation: 573

in the first table cell, this worked:
[[((case.excluded == False) or removeParentNode('blockTable')) and '']][[case.name]]
although i am still interested in knowing if there's a more logical way instead of destroying the entire created blocktable, especially since i'll be trying to figure out how not to leave an empty line when removing the parent node 'blocktable'.

Upvotes: 2

Related Questions