poste dae -> poste rh
[auf_rh_dae.git] / project / dae / models.py
index 56f63f4..cfba8db 100644 (file)
@@ -71,6 +71,35 @@ class Poste(PosteWorkflow, rh.Poste_):
         rh_poste = rh.Poste()
         # Faire une copie profonde de l'objet.
         # PosteFinancement, PosteComparaison, Remun modele a ajuster...
+
+        def copy_model(src, dst, exclude=[]):
+            keys = [f.name for f in src._meta.fields if f.name not in ['id', ] + exclude]
+            for k in keys:
+                setattr(dst, k, getattr(src, k))
+            return dst
+        
+        rh_poste = copy_model(self, rh_poste)
+        rh_poste.save()
+        print rh_poste.id
+
+        for o in self.dae_financements.all():
+            rh_financement = rh.PosteFinancement()
+            rh_financement = copy_model(o, rh_financement, exclude=['poste',])
+            rh_financement.poste = rh_poste
+            rh_financement.save()
+
+        for o in self.dae_pieces.all():
+            rh_piece = rh.PostePiece()
+            rh_piece = copy_model(o, rh_piece, exclude=['poste',])
+            rh_piece.poste = rh_poste
+            rh_piece.save()
+
+        for o in self.dae_comparaisons_internes.all():
+            rh_comp = rh.PosteComparaison()
+            rh_comp = copy_model(o, rh_financement, exclude=['poste',])
+            rh_comp.poste = rh_poste
+            rh_comp.save()
+
         return rh_poste
 
     def _get_key(self):