forked from studio1247/gertrude
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdoc_export_compta.py
More file actions
125 lines (111 loc) · 5.1 KB
/
doc_export_compta.py
File metadata and controls
125 lines (111 loc) · 5.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# -*- coding: utf-8 -*-
## This file is part of Gertrude.
##
## Gertrude is free software; you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation; either version 3 of the License, or
## (at your option) any later version.
##
## Gertrude is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
## GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with Gertrude; if not, see <http://www.gnu.org/licenses/>.
from constants import *
from functions import *
from facture import *
from cotisation import CotisationException
from ooffice import *
class ExportComptaModifications(object):
def __init__(self, inscrits, periode):
self.template = 'Export compta.txt'
self.inscrits = inscrits
self.periode = periode
self.default_output = u"Export compta %s %d.txt" % (months[periode.month - 1], periode.year)
self.email_to = None
self.multi = False
self.email = False
def execute(self, text):
errors = {}
result = []
replacements = { }
lines = text.splitlines(3)
for i, line in enumerate(lines):
if i == 0:
result.append(line)
elif i == 1:
template = line
else:
if "=" in line:
try:
key, value = line.split("=", 1)
replacements[key.strip()] = value.strip()
except:
pass
# print replacements
indexOperation = 0
for inscrit in self.inscrits:
try:
facture = Facture(inscrit, self.periode.year, self.periode.month)
except CotisationException, e:
errors["%s %s" % (inscrit.prenom, inscrit.nom)] = e.errors
continue
indexOperation += 1
date = GetMonthEnd(self.periode)
if len(creche.sites) > 1 and facture.site:
site = facture.site.nom
else:
site = creche.nom
fields = {'date-fin-mois': '%.2d/%.2d/%d' % (date.day, date.month, date.year),
'index-operation': "%04d" % indexOperation,
'nom': inscrit.nom.upper(),
'mois': months[date.month-1].lower(),
}
for i in range(5):
if i==0 and facture.total:
fields['numero-compte'] = "411%s" % inscrit.nom.upper()[:5]
fields['debit'] = facture.total
fields['credit'] = 0
fields['activite'] = ""
fields['plan-analytique'] = ""
fields['poste-analytique'] = ""
elif i==1 and facture.total - facture.supplement_activites:
fields['numero-compte'] = 70600000
fields['debit'] = 0
fields['credit'] = facture.total - facture.supplement_activites
fields['activite'] = 'garde'
fields['plan-analytique'] = "SITES"
fields['poste-analytique'] = site
elif i==2 and facture.supplement_activites:
fields['numero-compte'] = 70710000
fields['debit'] = 0
fields['credit'] = facture.supplement_activites
fields['activite'] = 'activites'
fields['plan-analytique'] = "SITES"
fields['poste-analytique'] = site
elif i==3 and facture.frais_inscription_reservataire:
fields['numero-compte'] = "411RESERVATAIRE"
fields['debit'] = facture.frais_inscription_reservataire
fields['credit'] = 0
fields['activite'] = ""
fields['plan-analytique'] = ""
fields['poste-analytique'] = ""
elif i==4 and facture.frais_inscription_reservataire:
fields['numero-compte'] = 70820000
fields['debit'] = 0
fields['credit'] = facture.frais_inscription_reservataire
fields['activite'] = "frais_inscription"
fields['plan-analytique'] = "SITES"
fields['poste-analytique'] = site
else:
break
line = template
for field in fields:
value = unicode(fields[field]).encode("latin-1")
if value in replacements.keys():
value = replacements[value]
line = line.replace("<%s>" % field, value)
result.append(line)
return ''.join(result), errors