From 860c9ec990c494783b911aaa557438e50def2492 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Olivier=20Larchev=C3=AAque?= Date: Mon, 13 Feb 2012 10:35:13 -0500 Subject: [PATCH] date poste import --- .../legacy/management/commands/rh_import_legacy.py | 24 +++++++++++++------- project/rh/admin.py | 4 ++-- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/project/legacy/management/commands/rh_import_legacy.py b/project/legacy/management/commands/rh_import_legacy.py index 0709494..728f60f 100644 --- a/project/legacy/management/commands/rh_import_legacy.py +++ b/project/legacy/management/commands/rh_import_legacy.py @@ -11,6 +11,14 @@ from django.db.models import Q, Max from project.legacy import models as legacy from project.rh import models as rh +def clean_date(date): + if date == '2003-06-31': # date inexistante (dossier 791-1) + return '2003-06-30' + elif date: + return date + else: + return None + class Command(BaseCommand): help = 'Importe les données du système RH legacy' @@ -147,6 +155,8 @@ def sync_poste(): if dossiers.count() == 0: service = None poste_du_responsable = None + date_debut = None + date_fin = None if dossiers.count() > 0: @@ -173,6 +183,10 @@ def sync_poste(): except: poste_du_responsable = None + # initialiser les dates du poste avec les dates du dossier + date_debut = clean_date(dossier.date_debut_mandat) + date_fin = clean_date(dossier.date_fin_mandat) + # Créer le poste rh_poste = rh.Poste.objects.create( id=poste.id_implantation_postes, @@ -184,6 +198,8 @@ def sync_poste(): service_id=service, supprime=False, responsable_id=poste_du_responsable, + date_debut=date_debut, + date_fin=date_fin, ) if service is None and poste.actif in ('0', 0, False): @@ -303,14 +319,6 @@ def sync_typeremuneration(): def sync_dossier(): - def clean_date(date): - if date == '2003-06-31': # date inexistante (dossier 791-1) - return '2003-06-30' - elif date: - return date - else: - return None - taux_cache = {} def get_taux(annee, devise): taux = taux_cache.get((annee, devise)) diff --git a/project/rh/admin.py b/project/rh/admin.py index 6c12274..fa1b26b 100644 --- a/project/rh/admin.py +++ b/project/rh/admin.py @@ -74,9 +74,9 @@ class ChangeList(DjangoChangeList): if date_debut is not None and date_fin is not None: q_left = (Q(**{'%s__isnull' % prefix_debut : True}) | Q(**{'%s__lte' % prefix_debut : date_debut})) & (Q(**{'%s__gte' % prefix_fin : date_debut}) & Q(**{'%s__lte' % prefix_fin : date_fin})) q_right = (Q(**{'%s__isnull' % prefix_fin : True}) | Q(**{'%s__gte' % prefix_fin : date_fin})) & (Q(**{'%s__gte' % prefix_debut : date_debut}) & Q(**{'%s__lte' % prefix_debut : date_fin})) - q_no_date = Q(**{'%s__isnull' % prefix_fin : True}) & Q(**{'%s__isnull' % prefix_debut : True}) + q_both = Q(**{'%s__isnull' % prefix_fin : True}) | Q(**{'%s__lte' % prefix_fin : date_fin}) & (Q(**{'%s__isnull' % prefix_debut : True}) | Q(**{'%s__gte' % prefix_debut : date_debut})) q_non_supprime = Q(**{'%s__exact' % prefix_debut.replace('date_debut', 'supprime') : False}) - q = (q_left | q_right | q_no_date) & q_non_supprime + q = (q_left | q_right | q_both) & q_non_supprime qs = qs.filter(q).distinct() self.params = old -- 1.7.10.4