1 # -*- coding: utf-8 -*-
2 ##############################################################################
4 # etudesetchantiersidf module for OpenERP, Custom module for Étude et
5 # Chantiers île-de-France
6 # Copyright (C) 2014-2022 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 ##############################################################################
34 import openerp
.exceptions
35 from openerp
.osv
import osv
36 from openerp
.tools
.translate
import _
37 from openerp
.addons
.account_export_csv
.wizard
.account_export_csv
import AccountUnicodeWriter
40 class AccountUnicodeWriter(AccountUnicodeWriter
):
42 def __init__(self
, f
, dialect
=csv
.excel
, encoding
="utf-8", **kwds
):
43 # Redirect output to a queue
44 self
.queue
= cStringIO
.StringIO()
45 # created a writer with Excel formating settings
47 self
.writer
= csv
.writer(self
.queue
, dialect
=dialect
,
48 quoting
=csv
.QUOTE_NONE
, **kwds
)
50 self
.encoder
= codecs
.getincrementalencoder(encoding
)()
53 class AccountCSVExport(osv
.osv_memory
):
54 _inherit
= "account.csv.export"
56 def action_manual_export_sage(self
, cr
, uid
, ids
, context
=None):
57 this
= self
.browse(cr
, uid
, ids
)[0]
58 rows
= self
.get_data(cr
, uid
, ids
, "sage", context
)
59 file_data
= StringIO
.StringIO()
61 writer
= AccountUnicodeWriter(file_data
)
62 writer
.writerows(rows
)
63 file_value
= file_data
.getvalue()
64 self
.write(cr
, uid
, ids
,
65 {'data': base64
.encodestring(file_value
)},
70 'type': 'ir.actions.act_window',
71 'res_model': 'account.csv.export',
75 'views': [(False, 'form')],
79 def _get_header_sage(self
, cr
, uid
, ids
, context
=None):
80 """docstring for _get_header_sage"""
81 return [_(u
'Code du journal'),
86 _(u
'Général/analytique'),
87 _(u
'Compte Analytique'),
93 def _get_rows_sage(self
, cr
, uid
, ids
,
99 fiscalyear_obj
= self
.pool
.get('account.fiscalyear')
100 fiscalyear_code
= fiscalyear_obj
.browse(cr
, uid
, fiscalyear_id
, context
=context
)
101 fiscalyear_code
= fiscalyear_obj
.browse(cr
, uid
, fiscalyear_id
, context
=context
).code
103 period_obj
= self
.pool
.get('account.period')
104 journal_obj
= self
.pool
.get('account.journal')
105 account_obj
= self
.pool
.get('account.account')
112 aml.journal_id as journal_id,
113 aml.account_id as account_id,
114 sum(aml.debit) as sum_debit,
115 sum(aml.credit) as sum_credit
117 account_move_line as aml
119 aml.period_id in %(period_ids)s and
120 aml.journal_id in %(journal_ids)s and
121 aml.account_id in %(account_ids)s
131 'period_ids': tuple(period_range_ids
),
132 'journal_ids': tuple(journal_ids
),
133 'account_ids': tuple(account_ids
),
139 journal
= journal_obj
.browse(cr
, uid
, line
[1], context
=context
)
140 journal_code
= journal
.code
[0:2]
141 period
= period_obj
.browse(cr
, uid
, line
[0], context
=context
)
142 if prev_journal
!= journal
or prev_period
!= period
:
144 year
= int(period
.code
[3:7])
145 month
= int(period
.code
[0:2])
146 day
= calendar
.monthrange(year
, month
)[1]
147 date
= datetime
.datetime(year
, month
, day
).strftime("%d/%m/%Y")
148 account
= account_obj
.browse(cr
, uid
, line
[2], context
=context
)
149 account_code
= account
.code
150 client_name
= journal
.name
.split(" - ", 1)[1].upper()
151 if account
.type in ("receivable", "payable"):
152 compte_tiers
= client_name
155 general_analytic
= "G"
156 analytic_account
= ""
188 if account
.type == "other":
189 general_analytic
= "A"
190 analytic_account
= journal
.code
[3:]
220 prev_journal
= journal
224 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: