Odoo is the world's easiest all-in-one management software. It includes hundreds of business apps:
CRM | e-Commerce | Accounting | Inventory | PoS | Project management | MRP | etc.
I'm trying to make a conditional table header in reports which shows Discount column only when there is a discount. The condition works fine but I have an issue with formatting. Since blockTable colWidths parameter should correspond to the number of columns, I get an error when one of the columns gets deleted.
So far I came up with this markup as a test case:
<docAssign var='d' expr='0'/> <section> <para>[[repeatIn(o.order_line,'line')]]</para> <para>[[ line.discount > 0 or removeParentNode('para') ]] <docExec stmt='d+=1'/></para> </section> <docIf cond='d>0'> <para style="Standard">There are discounts</para> <docElse/> <para style="Standard">No discounts</para> </docIf> <docPara expr='d' format='The number of discounts is %(__expr__)d' />
However, I don't see any output from docIf condition and docPara. Moreover, examples of conditional format operators from RML User Guide doesn't produce any output either. Does someone have any idea of how to work around that?
AFAIK, conditional formatting is not implemented in the OpenERP's RML processing. A way to work around it is to use [[ ]] block, such as:
[[ line.discount > 0 and 'There are discounts' or 'No discounts' ]]
If this is supposed to be based on total discount, then you need to create the function to calculate/check the total discount.
The similar approach goes for the "The number of discounts is XXXX" line:
<para> The number of discounts is [[ getDiscountedLine() and getDiscountedLine() or removeParentNode('para') ]] </para>
Where getDiscountedLine() method need to be implemented in the python code (the same method can be used for the logic above)
Ivan's answer would be the correct way to approach this particular issue.
However, I recently needed to implement the docIf RML flowable (in OpenERP 7.0) to guarantee that invoices generated would always be an even number of pages so they could be easily printed double-sided. I figured I'd share the implementation, as there is very little explanation elsewhere on how to do this.
Here's the RML of the bottom of the invoice:
</pto> <docIf cond="doc.page%2==1"> <pageBreak/> </docIf> </story> </document>
To make OpenERP properly parse the docIf flowable, you need to edit the following file:
Before line 888 (the else block reporting that the flowable is not implemented), add the following lines:
elif node.tag == 'docIf': return platypus.flowables.DocIf(node.get('cond'), self.render(node))
For reference, the surrounding code in trml2pdf.py should now look something like this (new lines in bold):
elif node.tag == 'frameEnd': return EndFrameFlowable() elif node.tag == 'hr': width_hr=node.get('width') or '100%' color_hr=node.get('color') or 'black' thickness_hr=node.get('thickness') or 1 lineCap_hr=node.get('lineCap') or 'round' return platypus.flowables.HRFlowable(width=width_hr,color=color.get(color_hr),thickness=float(thickness_hr),lineCap=str(lineCap_hr)) elif node.tag == 'docIf': return platypus.flowables.DocIf(node.get('cond'), self.render(node)) else: sys.stderr.write('Warning: flowable not yet implemented: %s !\n' % (node.tag,)) return None
The end result is that you can now utilize RML docIf statements in templates, and in my example, all invoices printed will always be an even number of pages.
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.Register
Odoo Training Center
Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.Test it now
|Asked: 5/6/13, 12:30 PM|
|Seen: 3230 times|
|Last updated: 8/12/15, 1:24 PM|