arst
[auf_rh_dae.git] / project / budget / models.py
CommitLineData
3fde9fe8
NC
1# -=- encoding: utf-8 -=-
2
3from django.db import models
4
5from rh import models as rh
6
7
8class Simulation(models.Model):
9 nom = models.CharField(max_length=255,
10 verbose_name=u'Nom de la simulation')
11
0c248d0a
NC
12 def copy_rh_model(self, obj):
13 """ Crée une copie de simulation d'un modèle rh. """
14 initial = dict(['simulation', self] +
15 [(f.name, getattr(obj, f.name))
16 for f in obj._meta.fields
17 if not isinstance(f, models.AutoField) and
18 not f in obj._meta.parents.values()])
19 return globals()[obj.__class__.__name__](**initial)
20
21
22 def initialize(self):
23 """ Copie les données nécessaires à une simulation. """
24 if (self.poste_set.all().count() > 0 or
25 self.dossier_set.all().count() > 0):
26 raise ValueError(u'Cette simulation a déjà été initialisée.')
27
28 postes = {}
29 for rh_p in rh.Poste.objects.all():
30 sim_p = self.copy_rh_model(rh_p)
31 sim_p.save()
32 postes[rh_p.id] = sim_p
33
34 dossiers = {}
35 for rh_d in rh.Dossier.objects.all():
36 sim_d = self.copy_rh_model(rh_d)
37 if not sim_d.poste.id in postes:
38 self.poste_set.all().delete()
39 self.dossier_set.all().delete()
40 raise ValueError(u'Données inconsistantes.')
41 sim_d.poste = postes[sim_d.poste.id]
42 sim_d.save()
43 dossiers[rh_d.id] = sim_d
3fde9fe8 44
f31ddfa0
NC
45class Dossier(rh.Dossier_):
46 __doc__ = rh.Dossier_.__doc__
47 simulation = models.ForeignKey(Simulation)
48
49
50class Evenement(rh.Evenement_):
51 __doc__ = rh.Evenement_.__doc__
52 simulation = models.ForeignKey(Simulation)
53
54
55class EvenementRemuneration(rh.EvenementRemuneration_):
56 __doc__ = rh.EvenementRemuneration_.__doc__
57 simulation = models.ForeignKey(Simulation)
58
59
3fde9fe8
NC
60class Poste(rh.Poste_):
61 __doc__ = rh.Poste_.__doc__
62 simulation = models.ForeignKey(Simulation)
63
64
f31ddfa0
NC
65class PosteFinancement(rh.PosteFinancement_):
66 __doc__ = rh.PosteFinancement_.__doc__
67 simulation = models.ForeignKey(Simulation)
68
69
70class Remuneration(rh.Remuneration_):
71 __doc__ = rh.Remuneration_.__doc__
3fde9fe8 72 simulation = models.ForeignKey(Simulation)