0052b918e059fd45c3439472d76e6cb1f2384fef
1 # -*- coding: utf-8 -*-
2 ##############################################################################
4 # etudesetchantiersidf module for OpenERP, Custom module for Étude et
5 # Chantiers île-de-France
6 # Copyright (C) 2014-2019 etudesetchantiersidf
7 # (<http://etudesetchantiersiledefrance.unarec.org/>)
9 # This file is a part of etudesetchantiersidf
11 # etudesetchantiersidf is free software: you can redistribute it and/or
12 # modify it under the terms of the GNU General Public License as published
13 # by the Free Software Foundation, either version 3 of the License, or (at
14 # your option) any later version.
16 # etudesetchantiersidf 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.
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/>.
24 ##############################################################################
33 import openerp
.exceptions
34 from openerp
.osv
import osv
35 from openerp
.tools
.translate
import _
36 from openerp
.addons
.account_export_csv
.wizard
.account_export_csv
import AccountUnicodeWriter
38 class AccountUnicodeWriter(AccountUnicodeWriter
):
40 def __init__(self
, f
, dialect
=csv
.excel
, encoding
="utf-8", **kwds
):
41 # Redirect output to a queue
42 self
.queue
= cStringIO
.StringIO()
43 # created a writer with Excel formating settings
45 self
.writer
= csv
.writer(self
.queue
, dialect
=dialect
,
46 quoting
=csv
.QUOTE_NONE
, **kwds
)
48 self
.encoder
= codecs
.getincrementalencoder(encoding
)()
51 class AccountCSVExport(osv
.osv_memory
):
52 _inherit
= "account.csv.export"
54 def action_manual_export_ccmx(self
, cr
, uid
, ids
, context
=None):
55 this
= self
.browse(cr
, uid
, ids
)[0]
56 rows
= self
.get_data(cr
, uid
, ids
, "ccmx", context
)
57 file_data
= StringIO
.StringIO()
59 writer
= AccountUnicodeWriter(file_data
)
60 writer
.writerows(rows
)
61 file_value
= file_data
.getvalue()
62 self
.write(cr
, uid
, ids
,
63 {'data': base64
.encodestring(file_value
)},
68 'type': 'ir.actions.act_window',
69 'res_model': 'account.csv.export',
73 'views': [(False, 'form')],
77 def _get_header_ccmx(self
, cr
, uid
, ids
, context
=None):
78 """docstring for _get_header_ccmx"""
90 def _get_rows_ccmx(self
, cr
, uid
, ids
,
96 fiscalyear_obj
= self
.pool
.get('account.fiscalyear')
97 fiscalyear_code
= fiscalyear_obj
.browse(cr
, uid
, fiscalyear_id
, context
=context
)
98 fiscalyear_code
= fiscalyear_obj
.browse(cr
, uid
, fiscalyear_id
, context
=context
).code
100 if len(period_range_ids
) != 1:
101 raise openerp
.exceptions
.Warning(_('You must select ONE period for this export.'))
105 if len(journal_ids
) != 1:
106 raise openerp
.exceptions
.Warning(_('You must select ONE journal for this export.'))
111 period_obj
= self
.pool
.get('account.period')
112 period_code
= period_obj
.browse(cr
, uid
, period_range_ids
[0], context
=context
).code
113 period_id
= period_obj
.browse(cr
, uid
, period_range_ids
[0], context
=context
).id
114 mandy
= period_code
.split("/")
115 nbday
= calendar
.monthrange(int(mandy
[1]), int(mandy
[0]))[1]
116 ref_date
= "".join((str(nbday
), mandy
[0], mandy
[1][2:4]))
117 journal_obj
= self
.pool
.get('account.journal')
118 journal
= journal_obj
.browse(cr
, uid
, journal_ids
[0], context
=context
)
119 journal_id
= journal
.id
121 city
= journal
.name
.split(" - ")[1]
122 libelle
= " ".join((journal
.name
, period_code
))
123 reference
= " ".join((journal
.code
[:2], period_code
))
125 raise openerp
.exceptions
.Warning(_('The selected journal is not available for this export type.'))
130 '%(ref_date)s' as date,
133 '%(libelle)s' as libelle,
134 '%(reference)s' as reference,
135 sum(debit) as sum_debit,
136 sum(credit) as sum_credit
138 account_move_line as aml,
139 account_account as ac,
142 aml.account_id = ac.id
143 and aml.journal_id = j.id
144 and period_id = %(period_id)d
145 and journal_id = %(journal_id)d
153 'ref_date': ref_date
,
155 'reference': reference
,
156 'fiscalyear_id': fiscalyear_id
,
157 'period_id': period_id
,
158 'journal_id': journal_id
,
168 analytic
= journal
[2:]
169 "Add analytic account for 6 and 7 classes accounts"
170 if code
[:1] in ('6', '7'):
171 line
= line
+ (analytic
,)
174 "Split lines whith debit AND credit amount"
183 rows
.append(list(line
))
186 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: