forked from studio1247/gertrude
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpanel_planning.py
More file actions
453 lines (403 loc) · 20.2 KB
/
panel_planning.py
File metadata and controls
453 lines (403 loc) · 20.2 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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
# -*- 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/>.
import datetime
from constants import *
from parameters import *
from functions import *
from sqlobjects import *
from controls import *
from planning import PlanningWidget, LigneConge, COMMENTS, ACTIVITES, TWO_PARTS, DEPASSEMENT_CAPACITE, SUMMARY_NUM, SUMMARY_DEN
from ooffice import *
from doc_planning_detaille import PlanningDetailleModifications
class DayPlanningPanel(PlanningWidget):
def __init__(self, parent, activity_combobox):
PlanningWidget.__init__(self, parent, activity_combobox, COMMENTS|ACTIVITES|TWO_PARTS|DEPASSEMENT_CAPACITE, self.CheckLine)
def CheckLine(self, line, plages_selectionnees):
lines = self.GetSummaryLines()
activites, activites_sans_horaires = GetActivitiesSummary(creche, lines)
for start, end in plages_selectionnees:
for i in range(start, end):
if activites[0][i][0] > creche.GetCapacite(line.day):
dlg = wx.MessageDialog(None, u"Dépassement de la capacité sur ce créneau horaire !", "Attention", wx.OK|wx.ICON_WARNING)
dlg.ShowModal()
dlg.Destroy()
self.state = None
return
def UpdateContents(self):
if self.date in creche.jours_fermeture:
conge = creche.jours_fermeture[self.date]
if conge.options == ACCUEIL_NON_FACTURE:
self.SetInfo(conge.label)
else:
if conge.label:
self.Disable(conge.label)
else:
self.Disable(u"Crèche fermée")
return
else:
self.SetInfo("")
self.lignes_enfants = []
for inscrit in creche.inscrits:
inscription = inscrit.GetInscription(self.date)
if inscription is not None and (len(creche.sites) <= 1 or inscription.site is self.site) and (self.groupe is None or inscription.groupe == self.groupe):
if creche.conges_inscription == GESTION_CONGES_INSCRIPTION_SIMPLE and self.date in inscrit.jours_conges:
line = LigneConge(inscrit.jours_conges[self.date].label)
elif self.date in inscrit.journees:
line = inscrit.journees[self.date]
if creche.conges_inscription == GESTION_CONGES_INSCRIPTION_AVEC_SUPPLEMENT and self.date in inscrit.jours_conges:
line.reference = JourneeReferenceInscription(None, 0)
if not line.commentaire:
line.commentaire = inscrit.jours_conges[self.date].label
else:
line.reference = inscription.GetJourneeReference(self.date)
line.insert = None
line.key = self.date
elif creche.conges_inscription == GESTION_CONGES_INSCRIPTION_AVEC_SUPPLEMENT and self.date in inscrit.jours_conges:
reference = JourneeReferenceInscription(None, 0)
line = Journee(inscrit, self.date, reference)
line.reference = reference
line.commentaire = inscrit.jours_conges[self.date].label
line.insert = inscrit.journees
line.key = self.date
else:
line = inscription.GetJourneeReferenceCopy(self.date)
line.reference = inscription.GetJourneeReference(self.date)
line.insert = inscrit.journees
line.key = self.date
line.label = GetPrenomNom(inscrit)
line.inscription = inscription
line.options |= COMMENTS|ACTIVITES
line.summary = SUMMARY_NUM
def GetHeuresEnfant(line):
heures = line.GetNombreHeures()
if heures > 0:
return GetHeureString(heures)
else:
return None
line.GetDynamicText = GetHeuresEnfant
if creche.temps_facturation == FACTURATION_FIN_MOIS:
date = GetMonthStart(self.date)
else:
date = GetNextMonthStart(self.date)
if date in inscrit.factures_cloturees:
line.readonly = True
line.day = self.date.weekday()
self.lignes_enfants.append(line)
if creche.tri_planning == TRI_GROUPE:
self.lignes_enfants = TrieParGroupes(self.lignes_enfants)
else:
self.lignes_enfants.sort(key=lambda line: line.label)
self.lignes_salaries = []
for salarie in creche.salaries:
contrat = salarie.GetContrat(self.date)
if contrat is not None and (len(creche.sites) <= 1 or contrat.site is self.site):
if self.date in salarie.journees:
line = salarie.journees[self.date]
line.reference = contrat.GetJourneeReference(self.date)
line.insert = None
else:
line = contrat.GetJourneeReferenceCopy(self.date)
line.insert = salarie.journees
line.key = self.date
line.salarie = salarie
line.label = GetPrenomNom(salarie)
line.contrat = contrat
line.day = self.date.weekday()
def GetHeuresSalarie(line):
date = line.date - datetime.timedelta(line.date.weekday())
heures_semaine = 0
for i in range(7):
if date in line.salarie.journees:
heures = line.salarie.journees[date].GetNombreHeures()
else:
heures = line.contrat.GetJourneeReference(date).GetNombreHeures()
heures_semaine += heures
if date == line.date:
heures_jour = heures
date += datetime.timedelta(1)
return GetHeureString(heures_jour) + '/' + GetHeureString(heures_semaine)
line.GetDynamicText = GetHeuresSalarie
line.summary = SUMMARY_DEN
self.lignes_salaries.append(line)
self.lignes_salaries.sort(key=lambda line: line.label)
if self.lignes_salaries:
self.lignes_enfants.append(None)
self.SetLines(self.lignes_enfants + self.lignes_salaries)
def GetSummaryDynamicText(self):
heures = 0.0
for line in self.lines:
if line is None:
break
elif not isinstance(line, basestring):
heures += line.GetNombreHeures()
day = line.day
if heures > 0:
text = GetHeureString(heures)
if self.site:
den = self.site.capacite * creche.GetAmplitudeHoraire()
else:
den = creche.GetHeuresAccueil(day)
if den > 0:
text += " / " + "%.1f%%" % (heures * 100 / den)
return text
else:
return None
def SetData(self, site, groupe, date):
self.site = site
self.groupe = groupe
self.date = date
self.UpdateContents()
class PlanningPanel(GPanel):
name = "Planning"
bitmap = GetBitmapFile("planning.png")
profil = PROFIL_ALL
def __init__(self, parent):
GPanel.__init__(self, parent, u'Planning')
sizer = wx.BoxSizer(wx.HORIZONTAL)
self.current_site = 0
# La combobox pour la selection du site
self.site_choice = wx.Choice(self, -1)
for site in creche.sites:
self.site_choice.Append(site.nom, site)
sizer.Add(self.site_choice, 0, wx.ALIGN_CENTER_VERTICAL|wx.EXPAND)
if len(creche.sites) < 2:
self.site_choice.Show(False)
self.site_choice.SetSelection(0)
self.Bind(wx.EVT_CHOICE, self.OnChangementSemaine, self.site_choice)
# Les raccourcis pour semaine précédente / suivante
self.previous_button = wx.Button(self, -1, '<', size=(20,0), style=wx.NO_BORDER)
self.next_button = wx.Button(self, -1, '>', size=(20,0), style=wx.NO_BORDER)
self.Bind(wx.EVT_BUTTON, self.onPreviousWeek, self.previous_button)
self.Bind(wx.EVT_BUTTON, self.onNextWeek, self.next_button)
sizer.Add(self.previous_button, 0, wx.ALIGN_CENTER_VERTICAL|wx.EXPAND)
sizer.Add(self.next_button, 0, wx.ALIGN_CENTER_VERTICAL|wx.EXPAND)
# La combobox pour la selection de la semaine
self.week_choice = wx.Choice(self, -1)
sizer.Add(self.week_choice, 1, wx.ALIGN_CENTER_VERTICAL|wx.EXPAND)
PopulateWeekChoice(self.week_choice)
self.Bind(wx.EVT_CHOICE, self.OnChangementSemaine, self.week_choice)
# La combobox pour la selection du groupe (si groupes)
self.groupe_choice = wx.Choice(self, -1)
sizer.Add(self.groupe_choice, 0, wx.ALIGN_CENTER_VERTICAL)
self.Bind(wx.EVT_CHOICE, self.OnChangeGroupeDisplayed, self.groupe_choice)
self.UpdateGroupeCombobox()
# La combobox pour la selection de l'outil (si activités)
self.activity_choice = ActivityComboBox(self)
sizer.Add(self.activity_choice, 0, wx.ALIGN_CENTER_VERTICAL)
# Le bouton d'impression
bmp = wx.Bitmap(GetBitmapFile("printer.png"), wx.BITMAP_TYPE_PNG)
button = wx.BitmapButton(self, -1, bmp, style=wx.NO_BORDER)
sizer.Add(button, 0, wx.ALIGN_CENTER_VERTICAL|wx.LEFT, 5)
self.Bind(wx.EVT_BUTTON, self.onPrintPlanning, button)
# Le bouton de synchro tablette
if config.options & TABLETTE:
bmp = wx.Bitmap(GetBitmapFile("tablette.png"), wx.BITMAP_TYPE_PNG)
button = wx.BitmapButton(self, -1, bmp, style=wx.NO_BORDER)
sizer.Add(button, 0, wx.ALIGN_CENTER_VERTICAL|wx.LEFT, 5)
self.Bind(wx.EVT_BUTTON, self.onTabletteSynchro, button)
self.sizer.Add(sizer, 0, wx.EXPAND)
# le notebook pour les jours de la semaine
self.notebook = wx.Notebook(self, style=wx.LB_DEFAULT)
self.sizer.Add(self.notebook, 1, wx.EXPAND|wx.TOP, 5)
first_monday = GetFirstMonday()
delta = datetime.date.today() - first_monday
semaine = int(delta.days / 7)
for week_day in range(7):
if JourSemaineAffichable(week_day):
date = first_monday + datetime.timedelta(semaine * 7 + week_day)
planning_panel = DayPlanningPanel(self.notebook, self.activity_choice)
self.notebook.AddPage(planning_panel, GetDateString(date))
self.Bind(wx.EVT_NOTEBOOK_PAGE_CHANGED, self.OnChangementSemaineday, self.notebook)
self.sizer.Layout()
def UpdateGroupeCombobox(self):
if len(creche.groupes) > 0:
self.groupe_choice.Clear()
for groupe, value in [("Tous groupes", None)] + [(groupe.nom, groupe) for groupe in creche.groupes]:
self.groupe_choice.Append(groupe, value)
self.groupe_choice.SetSelection(0)
self.groupe_choice.Show(True)
else:
self.groupe_choice.Show(False)
self.last_groupe_observer = time.time()
def onPrintPlanning(self, evt):
site = self.GetSelectedSite()
groupe = self.GetSelectedGroupe()
week_selection = self.week_choice.GetSelection()
start = self.week_choice.GetClientData(week_selection)
end = start + datetime.timedelta(6)
DocumentDialog(self, PlanningDetailleModifications((start, end), site, groupe)).ShowModal()
def OnChangeGroupeDisplayed(self, evt):
self.OnChangementSemaine(None)
def OnChangementSemaineday(self, evt=None):
self.notebook.GetCurrentPage().UpdateDrawing()
def GetSelectedSite(self):
if len(creche.sites) > 1:
self.current_site = self.site_choice.GetSelection()
return self.site_choice.GetClientData(self.current_site)
else:
return None
def GetSelectedGroupe(self):
if len(creche.groupes) > 1:
self.current_groupe = self.groupe_choice.GetSelection()
return self.groupe_choice.GetClientData(self.current_groupe)
else:
return None
def OnChangementSemaine(self, evt=None):
self.UpdateWeek()
self.notebook.SetSelection(0)
self.sizer.Layout()
def UpdateWeek(self):
site = self.GetSelectedSite()
groupe = self.GetSelectedGroupe()
week_selection = self.week_choice.GetSelection()
self.previous_button.Enable(week_selection is not 0)
self.next_button.Enable(week_selection is not self.week_choice.GetCount() - 1)
monday = self.week_choice.GetClientData(week_selection)
page_index = 0
for week_day in range(7):
if JourSemaineAffichable(week_day):
day = monday + datetime.timedelta(week_day)
self.notebook.SetPageText(page_index, GetDateString(day))
note = self.notebook.GetPage(page_index)
note.SetData(site, groupe, day)
page_index += 1
def onPreviousWeek(self, evt):
self.week_choice.SetSelection(self.week_choice.GetSelection() - 1)
self.OnChangementSemaine()
def onNextWeek(self, evt):
self.week_choice.SetSelection(self.week_choice.GetSelection() + 1)
self.OnChangementSemaine()
def onTabletteSynchro(self, evt):
journal = config.connection.LoadJournal()
class PeriodePresence(object):
def __init__(self, date, arrivee=None, depart=None, absent=False, malade=False):
self.date = date
self.arrivee = arrivee
self.depart = depart
self.absent = absent
self.malade = malade
array = {}
lines = journal.split("\n")
index = -1
if len(creche.last_tablette_synchro) > 20:
try:
index = lines.index(creche.last_tablette_synchro)
except:
pass
for line in lines[index+1:]:
try:
label, idx, date = line.split()
idx = int(idx)
tm = time.strptime(date, "%Y-%m-%d@%H:%M")
date = datetime.date(tm.tm_year, tm.tm_mon, tm.tm_mday)
if idx not in array:
array[idx] = []
if label == "arrivee":
arrivee = tm.tm_hour * 12 + tm.tm_min / creche.granularite * (creche.granularite/BASE_GRANULARITY)
array[idx].append(PeriodePresence(date, arrivee))
elif label == "depart":
depart = tm.tm_hour * 12 + (tm.tm_min+creche.granularite-1) / creche.granularite * (creche.granularite/BASE_GRANULARITY)
if len(array[idx]):
last = array[idx][-1]
if last.date == date and last.arrivee:
last.depart = depart
else:
array[idx].append(PeriodePresence(date, None, depart))
else:
array[idx].append(PeriodePresence(date, None, depart))
elif label == "absent":
array[idx].append(PeriodePresence(date, absent=True))
elif label == "malade":
array[idx].append(PeriodePresence(date, malade=True))
creche.last_tablette_synchro = line
except Exception, e:
pass
errors = []
for key in array:
inscrit = creche.GetInscrit(key)
if inscrit:
for periode in array[key]:
value = 0
if periode.absent:
value = VACANCES
elif periode.malade:
value = MALADE
elif not periode.arrivee:
if not date in inscrit.journees:
errors.append(u"%s : Pas d'arrivée enregistrée le %s" % (GetPrenomNom(inscrit), periode.date))
reference = inscrit.GetJournee(periode.date)
if reference:
periode.arrivee = reference.GetPlageHoraire()[0]
if periode.arrivee is None:
periode.arrivee = int(creche.ouverture*(60 / BASE_GRANULARITY))
else:
continue
elif not periode.depart:
if periode.date != today:
errors.append(u"%s : Pas de départ enregistré le %s" % (GetPrenomNom(inscrit), periode.date))
reference = inscrit.GetJournee(date)
if reference:
periode.depart = reference.GetPlageHoraire()[-1]
if periode.depart is None:
periode.depart = int(creche.fermeture*(60 / BASE_GRANULARITY))
else:
continue
if periode.date in inscrit.journees:
inscrit.journees[periode.date].RemoveActivities(0)
inscrit.journees[periode.date].RemoveActivities(0|PREVISIONNEL)
else:
inscrit.journees[periode.date] = Journee(inscrit, periode.date)
if value < 0:
inscrit.journees[periode.date].SetState(value)
else:
inscrit.journees[periode.date].SetActivity(periode.arrivee, periode.depart, value)
history.Append(None)
else:
errors.append(u"Inscrit %d: Inconnu!" % key)
if errors:
dlg = wx.MessageDialog(None, u"\n".join(errors), u'Erreurs de saisie tablette', wx.OK|wx.ICON_WARNING)
dlg.ShowModal()
dlg.Destroy()
self.UpdateWeek()
def UpdateContents(self):
if len(creche.sites) > 1:
self.site_choice.Show(True)
self.site_choice.Clear()
for site in creche.sites:
self.site_choice.Append(site.nom, site)
self.site_choice.SetSelection(self.current_site)
else:
self.site_choice.Show(False)
self.activity_choice.Clear()
selected = 0
if creche.HasActivitesAvecHoraires():
self.activity_choice.Show(True)
for i, activity in enumerate(creche.activites.values()):
if activity.mode not in (MODE_SANS_HORAIRES, MODE_SYSTEMATIQUE_SANS_HORAIRES):
self.activity_choice.Append(activity.label, activity)
try:
if self.activity_choice.activity.value == activity.value:
selected = i
except:
pass
else:
self.activity_choice.Show(False)
self.activity_choice.Append(creche.activites[0].label, creche.activites[0])
self.activity_choice.SetSelection(selected)
if 'groupes' in observers and observers['groupes'] > self.last_groupe_observer:
self.UpdateGroupeCombobox()
self.OnChangementSemaine()
self.sizer.Layout()