Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(86)

Side by Side Diff: doc/reports.rst

Issue 95068: start reports (Closed)
Patch Set: Updated based on comments. Created 15 years, 8 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 Reports 1 Reports
2 ####### 2 #######
3
4 Tryton can generate dynamic reports in many formats from report and style
5 templates. The reports are generated in one step as follows: a report template
6 in a special file format, explained later, is interpolated with dynamic data
7 and placed into document of the same file format. Tryton's ability to generate
8 documents in this way allows documents to be generated for OpenOfficeOrg which
ced1 2009/09/09 12:34:45 It is not linked to OpenOffice, you can use any ed
9 can be converted to third party formats, such as PDF. Extra libraries are·
10 required for this, see INSTALL for more information.
11
12 Report Templates
13 ****************
14
15 Report templates are files with a format supported by relatorio, that contain
16 snippets of the Genshi templating language.
17
18 Here is an example of the text that would be placed in an open office text
ced1 2009/09/09 12:34:45 open office text -> open document text
19 document, *.odt, that displays the full name and the address lines of the
20 first address of each party. The genshi code is placed in the template using
21 Functions->Placeholder->Text Fields. These are specific to OpenOfficeOrg.
ced1 2009/09/09 12:34:45 not specific to OOo but to odt
22
23 .. highlight:: genshi
24
25 ::
26
27 <for each="party in objects">
28 <party.full_name>
29 <if test="party.addresses">
30 <for each="line in party.addresses[0].full_address.split('\n')">
31 <line>
32 </for>
33 </if>
34 </for>
35
36 ··
37 Report styles
38 *************
39
40 Reports styles let you standardize the header, footer and styles of your
41 templates.
42
Ian Wilson 2009/07/21 08:47:22 I kind of understand this but I don't know a lot a
udono 2009/07/21 10:04:45 Oh yes, this could be. Maybe each document type ne
43
44 Report API
45 **********
46
47 .. _report:
48
49 Python API
50 ==========
51
52 .. _trytond.report.Report
53 .. autoclass:: trytond.report.Report
54 :members:
55 :undoc-members:
56
57 .. _trytond.ir.action.ActionReport
58 .. autoclass:: trytond.ir.action.ActionReport
59 :members:
60 :undoc-members:
61
62
63 XML Description
64 ===============
65
66 When defining an `ir.action.report` the following attributes are available:
67
68 * ``name``: The name of the report.
69
70 * ``report_name``: The name of the report model, for example
71 my_module.my_report. This is the name you would use with `pool.get`
72
73 * ``module_name``: If this report is of an existing model this is its name.
74 For example my_module.my_model. Custom reports that aren't of a specific
75 model will need to leave this blank.
76
77 * ``report``: The path to the template file starting with the module, for·
78 example my_module/my_report.odt.
79
80 * ``style``: The path to the style file starting with the module, for·
81 example, my_module/my_style.odt. If no style is to be used this field
82 will be blank.
83
84
85 Report Usage
86 ************
87
Ian Wilson 2009/07/21 08:47:22 This section is starting to get really confusing.
udono 2009/07/21 10:04:45 Don't understand correctly. Reporting system in Tr
88 Using genshi and open office reports
89 ====================================
90
91 Setting up an ODT file
92 ----------------------
93
94 If you are creating a report from scratch you should perform the following
95 steps:
96
97 - Remove user data
98 * "File > Properties..."
99 * Uncheck "Apply user data"
100 * Click on "Reset"·
101
102 - Select Style and Formatting
103 * Press F11 or "Format > Style and Formatting"
104 * Click on the drop down at the right top
105 * Select "Load Styles"
106 * Click on "From File..."
107 * Select a existing report ('company/header_A4.odt')
108 ····
109 - Set some parameters
110 * Set the zoom to 100% (View>Zoom)
111 * Set the document in read-only mode (Tools>Options>OpenOffice.org>Security)
ced1 2009/09/09 12:34:45 You can add that this is to speed opening
112
113 - Usage
114 * Use Liberation fonts
ced1 2009/09/09 12:34:45 This is only for inclusion into Tryton
115 * Try to use styles in report templates so that they can be extended in
116 report styles.
117
118 Using Genshi in an ODT file
119 ---------------------------
120 The genshi code is placed in the template using
121 Functions->Placeholder->Text Fields. These are specific to OpenOfficeOrg
ced1 2009/09/09 12:34:45 Not specific to Ooo
122 and can be found in the open office menu at Insert -> Fields -> Other and then
123 Functions -> Placeholder -> Text. Type genshi code into the Placeholder field.
ced1 2009/09/09 12:34:45 I don't know if it is good to give the path becaus
124 An alternative for embedding genshi that is supported by relatorio is use·
125 special hyperlinks, this is described in the examples on relatorio's site.
ced1 2009/09/09 12:34:45 As we don't want to use it, I don't think it is go
126
127 Also note that relatorio only supports a subset of genshi. The directives
128 that are supported are:
ced1 2009/09/09 12:34:45 How will we keep this uptodate. It is better to ha
129
130 - for
131 - if
132 - choose
133 - when
134 - otherwise
135 - with
136
137 See genshi's documentation for more information: `Genshi XML Templates`_
138
139 Examples
140 --------
141
142 The modules company, account_invoice and stock all contain helpful examples.
143
144 Also see relatorio's site for some examples:
145
146 - `Quick Example`_
147 ·
148 - `In Depth Introduction`_
149 ·
150 - `Example Documents`_
151
152
153 Accessing models from within the report
154 =======================================
155
156 By default instances of model that the report is for are passed in to the
157 report via a list of objects called `objects`. These objects behave just
158 as they would within trytond itself. You can access any of the models·
159 relations as well. For example within the invoice report each object is an
160 invoice and you can access the name of the party of the invoice via
161 `invoice.party.name`. Additional objects can be passed to a report. This
162 is discussed below in `Passing custom data to a report`.
163
164 Within tryton the model the report is for can be found by following the Menu to
165 Administration > UI > Actions > Report. Furthermore in tryton the fields
166 for that model can be found by following the menu to·
167 Administration > Model > Model. Model relation fields can be accessed to any
168 depth, for example, one could access `invoice.party.addresses` to get a list of
169 addresses for the party of an invoice.
170
171 Creating a simple report template for a model
172 =============================================
173
174 Less work has to be done if you just want a simple report representation of a
175 model. There are just 2 steps. First, create a report template file in a
176 format supported by relatorio. Second, describe your report in XML making
ced1 2009/09/09 12:34:45 Instead of XML, you can create a record in "Admini
Ian Wilson 2009/09/14 05:44:29 How complete is this? Can a printable report for
ced1 2009/09/14 06:02:31 Yes
177 sure to define the correct report_name and module_name.
178
179 Replacing existing Tryton reports
180 =================================
181
182 To replace an existing report you must deactivate the old report and activate
183 the new report.
184
185 For example to deactivate the invoice report:
186
187 .. highlight:: xml
188
189 ::
190
191 <record model="ir.action.report" id="account_invoice.report_invoice">
192 <field name="active" eval="False"/>
193 </record>
194
195 Then you must activate the new invoice report that exists in your new module:
196
197 .. highlight:: xml
198
199 ::
200
201 <record model="ir.action.report" id="report_invoice_new">
202 <field name="name">Invoice</field>
203 <field name="report_name">account.invoice</field>
204 <field name="model">account.invoice</field>
205 <field name="report">my_module/invoice.odt</field>
206 <field name="style">module_name/header_A4.odt</field>
207 </record>·
208
209 Passing custom data to a report
210 ===============================
211
212 TODO: Examples of overriding Report.execute.
213
214 In this example `Report.parse` is overridden and an employee object is·
215 set into context. Now the invoice report will be able to access the employee·
216 object.
217
218 .. highlight:: python
219
220 ::
221
222 class InvoiceReport(Report):
223 _name = 'account.invoice'
224 def parse(self, cursor, user_id, report, objects, datas, context):
225 employee_obj = self.pool.get('company.employee')
226 employee = False
227 if context.get('employee', False):
228 employee = employee_obj.browse(cursor, user_id,
229 context['employee'],
230 context=context)
231 context['employee'] = employee
232 return super(InvoiceReport, self).parse(cursor, user_id, report,
233 objects, datas, context)
234 InvoiceReport()
235
236
237 Replacing existing Tryton styles
238 ================================
239
240 TODO: Explaination of how to override `ir.report.get_style_content` to change
241 the default style.
242
243
244 .. External Links
245
246 .. _Genshi XML Templates: http://genshi.edgewall.org/wiki/Documentation/0.5.x/xm l-templates.html
247
248 .. _Quick Example: http://relatorio.openhex.org/wiki/QuickExample
249
250 .. _In Depth Introduction: http://relatorio.openhex.org/wiki/IndepthIntroduction
251
252 .. _Example Documents: http://relatorio.openhex.org/browser/examples
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b