Merge branch 'master-pos-wms-fva'
[odoo/odoo.git] / openerp / addons / base / report / custom.xsl
1 <?xml version="1.0" encoding="utf-8"?>
2 <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format">
3
4 <xsl:template match="/">
5         <xsl:apply-templates select="report"/>
6 </xsl:template>
7
8 <xsl:template match="report">
9         <document filename="example_5.pdf">
10         <template leftMargin="1.5cm" rightMargin="1.5cm" topMargin="1.5cm" bottomMargin="1.5cm"
11             title="Reporting" author="Generated by OpenERP, Fabien Pinckaers">
12                 <xsl:attribute name="pageSize">
13                         <xsl:value-of select="/report/config/pageSize"/>
14                 </xsl:attribute> 
15                 <pageTemplate id="first">
16                         <pageGraphics>
17                                 <drawCentredString>
18                                         <xsl:attribute name="x">
19                                                 <xsl:value-of select="/report/config/pageWidth div 2"/>
20                                         </xsl:attribute>
21                                         <xsl:attribute name="y">
22                                                 <xsl:value-of select="/report/config/pageHeight - 56.69"/>
23                                         </xsl:attribute>
24                                         <xsl:value-of select="config/report-header"/>
25                                 </drawCentredString>
26
27                                 <fill color="(0.2,0.2,0.2)"/>
28                                 <setFont name="Helvetica" size="10"/>
29                                 <drawCentredString y="10mm">
30                                         <xsl:attribute name="x">
31                                                 <xsl:value-of select="/report/config/pageWidth div 2"/>
32                                         </xsl:attribute>
33                                         <xsl:value-of select="config/report-footer"/>
34                                 </drawCentredString>
35
36                                 <fill color="(0.969,0.2,0.2)"/>
37                                 <setFont name="Helvetica" size="8"/>
38                                 <drawString x="1.5cm">
39                                         <xsl:attribute name="y">
40                                                 <xsl:value-of select="/report/config/pageHeight - 56.69"/>
41                                         </xsl:attribute><xsl:text>OpenERP</xsl:text>
42                                 </drawString>
43
44                                 <fill color="(0.2,0.2,0.2)"/>
45                                 <drawRightString>
46                                         <xsl:attribute name="x">
47                                                 <xsl:value-of select="/report/config/pageWidth - 45"/>
48                                         </xsl:attribute>
49                                         <xsl:attribute name="y">
50                                                 <xsl:value-of select="/report/config/pageHeight - 56.69"/>
51                                         </xsl:attribute><xsl:value-of select="/report/config/date"/>
52                                 </drawRightString>
53                         </pageGraphics>
54                         <frame id="column" x1="1.5cm" y1="1.5cm">
55                                 <xsl:attribute name="width">
56                                         <xsl:value-of select="/report/config/pageWidth - 85"/>
57                                 </xsl:attribute> 
58                                 <xsl:attribute name="height">
59                                         <xsl:value-of select="/report/config/pageHeight - 100"/>
60                                 </xsl:attribute> 
61                         </frame>
62                 </pageTemplate>
63         </template>
64         <stylesheet>
65                 <paraStyle name="sum" fontName="Helvetica" textColor="green"/>
66                 <paraStyle name="sum_float" fontName="Helvetica" alignment="right" textColor="green"/>
67                 <paraStyle name="sum_end" fontName="Helvetica" textColor="red"/>
68                 <paraStyle name="sum_float_end" fontName="Helvetica" alignment="right" textColor="red"/>
69                 <blockTableStyle id="table">
70                         <blockValign value="TOP"/>
71                         <blockFont name="Helvetica" size="12" start="0,0" stop="-1,0"/>
72                         <blockBackground colorName="(0.8,0.8,0.8)" start="0,0" stop="-1,0"/>
73
74                         <lineStyle kind="GRID" colorName="lightgrey" thickness="0.3"/>
75
76                         <lineStyle kind="LINEBELOW" colorName="black" thickness="1.5" start="0,0" stop="-1,0"/>
77                         <lineStyle kind="LINEABOVE" colorName="black" thickness="1.5" start="0,0" stop="-1,0"/>
78                 </blockTableStyle>
79         </stylesheet>
80         <story>
81                 <blockTable style="table">
82                         <xsl:attribute name="colWidths">
83                                 <xsl:value-of select="/report/config/tableSize"/>
84                         </xsl:attribute> 
85                         <xsl:apply-templates select="header"/>
86                         <xsl:apply-templates select="group"/>
87
88                         <xsl:if test="group//@sum">
89                                 <tr>
90                                         <xsl:for-each select="group[position()=1]/record[position()=1]/field">
91                                                 <xsl:choose>
92                                                         <xsl:when test="position()=1">
93                                                                 <td><para style="sum_end">SUM</para></td>
94                                                         </xsl:when>
95                                                         <xsl:when test="@sum"> 
96                                                                 <xsl:variable name="ici">
97                                                                         <xsl:value-of select="@id"/>
98                                                                 </xsl:variable> 
99                                                                 <td><para style="sum_float_end"><xsl:value-of select="sum(../../../group/record/field[@id=$ici])"/></para></td>
100                                                         </xsl:when>
101                                                         <xsl:otherwise>
102                                                                 <td/>
103                                                         </xsl:otherwise>
104                                                 </xsl:choose>
105                                         </xsl:for-each>
106                                 </tr>
107                         </xsl:if>
108                         <xsl:if test="group//@count">
109                                 <tr>
110                                         <xsl:for-each select="group[position()=1]/record[position()=1]/field">
111                                                 <xsl:choose>
112                                                         <xsl:when test="position()=1">
113                                                                 <td><para style="sum_end">#</para></td>
114                                                         </xsl:when>
115                                                         <xsl:when test="@count"> 
116                                                                 <xsl:variable name="ici">
117                                                                         <xsl:value-of select="@id"/>
118                                                                 </xsl:variable> 
119                                                                 <td><para style="sum_float_end"><xsl:value-of select="count(../../../group/record/field[@id=$ici])"/></para></td>
120                                                         </xsl:when>
121                                                         <xsl:otherwise>
122                                                                 <td/>
123                                                         </xsl:otherwise>
124                                                 </xsl:choose>
125                                         </xsl:for-each>
126                                 </tr>
127                         </xsl:if>
128                         <xsl:if test="group//@avg">
129                                 <tr>
130                                         <xsl:for-each select="group[position()=1]/record[position()=1]/field">
131                                                 <xsl:choose>
132                                                         <xsl:when test="position()=1">
133                                                                 <td><para style="sum_end">AVG</para></td>
134                                                         </xsl:when>
135                                                         <xsl:when test="@avg"> 
136                                                                 <xsl:variable name="ici">
137                                                                         <xsl:value-of select="@id"/>
138                                                                 </xsl:variable> 
139                                                                 <td><para style="sum_float_end"><xsl:value-of select="sum(../../../group/record/field[@id=$ici]) div count(../../../group/record/field[@id=$ici])"/></para></td>
140                                                         </xsl:when>
141                                                         <xsl:otherwise>
142                                                                 <td/>
143                                                         </xsl:otherwise>
144                                                 </xsl:choose>
145                                         </xsl:for-each>
146                                 </tr>
147                         </xsl:if>
148                 </blockTable>
149         </story>
150         </document>
151 </xsl:template>
152
153 <xsl:template match="header">
154         <tr>
155                 <xsl:apply-templates select="field"/>
156         </tr>
157 </xsl:template>
158
159 <xsl:template match="group">
160         <xsl:if test="not(/report/config/totalonly)">
161                 <xsl:apply-templates select="record"/>
162         </xsl:if>
163         <xsl:if test="/report/config/groupby">
164                 <!-- SUM -->
165                 <xsl:if test="//@sum">
166                         <tr>
167                                 <xsl:for-each select="record[position()=1]/field">
168                                         <xsl:choose>
169                                                 <xsl:when test="/report/config/groupby = @id">
170                                                         <td><para style="sum"><xsl:value-of select="."/> (SUM)</para></td>
171                                                 </xsl:when>
172                                                 <xsl:when test="@sum"> 
173                                                         <xsl:variable name="ici">
174                                                                 <xsl:value-of select="@id"/>
175                                                         </xsl:variable> 
176                                                         <td><para style="sum_float"><xsl:value-of select="sum(../../record/field[@id=$ici])"/></para></td>
177                                                 </xsl:when>
178                                                 <xsl:otherwise>
179                                                         <td/>
180                                                 </xsl:otherwise>
181                                         </xsl:choose>
182                                 </xsl:for-each>
183                         </tr>
184                 </xsl:if>
185                 <!-- COUNT -->
186                 <xsl:if test="//@count">
187                         <tr>
188                                 <xsl:for-each select="record[position()=1]/field">
189                                         <xsl:choose>
190                                                 <xsl:when test="/report/config/groupby = @id">
191                                                         <td><para style="sum"><xsl:value-of select="."/> (#)</para></td>
192                                                 </xsl:when>
193                                                 <xsl:when test="@count"> 
194                                                         <xsl:variable name="ici">
195                                                                 <xsl:value-of select="@id"/>
196                                                         </xsl:variable> 
197                                                         <td><para style="sum_float"><xsl:value-of select="count(../../record/field[@id=$ici])"/></para></td>
198                                                 </xsl:when>
199                                                 <xsl:otherwise>
200                                                         <td/>
201                                                 </xsl:otherwise>
202                                         </xsl:choose>
203                                 </xsl:for-each>
204                         </tr>
205                 </xsl:if>
206                 <!-- AVG -->
207                 <xsl:if test="//@avg">
208                         <tr>
209                                 <xsl:for-each select="record[position()=1]/field">
210                                         <xsl:choose>
211                                                 <xsl:when test="/report/config/groupby = @id">
212                                                         <td><para style="sum"><xsl:value-of select="."/> (AVG)</para></td>
213                                                 </xsl:when>
214                                                 <xsl:when test="@avg"> 
215                                                         <xsl:variable name="ici">
216                                                                 <xsl:value-of select="@id"/>
217                                                         </xsl:variable> 
218                                                         <td><para style="sum_float"><xsl:value-of select="sum(../../record/field[@id=$ici]) div count(../../record/field[@id=$ici])"/></para></td>
219                                                 </xsl:when>
220                                                 <xsl:otherwise>
221                                                         <td/>
222                                                 </xsl:otherwise>
223                                         </xsl:choose>
224                                 </xsl:for-each>
225                         </tr>
226                 </xsl:if>
227         </xsl:if>
228 </xsl:template>
229
230 <xsl:template match="record">
231         <tr>
232                 <xsl:apply-templates select="field"/>
233         </tr>
234 </xsl:template>
235
236 <xsl:template match="field">
237         <xsl:choose>
238                 <xsl:when test="@level">
239                         <td><pre><xsl:value-of select="@level"/><xsl:value-of select="."/></pre></td>
240                 </xsl:when>
241                 <xsl:otherwise>
242                         <td><para><xsl:value-of select="."/></para></td>
243                 </xsl:otherwise>
244         </xsl:choose>
245 </xsl:template>
246
247 </xsl:stylesheet>