forked from studio1247/gertrude
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdoc_appel_cotisations.py
More file actions
93 lines (80 loc) · 3.61 KB
/
doc_appel_cotisations.py
File metadata and controls
93 lines (80 loc) · 3.61 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
# -*- 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 AppelCotisationsModifications(object):
def __init__(self, date, options=0):
self.multi = False
self.template = 'Appel cotisations.ods'
self.default_output = u"Appel cotisations %s %d.ods" % (months[date.month - 1], date.year)
self.debut, self.fin = date, GetMonthEnd(date)
self.options = options
self.gauge = None
self.email = None
self.site = None
def execute(self, filename, dom):
if filename != 'content.xml':
return None
errors = {}
spreadsheet = dom.getElementsByTagName('office:spreadsheet').item(0)
template = spreadsheet.getElementsByTagName("table:table").item(0)
if len(creche.sites) > 1:
spreadsheet.removeChild(template)
for i, site in enumerate(creche.sites):
table = template.cloneNode(1)
spreadsheet.appendChild(table)
table.setAttribute("table:name", site.nom)
self.fill_table(table, site, errors)
if self.gauge:
self.gauge.SetValue((90/len(creche.sites)) * (i+1))
else:
self.fill_table(template)
if self.gauge:
self.gauge.SetValue(90)
return errors
def fill_table(self, table, site=None, errors={}):
lignes = table.getElementsByTagName("table:table-row")
# La date
fields = [('date', self.debut)]
if site:
fields.append(('site', site.nom))
else:
fields.append(('site', None))
ReplaceFields(lignes, fields)
# Les cotisations
lines_template = [lignes.item(7), lignes.item(8)]
inscrits = GetInscrits(self.debut, self.fin, site=site)
inscrits.sort(cmp=lambda x,y: cmp(GetPrenomNom(x), GetPrenomNom(y)))
for i, inscrit in enumerate(inscrits):
if self.gauge:
self.gauge.SetValue(10+int(80.0*i/len(inscrits)))
line = lines_template[i % 2].cloneNode(1)
try:
facture = Facture(inscrit, self.debut.year, self.debut.month, self.options)
commentaire = None
except CotisationException, e:
facture = None
commentaire = '\n'.join(e.errors)
errors[GetPrenomNom(inscrit)] = e.errors
fields = GetCrecheFields(creche) + GetInscritFields(inscrit) + GetFactureFields(facture) + [('commentaire', commentaire)]
ReplaceFields(line, fields)
table.insertBefore(line, lines_template[0])
IncrementFormulas(lines_template[i % 2], row=+2)
table.removeChild(lines_template[0])
table.removeChild(lines_template[1])