# coding: utf-8
-from datetime import datetime, date
+from datetime import datetime, date, timedelta
from decimal import Decimal
from django.contrib.auth.models import User
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)
+ if date == '2003-06-31': # date inexistante (dossier 791-1)
return '2003-06-30'
elif date:
return date
coefficient=classement.coefficient,
commentaire=classement.commentaire,
date_modification=classement.date_modif,
- #actif=classement.actif
)
+
def sync_employe():
cursor = connection.cursor()
cursor.execute('TRUNCATE rh_employe')
nom=fiche.nom,
prenom=fiche.prenom,
nationalite_id=fiche.nationalite,
- date_naissance=fiche.date_naissance if fiche.date_naissance else None,
+ date_naissance=(fiche.date_naissance if fiche.date_naissance
+ else None),
genre=fiche.sexe.upper(),
- situation_famille=None if fiche.situation_famille == '-1' else fiche.situation_famille,
+ situation_famille=(None if fiche.situation_famille == '-1'
+ else fiche.situation_famille),
date_entree=fiche.date_entree,
tel_domicile=fiche.tel_domicile,
tel_cellulaire=fiche.tel_cellulaire,
date_creation=fiche.date_ouverture,
date_modification=fiche.date_maj,
supprime=False,
- nb_postes=None, # meta
+ nb_postes=None, # meta
)
if fiche.remarque:
rh.EmployeCommentaire.objects.create(
owner=odette
)
+
def sync_familleemploi():
cursor = connection.cursor()
cursor.execute('TRUNCATE rh_familleemploi')
rh.FamilleEmploi.objects.create(
id=famille.id_famille_emploi,
nom=famille.famille_emploi,
- #actif=famille.actif
)
+
def sync_typeposte():
cursor = connection.cursor()
cursor.execute('TRUNCATE rh_typeposte')
nom_feminin=type.titre_poste_f,
is_responsable=bool(int(type.poste_responsable)),
famille_emploi_id=type.id_famille_emploi,
- date_modification = type.datemaj,
- #actif=bool(int(type.actif))
+ date_modification=type.datemaj,
)
+
def sync_service():
cursor = connection.cursor()
cursor.execute('TRUNCATE rh_service')
- #for service in legacy.DirectionService.objects.all():
- # rh.Service.objects.create(
- # id=service.id_direction_service,
- # nom=service.direction_service,
- # archive=not bool(service.actif),
- # )
-
+
# Création des services à partir de la table de références
for s in ref.Service.objects.all():
rh.Service.objects.create(
nom=s.nom,
archive=not bool(s.actif),
)
-
+
def sync_poste():
cursor = connection.cursor()
cursor.execute('TRUNCATE rh_poste')
- for poste in legacy.ImplantationPostes.objects.select_related('type_poste'):
-
- #legacy.Fiches.objects.filter(prenom='Odette')[0].dossiers.all()[0].ids_direction_service
+ for poste in legacy.ImplantationPostes.objects \
+ .select_related('type_poste'):
# Aller chercher certaines informations dans le dernier dossier
# associé à ce poste
dossiers = legacy.Dossiers.objects.filter(
- Q(poste_1=poste.id_implantation_postes) | Q(poste_2=poste.id_implantation_postes)
+ Q(poste_1=poste.id_implantation_postes) |
+ Q(poste_2=poste.id_implantation_postes)
).order_by('-id_dossier')
complement = ''
# Déterminer le poste du responsable
try:
responsable = dossier.responsable
- dossiers_du_responsable = responsable.dossiers.order_by('-id_dossier')
+ dossiers_du_responsable = responsable.dossiers \
+ .order_by('-id_dossier')
if dossiers_du_responsable.count() > 0:
poste_du_responsable = dossiers_du_responsable[0].poste_1
except:
id=organisme.id_bstg,
nom=organisme.organisme_nom,
type=organisme.bstg_type,
- #actif=bool(organisme.actif)
)
+
def sync_statut():
connection.cursor().execute('TRUNCATE rh_statut')
for statut in legacy.Statut.objects.all():
id=statut.id_statut,
code=statut.statut_contractuel,
nom=statut.description_statut_contractuel,
- #actif=bool(statut.actif)
)
+
def sync_tauxchange():
connection.cursor().execute('TRUNCATE rh_tauxchange')
connection.cursor().execute('TRUNCATE rh_devise')
for taux in legacy.TauxChangeAnnuel.objects.exclude(taux_annuel=None):
# Créer la devise
- devise, created = rh.Devise.objects.get_or_create(code=taux.code_devise)
+ devise, created = rh.Devise.objects.get_or_create(
+ code=taux.code_devise
+ )
if created:
- devise.nom=taux.nom_devise
+ devise.nom = taux.nom_devise
devise.save()
# Créer le taux de change
taux=taux.taux_annuel,
)
+
def sync_valeurpoint():
connection.cursor().execute('TRUNCATE rh_valeurpoint')
for vp in legacy.ValeurPoint.objects.all():
# Trouver la devise associée à cette implantation
annee = vp.date_actif[:4]
try:
- taux = legacy.TauxChangeAnnuel.objects.get(annee=annee, id_implantation=vp.id_implantation)
+ taux = legacy.TauxChangeAnnuel.objects.get(
+ annee=annee, id_implantation=vp.id_implantation
+ )
except:
continue
devise = rh.Devise.objects.get(code=taux.code_devise)
devise=devise
)
+
def sync_typecontrat():
connection.cursor().execute('TRUNCATE rh_typecontrat')
for type in legacy.TypeContrat.objects.all():
id=type.id_type_contrat,
nom=type.nom_contrat,
nom_long=type.description_contrat,
- #actif=bool(type.actif_contrat)
)
+
def sync_typerevalorisation():
connection.cursor().execute('TRUNCATE rh_typerevalorisation')
for type in legacy.TypeRevalorisation.objects.all():
rh.TypeRevalorisation.objects.create(
id=type.id_type_revalorisation,
nom=type.type_revalorisation,
- #actif=bool(type.actif)
)
+
def sync_typeremuneration():
connection.cursor().execute('TRUNCATE rh_typeremuneration')
for type in legacy.TypeRemuneration.objects.all():
nom=type.type_remuneration,
type_paiement=type.type_paiement,
nature_remuneration=type.nature_remuneration,
- #actif=bool(type.actif)
)
-def sync_dossier():
+def sync_dossier():
taux_cache = {}
+
def get_taux(annee, devise):
taux = taux_cache.get((annee, devise))
if taux is not None:
return taux
- taux = rh.TauxChange.objects.filter(annee__gte=annee).order_by('annee')[0].taux
+ taux = rh.TauxChange.objects.filter(annee__gte=annee) \
+ .order_by('annee')[0].taux
taux_cache[(annee, devise)] = taux
return taux
nom='Inconnu',
nom_long='Inconnu',
)
- dossiers = legacy.Dossiers.objects.annotate(timestamp_modif=Max('historique__stamp')) \
+ dossiers = legacy.Dossiers.objects \
+ .annotate(timestamp_modif=Max('historique__stamp')) \
.order_by('no_dossier')
for dossier in dossiers:
date_modification = datetime.fromtimestamp(dossier.timestamp_modif) \
poste_id=dossier.poste_1,
statut_id=dossier.id_statut,
organisme_bstg_id=dossier.id_bstg,
- statut_residence='expat' if dossier.id_local_expatrie == 1 else 'local',
+ statut_residence=('expat' if dossier.id_local_expatrie == 1
+ else 'local'),
classement_id=dossier.id_classement,
regime_travail=dossier.regime_travail,
date_debut=clean_date(dossier.date_debut_mandat),
today = date.today().isoformat()
if not dossier.date_fin_mandat or dossier.date_fin_mandat >= today:
if dossier.responsable_implantation_1:
- responsable, created = rh.ResponsableImplantation.objects.get_or_create(
- implantation_id=dossier.id_implantation_1
- )
+ responsable, created = rh.ResponsableImplantation.objects \
+ .get_or_create(
+ implantation_id=dossier.id_implantation_1
+ )
responsable.employe_id = dossier.employe_id
responsable.save()
if dossier.responsable_implantation_2:
- responsable, created = rh.ResponsableImplantation.objects.get_or_create(
- implantation_id=dossier.id_implantation_2
- )
+ responsable, created = rh.ResponsableImplantation.objects \
+ .get_or_create(
+ implantation_id=dossier.id_implantation_2
+ )
responsable.employe_id = dossier.employe_id
responsable.save()
charges_precedentes = None
pourcentage_charges = 0
devise_charges = rh.Devise.objects.get(code='EUR')
- for remun in legacy.HistoRemuneration.objects.filter(no_dossier=dossier.no_dossier) \
+ for remun in legacy.HistoRemuneration.objects \
+ .filter(no_dossier=dossier.no_dossier) \
.order_by('id_histo_remuneration'):
# Calcul de la période
date_debut = '2000-08-09'
elif date_debut == '2003-06-31':
date_debut = '2003-06-30'
+ date_debut = date(
+ int(date_debut[:4]), int(date_debut[5:7]), int(date_debut[8:])
+ )
if remun.type_remuneration.type_paiement == 'Ponctuel':
date_fin = date_debut
else:
date_fin = None
- remun_precedente = remuns_precedentes.get(remun.type_remuneration_id)
+ remun_precedente = remuns_precedentes.get(
+ remun.type_remuneration_id
+ )
if remun_precedente:
if str(remun_precedente.date_debut) == str(date_debut):
remun_precedente.delete()
else:
- remun_precedente.date_fin = date_debut
+ remun_precedente.date_fin = \
+ date_debut - timedelta(days=1)
remun_precedente.save()
# Création de la ligne de rémunération
- if remun.type_remuneration.nature_remuneration != 'Charges' and remun.montant != 0:
- devise, created = rh.Devise.objects.get_or_create(code=remun.code_devise)
+ if remun.type_remuneration.nature_remuneration != 'Charges' \
+ and remun.montant != 0:
+ devise, created = rh.Devise.objects.get_or_create(
+ code=remun.code_devise
+ )
rh_remun = rh.Remuneration.objects.create(
dossier=dossier1,
if remun.type_remuneration.type_paiement == u'Régulier':
charges = 0
- annee_charges = int(date_debut[:4])
+ annee_charges = date_debut.year
taux2 = get_taux(annee_charges, devise_charges)
if pourcentage_charges:
for remun_precedente in remuns_precedentes.values():
devise = remun_precedente.devise
if devise != devise_charges:
taux1 = get_taux(annee_charges, devise)
- montant = montant * Decimal(str(taux1)) / Decimal(str(taux2))
- if remun_precedente.type.nature_remuneration == 'Traitement':
- montant = montant * remun_precedente.dossier.regime_travail / 100
+ montant = (montant * Decimal(str(taux1)) /
+ Decimal(str(taux2)))
+ if remun_precedente.type.nature_remuneration == \
+ 'Traitement':
+ montant = (
+ montant *
+ remun_precedente.dossier.regime_travail / 100
+ )
montant = montant * pourcentage_charges / 100
montant.quantize(remun_precedente.montant)
charges += montant
charges = charges * pourcentage_charges / 100
if charges_precedentes:
- if str(charges_precedentes.date_debut) == str(date_debut):
+ if charges_precedentes.date_debut == date_debut:
charges_precedentes.delete()
else:
- charges_precedentes.date_fin = date_debut
+ charges_precedentes.date_fin = date_debut - \
+ timedelta(days=1)
charges_precedentes.save()
if charges > 0 and \
- (not charges_precedentes or charges_precedentes.montant != charges or
- str(charges_precedentes.date_debut) == str(date_debut)):
+ (not charges_precedentes or
+ charges_precedentes.montant != charges or
+ charges_precedentes.date_debut == date_debut):
charges_precedentes = rh.Remuneration.objects.create(
dossier=dossier1,
type_id=17,
devise=devise_charges,
supprime=False,
date_debut=date_debut,
- commentaire=u'Charges patronales: %s%%' % pourcentage_charges
+ commentaire=(u'Charges patronales: %s%%' %
+ pourcentage_charges)
)
# Dossier différent pour le deuxième poste
poste_id=dossier.poste_2,
statut_id=dossier.id_statut,
organisme_bstg_id=dossier.id_bstg,
- statut_residence='expat' if dossier.id_local_expatrie == 1 else 'local',
+ statut_residence=('expat' if dossier.id_local_expatrie == 1
+ else 'local'),
classement_id=dossier.id_classement,
regime_travail=dossier.regime_travail,
date_debut=clean_date(dossier.date_debut_mandat),
)
rh.Contrat.objects.create(
dossier=dossier2,
- type_contrat_id=dossier.id_type_contrat or type_contrat_inconnu.id,
+ type_contrat_id=(dossier.id_type_contrat or
+ type_contrat_inconnu.id),
date_debut=clean_date(dossier.date_debut_contrat),
date_fin=clean_date(dossier.date_fin_contrat),
supprime=False
)
+
def sync_ayantdroit():
connection.cursor().execute('TRUNCATE rh_ayantdroit')
odette = User.objects.get(username='odette.tremblay')
nom=ad.nom_ayant_droit,
prenom=ad.prenom_ayant_droit,
employe_id=ad.no_employe,
- lien_parente=None if ad.lien_parente == 'Autre' else ad.lien_parente,
- #actif=bool(ad.actif)
+ lien_parente=(None if ad.lien_parente == 'Autre'
+ else ad.lien_parente),
)
if ad.commentaire_ayant_droit:
rh.AyantDroitCommentaire.objects.create(
owner=odette
)
+
def sync_devises():
for p in rh.Poste.objects.all():
if p.implantation is not None:
- qs = rh.ValeurPoint.objects.filter(implantation=p.implantation).order_by('-id')
+ qs = rh.ValeurPoint.objects \
+ .filter(implantation=p.implantation) \
+ .order_by('-id')
if qs.exists():
point = qs[0]
p.devise_min = point.devise