Merge lp:~camptocamp/account-financial-report/account_csv_VRE into lp:~account-report-core-editor/account-financial-report/7.0
- account_csv_VRE
- Merge into 7.0
Status: | Superseded |
---|---|
Proposed branch: | lp:~camptocamp/account-financial-report/account_csv_VRE |
Merge into: | lp:~account-report-core-editor/account-financial-report/7.0 |
Diff against target: |
605 lines (+561/-0) 8 files modified
account_export_csv/__init__.py (+21/-0) account_export_csv/__openerp__.py (+46/-0) account_export_csv/i18n/account_export_csv.po (+111/-0) account_export_csv/i18n/fr.po (+74/-0) account_export_csv/menu.xml (+16/-0) account_export_csv/wizard/__init__.py (+22/-0) account_export_csv/wizard/account_export_csv.py (+226/-0) account_export_csv/wizard/account_export_csv_view.xml (+45/-0) |
To merge this branch: | bzr merge lp:~camptocamp/account-financial-report/account_csv_VRE |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Joël Grand-Guillaume @ camptocamp | code review, no test | Approve | |
Review via email: mp+158373@code.launchpad.net |
This proposal supersedes a proposal from 2013-04-11.
This proposal has been superseded by a proposal from 2013-04-11.
Commit message
Description of the change
Add account_export_csv, that allow to export Trial Balance and Analytic Balance with accounts in CSV
Joël Grand-Guillaume @ camptocamp (jgrandguillaume-c2c) wrote : Posted in a previous version of this proposal | # |
Vincent Renaville@camptocamp (vrenaville-c2c) wrote : Posted in a previous version of this proposal | # |
Thanks for your review
I will work on that , I will resubmit the fixes soon
Vincent
Vincent Renaville@camptocamp (vrenaville-c2c) wrote : | # |
Joel, I have fix according to your comment
Thanks for your review
- 32. By Vincent Renaville@camptocamp
-
[FIX] improve sql to display not analytic account line
- 33. By Vincent Renaville@camptocamp
-
[FIX] group by
- 34. By Vincent Renaville@camptocamp
-
[FIX] License and comment
Joël Grand-Guillaume @ camptocamp (jgrandguillaume-c2c) wrote : | # |
Thanks for fixing, it LGTM !
Guewen Baconnier @ Camptocamp (gbaconnier-c2c) wrote : Posted in a previous version of this proposal | # |
The _get_rows_account and _get_rows_analytic methods take a 'company_id' argument, this one is passed to the query, but this one does not use it, so the lines are not multi-company aware.
I'm not sure if it should be done directly in the query or if you should leave the query as is and do a self.search(cr, uid, [('id', 'in', line_ids)], context=context) afterwards to apply the rules.
Unmerged revisions
Preview Diff
1 | === added directory 'account_export_csv' |
2 | === added file 'account_export_csv/__init__.py' |
3 | --- account_export_csv/__init__.py 1970-01-01 00:00:00 +0000 |
4 | +++ account_export_csv/__init__.py 2013-04-11 15:03:19 +0000 |
5 | @@ -0,0 +1,21 @@ |
6 | +# -*- coding: utf-8 -*- |
7 | +############################################################################## |
8 | +# |
9 | +# Author Joel Grand-Guillaume and Vincent Renaville Copyright 2013 Camptocamp SA |
10 | +# |
11 | +# This program is free software: you can redistribute it and/or modify |
12 | +# it under the terms of the GNU General Public License as published by |
13 | +# the Free Software Foundation, either version 3 of the License, or |
14 | +# (at your option) any later version. |
15 | +# |
16 | +# This program is distributed in the hope that it will be useful, |
17 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
18 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
19 | +# GNU General Public License for more details. |
20 | +# |
21 | +# You should have received a copy of the GNU General Public License |
22 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. |
23 | +# |
24 | +############################################################################## |
25 | + |
26 | +import wizard |
27 | \ No newline at end of file |
28 | |
29 | === added file 'account_export_csv/__openerp__.py' |
30 | --- account_export_csv/__openerp__.py 1970-01-01 00:00:00 +0000 |
31 | +++ account_export_csv/__openerp__.py 2013-04-11 15:03:19 +0000 |
32 | @@ -0,0 +1,46 @@ |
33 | +# -*- coding: utf-8 -*- |
34 | +############################################################################## |
35 | +# |
36 | +# Author Joel Grand-Guillaume and Vincent Renaville Copyright 2013 Camptocamp SA |
37 | +# |
38 | +# This program is free software: you can redistribute it and/or modify |
39 | +# it under the terms of the GNU General Public License as published by |
40 | +# the Free Software Foundation, either version 3 of the License, or |
41 | +# (at your option) any later version. |
42 | +# |
43 | +# This program is distributed in the hope that it will be useful, |
44 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
45 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
46 | +# GNU General Public License for more details. |
47 | +# |
48 | +# You should have received a copy of the GNU General Public License |
49 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. |
50 | +# |
51 | +############################################################################## |
52 | + |
53 | +{ |
54 | + 'name' : 'Account Export CSV', |
55 | + 'version' : '1', |
56 | + 'depends' : [ |
57 | + 'account', |
58 | + ], |
59 | + 'author' : 'Camptocamp', |
60 | + 'description': """ |
61 | + |
62 | + Add a wizard that allow you to export a csv file based on accounting journal entries |
63 | + |
64 | + - Trial Balance |
65 | + - Analytic Balance (with accounts) |
66 | + |
67 | + You can filter by period |
68 | + |
69 | + |
70 | + """, |
71 | + 'website': 'http://www.camptocamp.com', |
72 | + 'data': [ |
73 | + 'wizard/account_export_csv_view.xml', |
74 | + 'menu.xml', |
75 | + ], |
76 | + 'installable': True, |
77 | + 'active': False, |
78 | +} |
79 | |
80 | === added directory 'account_export_csv/i18n' |
81 | === added file 'account_export_csv/i18n/account_export_csv.po' |
82 | --- account_export_csv/i18n/account_export_csv.po 1970-01-01 00:00:00 +0000 |
83 | +++ account_export_csv/i18n/account_export_csv.po 2013-04-11 15:03:19 +0000 |
84 | @@ -0,0 +1,111 @@ |
85 | +# Translation of OpenERP Server. |
86 | +# This file contains the translation of the following modules: |
87 | +# * account_export_csv |
88 | +# |
89 | +msgid "" |
90 | +msgstr "" |
91 | +"Project-Id-Version: OpenERP Server 7.0\n" |
92 | +"Report-Msgid-Bugs-To: \n" |
93 | +"POT-Creation-Date: 2013-04-10 15:11+0000\n" |
94 | +"PO-Revision-Date: 2013-04-10 15:11+0000\n" |
95 | +"Last-Translator: <>\n" |
96 | +"Language-Team: \n" |
97 | +"MIME-Version: 1.0\n" |
98 | +"Content-Type: text/plain; charset=UTF-8\n" |
99 | +"Content-Transfer-Encoding: \n" |
100 | +"Plural-Forms: \n" |
101 | + |
102 | +#. module: account_export_csv |
103 | +#: model:ir.model,name:account_export_csv.model_account_csv_export |
104 | +msgid "Export Accounting" |
105 | +msgstr "" |
106 | + |
107 | +#. module: account_export_csv |
108 | +#: field:account.csv.export,export_filename:0 |
109 | +msgid "Export CSV Filename" |
110 | +msgstr "" |
111 | + |
112 | +#. module: account_export_csv |
113 | +#: view:account.csv.export:0 |
114 | +msgid "Trial Balance" |
115 | +msgstr "" |
116 | + |
117 | +#. module: account_export_csv |
118 | +#: field:account.csv.export,company_id:0 |
119 | +msgid "Company" |
120 | +msgstr "" |
121 | + |
122 | +#. module: account_export_csv |
123 | +#: view:account.csv.export:0 |
124 | +msgid "Analytic Balance (with accounts)" |
125 | +msgstr "" |
126 | + |
127 | +#. module: account_export_csv |
128 | +#: help:account.csv.export,periods:0 |
129 | +msgid "All periods in the fiscal year if empty" |
130 | +msgstr "" |
131 | + |
132 | +#. module: account_export_csv |
133 | +#: field:account.csv.export,periods:0 |
134 | +msgid "Periods" |
135 | +msgstr "" |
136 | + |
137 | +#. module: account_export_csv |
138 | +#: view:account.csv.export:0 |
139 | +msgid "Close" |
140 | +msgstr "" |
141 | + |
142 | +#. module: account_export_csv |
143 | +#: view:account.csv.export:0 |
144 | +#: model:ir.actions.act_window,name:account_export_csv.action_account_csv_export |
145 | +#: model:ir.ui.menu,name:account_export_csv.menu_account_csv_export |
146 | +msgid "Accounting CSV Export" |
147 | +msgstr "" |
148 | + |
149 | +#. module: account_export_csv |
150 | +#: field:account.csv.export,data:0 |
151 | +msgid "CSV" |
152 | +msgstr "" |
153 | + |
154 | +#. module: account_export_csv |
155 | +#: field:account.csv.export,fiscalyear_id:0 |
156 | +msgid "Fiscalyear" |
157 | +msgstr "" |
158 | + |
159 | +#. module: account_export_csv |
160 | +#: view:account.csv.export:0 |
161 | +msgid "Analytic Balance (with accounts)" |
162 | +msgstr "" |
163 | + |
164 | +#. module: account_export_csv |
165 | +#: field:account.csv.export,stop_period_id:0 |
166 | +msgid "End period" |
167 | +msgstr "" |
168 | + |
169 | +#. module: account_export_csv |
170 | +#: view:account.csv.export:0 |
171 | +msgid "Close" |
172 | +msgstr "" |
173 | + |
174 | +#. module: account_export_csv |
175 | +#: view:account.csv.export:0 |
176 | +#: model:ir.actions.act_window,name:account_export_csv.action_account_csv_export |
177 | +#: model:ir.ui.menu,name:account_export_csv.menu_account_csv_export |
178 | +msgid "Accounting CSV Export" |
179 | +msgstr "" |
180 | + |
181 | +#. module: account_export_csv |
182 | +#: field:account.csv.export,data:0 |
183 | +msgid "CSV" |
184 | +msgstr "" |
185 | + |
186 | +#. module: account_export_csv |
187 | +#: model:ir.model,name:account_export_csv.model_account_csv_export |
188 | +msgid "Export Accounting Entries" |
189 | +msgstr "" |
190 | + |
191 | +#. module: account_export_csv |
192 | +#: field:account.csv.export,fiscalyear_id:0 |
193 | +msgid "Fiscalyear" |
194 | +msgstr "" |
195 | + |
196 | |
197 | === added file 'account_export_csv/i18n/fr.po' |
198 | --- account_export_csv/i18n/fr.po 1970-01-01 00:00:00 +0000 |
199 | +++ account_export_csv/i18n/fr.po 2013-04-11 15:03:19 +0000 |
200 | @@ -0,0 +1,74 @@ |
201 | +# Translation of OpenERP Server. |
202 | +# This file contains the translation of the following modules: |
203 | +# * account_export_csv |
204 | +# |
205 | +msgid "" |
206 | +msgstr "" |
207 | +"Project-Id-Version: OpenERP Server 7.0\n" |
208 | +"Report-Msgid-Bugs-To: \n" |
209 | +"POT-Creation-Date: 2013-04-10 15:11+0000\n" |
210 | +"PO-Revision-Date: 2013-04-10 15:11+0000\n" |
211 | +"Last-Translator: <>\n" |
212 | +"Language-Team: \n" |
213 | +"MIME-Version: 1.0\n" |
214 | +"Content-Type: text/plain; charset=UTF-8\n" |
215 | +"Content-Transfer-Encoding: \n" |
216 | +"Plural-Forms: \n" |
217 | + |
218 | +#. module: account_export_csv |
219 | +#: model:ir.model,name:account_export_csv.model_account_csv_export |
220 | +msgid "Export Accounting" |
221 | +msgstr "Export comptable" |
222 | + |
223 | +#. module: account_export_csv |
224 | +#: field:account.csv.export,export_filename:0 |
225 | +msgid "Export CSV Filename" |
226 | +msgstr "Nom du fichier CSV d'export" |
227 | + |
228 | +#. module: account_export_csv |
229 | +#: view:account.csv.export:0 |
230 | +msgid "Trial Balance" |
231 | +msgstr "Balance générale" |
232 | + |
233 | +#. module: account_export_csv |
234 | +#: field:account.csv.export,company_id:0 |
235 | +msgid "Company" |
236 | +msgstr "Société" |
237 | + |
238 | +#. module: account_export_csv |
239 | +#: view:account.csv.export:0 |
240 | +msgid "Analytic Balance (with accounts)" |
241 | +msgstr "Balance analytique (avec comptes)" |
242 | + |
243 | +#. module: account_export_csv |
244 | +#: help:account.csv.export,periods:0 |
245 | +msgid "All periods in the fiscal year if empty" |
246 | +msgstr "Toutes les périodes de l'année fiscale si vide" |
247 | + |
248 | +#. module: account_export_csv |
249 | +#: field:account.csv.export,periods:0 |
250 | +msgid "Periods" |
251 | +msgstr "Périodes" |
252 | + |
253 | +#. module: account_export_csv |
254 | +#: view:account.csv.export:0 |
255 | +msgid "Close" |
256 | +msgstr "Fermer" |
257 | + |
258 | +#. module: account_export_csv |
259 | +#: view:account.csv.export:0 |
260 | +#: model:ir.actions.act_window,name:account_export_csv.action_account_csv_export |
261 | +#: model:ir.ui.menu,name:account_export_csv.menu_account_csv_export |
262 | +msgid "Accounting CSV Export" |
263 | +msgstr "Export comptable CSV" |
264 | + |
265 | +#. module: account_export_csv |
266 | +#: field:account.csv.export,data:0 |
267 | +msgid "CSV" |
268 | +msgstr "CSV" |
269 | + |
270 | +#. module: account_export_csv |
271 | +#: field:account.csv.export,fiscalyear_id:0 |
272 | +msgid "Fiscalyear" |
273 | +msgstr "Année fiscale" |
274 | + |
275 | |
276 | === added file 'account_export_csv/menu.xml' |
277 | --- account_export_csv/menu.xml 1970-01-01 00:00:00 +0000 |
278 | +++ account_export_csv/menu.xml 2013-04-11 15:03:19 +0000 |
279 | @@ -0,0 +1,16 @@ |
280 | +<?xml version="1.0" encoding="utf-8"?> |
281 | +<openerp> |
282 | + <data> |
283 | + |
284 | + <menuitem |
285 | + icon="STOCK_EXECUTE" |
286 | + name="Accounting CSV Export" |
287 | + action="action_account_csv_export" |
288 | + id="menu_account_csv_export" |
289 | + parent="account.menu_finance_reports" |
290 | + sequence="110" |
291 | + /> |
292 | + |
293 | + |
294 | + </data> |
295 | +</openerp> |
296 | |
297 | === added directory 'account_export_csv/wizard' |
298 | === added file 'account_export_csv/wizard/__init__.py' |
299 | --- account_export_csv/wizard/__init__.py 1970-01-01 00:00:00 +0000 |
300 | +++ account_export_csv/wizard/__init__.py 2013-04-11 15:03:19 +0000 |
301 | @@ -0,0 +1,22 @@ |
302 | +# -*- coding: utf-8 -*- |
303 | +############################################################################## |
304 | +# |
305 | +# Author Joel Grand-Guillaume and Vincent Renaville Copyright 2013 Camptocamp SA |
306 | +# |
307 | +# This program is free software: you can redistribute it and/or modify |
308 | +# it under the terms of the GNU General Public License as published by |
309 | +# the Free Software Foundation, either version 3 of the License, or |
310 | +# (at your option) any later version. |
311 | +# |
312 | +# This program is distributed in the hope that it will be useful, |
313 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
314 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
315 | +# GNU General Public License for more details. |
316 | +# |
317 | +# You should have received a copy of the GNU General Public License |
318 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. |
319 | +# |
320 | +############################################################################## |
321 | + |
322 | + |
323 | +import account_export_csv |
324 | \ No newline at end of file |
325 | |
326 | === added file 'account_export_csv/wizard/account_export_csv.py' |
327 | --- account_export_csv/wizard/account_export_csv.py 1970-01-01 00:00:00 +0000 |
328 | +++ account_export_csv/wizard/account_export_csv.py 2013-04-11 15:03:19 +0000 |
329 | @@ -0,0 +1,226 @@ |
330 | +# -*- coding: utf-8 -*- |
331 | +############################################################################## |
332 | +# |
333 | +# Author Joel Grand-Guillaume and Vincent Renaville Copyright 2013 Camptocamp SA |
334 | +# |
335 | +# This program is free software: you can redistribute it and/or modify |
336 | +# it under the terms of the GNU General Public License as published by |
337 | +# the Free Software Foundation, either version 3 of the License, or |
338 | +# (at your option) any later version. |
339 | +# |
340 | +# This program is distributed in the hope that it will be useful, |
341 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
342 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
343 | +# GNU General Public License for more details. |
344 | +# |
345 | +# You should have received a copy of the GNU General Public License |
346 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. |
347 | +# |
348 | +############################################################################## |
349 | + |
350 | +import time |
351 | +import StringIO |
352 | +import cStringIO |
353 | +import base64 |
354 | + |
355 | +import csv |
356 | +import codecs |
357 | + |
358 | +from openerp.osv import orm, fields |
359 | +from openerp.tools.translate import _ |
360 | + |
361 | + |
362 | +class AccountUnicodeWriter(object): |
363 | + """ |
364 | + A CSV writer which will write rows to CSV file "f", |
365 | + which is encoded in the given encoding. |
366 | + """ |
367 | + |
368 | + def __init__(self, f, dialect=csv.excel, encoding="utf-8", **kwds): |
369 | + # Redirect output to a queue |
370 | + self.queue = cStringIO.StringIO() |
371 | + # self.writer = csv.writer(self.queue, delimiter=',', quotechar='"', quoting=csv.QUOTE_NONNUMERIC, **kwds) |
372 | + self.writer = csv.writer(self.queue, dialect=dialect, **kwds) |
373 | + self.stream = f |
374 | + self.encoder = codecs.getincrementalencoder(encoding)() |
375 | + |
376 | + def writerow(self, row): |
377 | + #we ensure that we do not try to encode none or bool |
378 | + row = [x or u'' for x in row] |
379 | + |
380 | + encoded_row = [] |
381 | + for c in row: |
382 | + if type(c) == unicode: |
383 | + encoded_row.append(c.encode("utf-8")) |
384 | + else: |
385 | + encoded_row.append(c) |
386 | + |
387 | + self.writer.writerow(encoded_row) |
388 | + # self.writer.writerow([s.encode("utf-8") for s in row]) |
389 | + # Fetch UTF-8 output from the queue ... |
390 | + data = self.queue.getvalue() |
391 | + data = data.decode("utf-8") |
392 | + # ... and reencode it into the target encoding |
393 | + data = self.encoder.encode(data) |
394 | + # write to the target stream |
395 | + self.stream.write(data) |
396 | + # empty queue |
397 | + self.queue.truncate(0) |
398 | + |
399 | + def writerows(self, rows): |
400 | + for row in rows: |
401 | + self.writerow(row) |
402 | + |
403 | +class AccountCSVExport(orm.TransientModel): |
404 | + _name = 'account.csv.export' |
405 | + _description = 'Export Accounting' |
406 | + |
407 | + _columns = { |
408 | + 'data': fields.binary('CSV',readonly=True), |
409 | + 'company_id': fields.many2one('res.company', 'Company', invisible=True), |
410 | + 'fiscalyear_id': fields.many2one('account.fiscalyear', 'Fiscalyear', required=True), |
411 | + 'periods': fields.many2many('account.period','rel_wizard_period','wizard_id','period_id','Periods',help='All periods in the fiscal year if empty'), |
412 | + 'export_filename': fields.char('Export CSV Filename', size=128), |
413 | + } |
414 | + |
415 | + def _get_company_default(self, cr, uid, context=None): |
416 | + comp_obj = self.pool['res.company'] |
417 | + return comp_obj._company_default_get(cr, uid, 'account.fiscalyear', context=context) |
418 | + |
419 | + def _get_fiscalyear_default(self, cr, uid, context=None): |
420 | + fiscalyear_obj = self.pool['account.fiscalyear'] |
421 | + context['company_id'] = self._get_company_default(cr, uid, context) |
422 | + return fiscalyear_obj.find(cr,uid,dt=None,exception=True, context=context) |
423 | + |
424 | + _defaults = {'company_id': _get_company_default, |
425 | + 'fiscalyear_id' : _get_fiscalyear_default, |
426 | + 'export_filename' : 'account_export.csv'} |
427 | + |
428 | + def action_manual_export_account(self, cr, uid, ids, context=None): |
429 | + this = self.browse(cr, uid, ids)[0] |
430 | + rows = self.get_data(cr, uid, ids,"account", context) |
431 | + file_data = StringIO.StringIO() |
432 | + try: |
433 | + writer = AccountUnicodeWriter(file_data) |
434 | + writer.writerows(rows) |
435 | + file_value = file_data.getvalue() |
436 | + self.write(cr, uid, ids, |
437 | + {'data': base64.encodestring(file_value)}, |
438 | + context=context) |
439 | + finally: |
440 | + file_data.close() |
441 | + return { |
442 | + 'type': 'ir.actions.act_window', |
443 | + 'res_model': 'account.csv.export', |
444 | + 'view_mode': 'form', |
445 | + 'view_type': 'form', |
446 | + 'res_id': this.id, |
447 | + 'views': [(False, 'form')], |
448 | + 'target': 'new', |
449 | + } |
450 | + |
451 | + |
452 | + def _get_header_account(self, cr, uid, ids, context=None): |
453 | + return [_(u'CODE'), |
454 | + _(u'NAME'), |
455 | + _(u'DEBIT'), |
456 | + _(u'CREDIT'), |
457 | + _(u'BALANCE'), |
458 | + ] |
459 | + |
460 | + def _get_rows_account(self, cr, uid, ids, fiscalyear_id,period_range_ids,company_id,context=None): |
461 | + """ |
462 | + Return list to generate rows of the CSV file |
463 | + """ |
464 | + cr.execute(""" |
465 | + select ac.code,ac.name, |
466 | + sum(debit) as sum_debit,sum(credit) as sum_credit,sum(debit) - sum(credit) as balance |
467 | + from account_move_line as aml,account_account as ac |
468 | + where aml.account_id = ac.id |
469 | + and period_id in %(period_ids)s |
470 | + group by ac.id,ac.code,ac.name |
471 | + order by ac.code |
472 | + """, |
473 | + {'fiscalyear_id': fiscalyear_id,'company_id':company_id,'period_ids':tuple(period_range_ids)} |
474 | + ) |
475 | + res = cr.fetchall() |
476 | + |
477 | + rows = [] |
478 | + for line in res: |
479 | + rows.append(list(line)) |
480 | + return rows |
481 | + |
482 | + def action_manual_export_analytic(self, cr, uid, ids, context=None): |
483 | + this = self.browse(cr, uid, ids)[0] |
484 | + rows = self.get_data(cr, uid, ids,"analytic", context) |
485 | + file_data = StringIO.StringIO() |
486 | + try: |
487 | + writer = AccountUnicodeWriter(file_data) |
488 | + writer.writerows(rows) |
489 | + file_value = file_data.getvalue() |
490 | + self.write(cr, uid, ids, |
491 | + {'data': base64.encodestring(file_value)}, |
492 | + context=context) |
493 | + finally: |
494 | + file_data.close() |
495 | + return { |
496 | + 'type': 'ir.actions.act_window', |
497 | + 'res_model': 'account.csv.export', |
498 | + 'view_mode': 'form', |
499 | + 'view_type': 'form', |
500 | + 'res_id': this.id, |
501 | + 'views': [(False, 'form')], |
502 | + 'target': 'new', |
503 | + } |
504 | + |
505 | + def _get_header_analytic(self, cr, uid, ids, context=None): |
506 | + return [_(u'ANALYTIC CODE'), |
507 | + _(u'ANALYTIC NAME'), |
508 | + _(u'CODE'), |
509 | + _(u'ACCOUNT NAME'), |
510 | + _(u'DEBIT'), |
511 | + _(u'CREDIT'), |
512 | + _(u'BALANCE'), |
513 | + ] |
514 | + |
515 | + def _get_rows_analytic(self, cr, uid, ids, fiscalyear_id,period_range_ids,company_id,context=None): |
516 | + """ |
517 | + Return list to generate rows of the CSV file |
518 | + """ |
519 | + cr.execute(""" select aac.code as analytic_code,aac.name as analytic_name,ac.code,ac.name, |
520 | + sum(debit) as sum_debit,sum(credit) as sum_credit,sum(debit) - sum(credit) as balance |
521 | + from account_move_line |
522 | + left outer join account_analytic_account as aac |
523 | + on (account_move_line.analytic_account_id = aac.id) |
524 | + inner join account_account as ac |
525 | + on account_move_line.account_id = ac.id |
526 | + and account_move_line.period_id in %(period_ids)s |
527 | + group by aac.id,aac.code,ac.name,ac.id,ac.code,ac.name |
528 | + order by aac.code |
529 | + """, |
530 | + {'fiscalyear_id': fiscalyear_id,'company_id':company_id,'period_ids':tuple(period_range_ids)} |
531 | + ) |
532 | + res = cr.fetchall() |
533 | + |
534 | + rows = [] |
535 | + for line in res: |
536 | + rows.append(list(line)) |
537 | + return rows |
538 | + |
539 | + def get_data(self, cr, uid, ids,result_type,context=None): |
540 | + get_header_func = getattr(self,("_get_header_%s"%(result_type)), None) |
541 | + get_rows_func = getattr(self,("_get_rows_%s"%(result_type)), None) |
542 | + form = self.browse(cr, uid, ids[0], context=context) |
543 | + fiscalyear_id = form.fiscalyear_id.id |
544 | + user_obj = self.pool.get('res.users') |
545 | + company_id = user_obj.browse(cr, uid, uid).company_id.id |
546 | + if form.periods: |
547 | + period_range_ids = [x.id for x in form.periods] |
548 | + else: |
549 | + # If not period selected , we take all periods |
550 | + p_obj = self.pool.get("account.period") |
551 | + period_range_ids = p_obj.search(cr,uid,[('fiscalyear_id','=',fiscalyear_id)],context=context) |
552 | + rows = [] |
553 | + rows.append(get_header_func(cr, uid, ids, context=context)) |
554 | + rows.extend(get_rows_func(cr, uid, ids, fiscalyear_id,period_range_ids,company_id, context=context)) |
555 | + return rows |
556 | |
557 | === added file 'account_export_csv/wizard/account_export_csv_view.xml' |
558 | --- account_export_csv/wizard/account_export_csv_view.xml 1970-01-01 00:00:00 +0000 |
559 | +++ account_export_csv/wizard/account_export_csv_view.xml 2013-04-11 15:03:19 +0000 |
560 | @@ -0,0 +1,45 @@ |
561 | +<?xml version="1.0" encoding="utf-8"?> |
562 | +<openerp> |
563 | + <data> |
564 | + |
565 | + <record id="account_csv_export_view" model="ir.ui.view"> |
566 | + <field name="name">Accounting Entries CSV Export</field> |
567 | + <field name="model">account.csv.export</field> |
568 | + <field name="type">form</field> |
569 | + <field name="arch" type="xml"> |
570 | + <form string="Accounting CSV Export"> |
571 | + <group colspan="4"> |
572 | + <field name="company_id" /> |
573 | + <field name="fiscalyear_id" domain="[('company_id', '=', company_id)]"/> |
574 | + </group> |
575 | + <group colspan="4" col="2"> |
576 | + <field name="periods" domain="[('state', '=', 'draft'),('fiscalyear_id','=',fiscalyear_id)]"/> |
577 | + </group> |
578 | + <separator string ="" colspan="4"/> |
579 | + <group colspan="4" col="3"> |
580 | + <button special="cancel" string="Close" icon="gtk-cancel"/> |
581 | + <button name="action_manual_export_account" string="Trial Balance" type="object" icon="gtk-execute"/> |
582 | + <button name="action_manual_export_analytic" string="Analytic Balance (with accounts)" type="object" icon="gtk-execute"/> |
583 | + </group> |
584 | + <separator string ="" colspan="4"/> |
585 | + <group colspan="4"> |
586 | + <field name="data" filename="export_filename"/> |
587 | + </group> |
588 | + |
589 | + </form> |
590 | + </field> |
591 | + </record> |
592 | + |
593 | + <record id="action_account_csv_export" model="ir.actions.act_window"> |
594 | + <field name="name">Accounting CSV Export</field> |
595 | + <field name="res_model">account.csv.export</field> |
596 | + <field name="type">ir.actions.act_window</field> |
597 | + <field name="view_type">form</field> |
598 | + <field name="view_mode">tree,form</field> |
599 | + <field name="view_id" ref="account_csv_export_view"/> |
600 | + <field name="context">{}</field> |
601 | + <field name="target">new</field> |
602 | + </record> |
603 | + |
604 | + </data> |
605 | +</openerp> |
Hi,
Thanks for this merge. My comments:
- Use coding instead of encoding in file header
- Split line 412
- In account_ export_ csv.py, only 1 line after each method not more
- get_data and get_data_analytic are so similar, I'd love to see the factorize by passing an args on which method to call (_analytic or _account) + renaming the _get_header_ analytic, _get_row_analytic, _get_header and _get_row accordingly (e.g. _get_header_account and _get_header_ analytic)
Otherwise it look good to me.
Regards,