from django.conf import settings
from django.db.models import Q, Count
from django.template.defaultfilters import date
+from django.utils.formats import date_format
from ajax_select import make_ajax_form
'_id',
'_apercu',
'_nom',
- '_poste',
'_employe',
+ '_poste',
+ '_region',
+ '_implantation',
'_date_debut',
'_date_fin',
'_date_modification',
- 'user_modification',
'_dae',
)
list_display_links = ('_nom',)
_id.short_description = u"#"
_id.admin_order_field = "id"
- def _nom(self, obj):
- return "%d : %s %s" % (
- obj.date_debut.year,
- obj.employe.nom.upper(),
- obj.employe.prenom)
- _nom.allow_tags = True
- _nom.short_description = u"Dossier"
-
def _apercu(self, d):
apercu_link = u"""<a title="Aperçu du dossier"
onclick="return showAddAnotherPopup(this);"
_apercu.allow_tags = True
_apercu.short_description = u""
- def _dae(self, d):
- apercu_link = ""
- dossiers_dae = d.dossiers_dae.all()
- if len(dossiers_dae) > 0:
- dossier_dae = dossiers_dae[0]
- apercu_link = u"""<a title="Aperçu du dossier"
- onclick="return showAddAnotherPopup(this);"
- href='%s'>
- <img src="%simg/loupe.png" />
- </a>""" % \
- (reverse('embauche_consulter', args=(dossier_dae.id,)),
- settings.STATIC_URL,
- )
- return apercu_link
- _dae.allow_tags = True
- _dae.short_description = u"DAE"
-
- def _date_debut(self, obj):
- return date(obj.date_debut)
-
- _date_debut.short_description = u'Occupation début'
- _date_debut.admin_order_field = 'date_debut'
+ def _nom(self, obj):
+ return "Dossier"
+ _nom.allow_tags = True
+ _nom.short_description = u"Dossier"
- def _date_fin(self, obj):
- return date(obj.date_fin)
- _date_fin.short_description = u'Occupation fin'
- _date_fin.admin_order_field = 'date_fin'
+ def _employe(self, obj):
+ employe = obj.employe
+ view_link = reverse('employe_apercu', args=(employe.id,))
+ edit_link = reverse('admin:rh_employe_change', args=(employe.id,))
- def _date_modification(self, obj):
- return date(obj.date_modification) \
- if obj.date_modification is not None else "(aucune)"
- _date_modification.short_description = u'date modification'
- _date_modification.admin_order_field = 'date_modification'
+ style = ""
+ view = u"""<a href="%s"
+ title="Aperçu l'employé"
+ onclick="return showAddAnotherPopup(this);">
+ <img src="%simg/employe-apercu.png" />
+ </a>""" % (view_link, settings.STATIC_URL,)
+ return u"""%s<a href='%s' style="%s;">%s</a>""" % \
+ (view, edit_link, style, employe)
+ _employe.allow_tags = True
+ _employe.short_description = u"Employé"
+ _employe.admin_order_field = "employe__nom"
def _poste(self, dossier):
link = u"""<a title="Aperçu du poste"
onclick="return showAddAnotherPopup(this);"
href='%s'><img src="%simg/poste-apercu.png" />
</a>
- <a href="%s" title="Modifier le poste">%s</a>""" % \
+ <a href="%s" title="Modifier le poste">%s [%d]</a>""" % \
(reverse('poste_apercu', args=(dossier.poste.id,)),
settings.STATIC_URL,
reverse('admin:rh_poste_change', args=(dossier.poste.id,)),
- dossier.poste,
+ dossier.poste.nom,
+ dossier.poste.id,
)
return link
_poste.allow_tags = True
_poste.short_description = u'Poste'
_poste.admin_order_field = 'poste__nom'
- def _employe(self, obj):
- employe = obj.employe
- view_link = reverse('employe_apercu', args=(employe.id,))
- edit_link = reverse('admin:rh_employe_change', args=(employe.id,))
+ def _region(self, obj):
+ return obj.poste.implantation.region.code
+ _region.short_description = u"Région"
+ _region.admin_order_field = 'poste__implantation__region__code'
- style = ""
- view = u"""<a href="%s"
- title="Aperçu l'employé"
- onclick="return showAddAnotherPopup(this);">
- <img src="%simg/employe-apercu.png" />
- </a>""" % (view_link, settings.STATIC_URL,)
- return u"""%s<a href='%s' style="%s;">%s</a>""" % \
- (view, edit_link, style, employe)
- _employe.allow_tags = True
- _employe.short_description = u"Employé"
- _employe.admin_order_field = "employe__nom"
+ def _implantation(self, obj):
+ return obj.poste.implantation.nom
+ _implantation.short_description = u"Implantation"
+ _implantation.admin_order_field = 'poste__implantation__nom'
+
+ def _date_debut(self, obj):
+ return date(obj.date_debut)
+
+ _date_debut.short_description = u'Début'
+ _date_debut.admin_order_field = 'date_debut'
+
+ def _date_fin(self, obj):
+ return date(obj.date_fin)
+ _date_fin.short_description = u'Fin'
+ _date_fin.admin_order_field = 'date_fin'
+
+ def _date_modification(self, obj):
+ return date(obj.date_modification) \
+ if obj.date_modification is not None else "(aucune)"
+ _date_modification.short_description = u'date modification'
+ _date_modification.admin_order_field = 'date_modification'
+
+ def _dae(self, d):
+ apercu_link = ""
+ dossiers_dae = d.dossiers_dae.all()
+ if len(dossiers_dae) > 0:
+ dossier_dae = dossiers_dae[0]
+ apercu_link = u"""<a title="Aperçu du dossier"
+ onclick="return showAddAnotherPopup(this);"
+ href='%s'>
+ <img src="%simg/loupe.png" />
+ </a>""" % \
+ (reverse('embauche_consulter', args=(dossier_dae.id,)),
+ settings.STATIC_URL,
+ )
+ return apercu_link
+ _dae.allow_tags = True
+ _dae.short_description = u"DAE"
def save_formset(self, request, form, formset, change):
instances = formset.save(commit=False)
'_apercu',
'_nom',
'_dossiers_postes',
+ '_region',
+ '_implantation',
'date_entree',
'_date_modification',
- 'user_modification',
)
list_display_links = ('_nom',)
list_filter = (
),
)
+ def _id(self, obj):
+ return obj.id
+ _id.short_description = u"#"
+ _id.admin_order_field = "id"
+
def _apercu(self, obj):
return u"""<a title="Aperçu de l'employé"
onclick="return showAddAnotherPopup(this);"
_nom.short_description = u"Employé"
_nom.admin_order_field = "nom"
- def _id(self, obj):
- return obj.id
- _id.short_description = u"#"
- _id.admin_order_field = "id"
+ def _region(self, obj):
+ try:
+ d = rh.Dossier.objects.filter(employe=obj.id, principal=True)[0]
+ region = d.poste.implantation.region.code
+ except:
+ region = None
+ return region
+ _region.short_description = u"Région"
- def _date_modification(self, obj):
- return date(obj.date_modification) \
- if obj.date_modification is not None else "(aucune)"
- _date_modification.short_description = u'date modification'
- _date_modification.admin_order_field = 'date_modification'
+ def _implantation(self, obj):
+ try:
+ d = rh.Dossier.objects.filter(employe=obj.id, principal=True)[0]
+ implantation = d.poste.implantation.nom
+ except:
+ implantation = None
+ return implantation
+ _implantation.short_description = u"Implantation"
def _dossiers_postes(self, obj):
l = []
for d in obj.rh_dossiers.all().order_by('-date_debut'):
+ actif = True
+ link_style = u''
+ list_style = u''
+ if d.date_fin is not None and d.date_fin < datetime.date.today():
+ actif = False
+ link_style = u' style="color:#666;"'
+ list_style = u' style="color:grey;"'
+
dossier = u"""<a title="Aperçu du dossier"
href="%s"
onclick="return showAddAnotherPopup(this);"
title="Aperçu du dossier">
<img src="%simg/dossier-apercu.png" />
</a>
- <a href="%s">Dossier</a>
+ <a href="%s"%s>Dossier</a>
""" % \
(reverse('dossier_apercu', args=(d.id,)),
settings.STATIC_URL,
- reverse('admin:rh_dossier_change', args=(d.id,)))
+ reverse('admin:rh_dossier_change', args=(d.id,)),
+ link_style,)
poste = u"""<a title="Aperçu du poste"
href="%s"
title="Aperçu du poste">
<img src="%simg/poste-apercu.png" />
</a>
- <a href="%s">Poste</a>
+ <a href="%s"%s>%s [%d]</a>
""" % \
(reverse('poste_apercu', args=(d.poste.id,)),
settings.STATIC_URL,
- reverse('admin:rh_poste_change', args=(d.poste.id,)))
- link = u"""<li>%s %s - %s : [%s] %s</li>""" % \
- (dossier, poste,
- d.date_debut.year,
- d.poste.id,
+ reverse('admin:rh_poste_change', args=(d.poste.id,)),
+ link_style,
d.poste.nom,
- )
-
- # Dossier terminé en gris non cliquable
- if d.date_fin is not None and d.date_fin < datetime.date.today():
- link = u"""<li style="color: grey">%s : [%s] %s</li>""" % \
- (d.date_debut.year,
- d.poste.id,
- d.poste.nom,
- )
+ d.poste.id)
+
+ link = u"""<li%s>%s %s</li>""" % \
+ (list_style, dossier, poste)
l.append(link)
return "<ul>%s</ul>" % "\n".join(l)
_dossiers_postes.allow_tags = True
_dossiers_postes.short_description = u"Dossiers et postes"
+ def _date_modification(self, obj):
+ return date(obj.date_modification) \
+ if obj.date_modification is not None else "(aucune)"
+ _date_modification.short_description = u'date modification'
+ _date_modification.admin_order_field = 'date_modification'
+
def queryset(self, request):
qs = super(EmployeAdmin, self).queryset(request)
return qs.select_related(depth=1).order_by('nom')
'_apercu',
'_nom',
'_occupe_par',
+ '_region',
'_implantation',
'_service',
'_responsable',
- 'date_debut',
- 'date_fin',
+ '_date_debut',
+ '_date_fin',
'_date_modification',
- 'user_modification',
'_dae',
)
list_filter = (
'service__isnull', 'vacant__exact', 'vacant__isnull',
) or super(PosteAdmin, self).lookup_allowed(key, value)
+ def _id(self, obj):
+ return "%s" % obj.id
+ _id.short_description = '#'
+ _id.admin_order_field = 'id'
+
def _apercu(self, poste):
view_link = u"""<a onclick="return showAddAnotherPopup(this);"
title="Aperçu du poste"
_apercu.allow_tags = True
_apercu.short_description = ''
- def _dae(self, poste):
- apercu_link = ""
- postes_dae = poste.postes_dae.all()
- if len(postes_dae) > 0:
- poste_dae = postes_dae[0]
- apercu_link = \
- u'<a title="Aperçu du dossier" href="%s" ' \
- u'onclick="return showAddAnotherPopup(this);">' \
- u'<img src="%simg/loupe.png" /></a>' % (reverse(
- 'poste_consulter', args=("dae-%s" % poste_dae.id,)
- ), settings.STATIC_URL)
- return apercu_link
- _dae.allow_tags = True
- _dae.short_description = u"DAE"
+ def _nom(self, poste):
+ return """<a href="%s">%s</a>""" % \
+ (reverse('admin:rh_poste_change', args=(poste.id,)),
+ poste.nom)
+ _nom.allow_tags = True
+ _nom.short_description = u'Poste'
+ _nom.admin_order_field = 'nom'
- def _id(self, obj):
- return "%s" % obj.id
- _id.short_description = '#'
- _id.admin_order_field = 'id'
+ def _occupe_par(self, obj):
+ """Formatte la méthode Poste.occupe_par() pour l'admin"""
+ output = u"Vacant"
+ if obj.date_fin is not None and obj.date_fin < datetime.date.today():
+ return u"s/o"
+ employes = obj.occupe_par()
+ if employes:
+ l = []
+ for e in employes:
+ link = u"""<a href='%s'
+ title='Aperçu de l\'employé'
+ onclick='return showAddAnotherPopup(this)'>
+ <img src='%simg/employe-apercu.png' />
+ </a>
+ <a href='%s'>%s</a>""" % \
+ (reverse('employe_apercu', args=(e.id,)),
+ settings.STATIC_URL,
+ reverse('admin:rh_employe_change', args=(e.id,)),
+ e)
+ l.append(link)
+ output = "\n<br />".join(l)
+ return output
+ _occupe_par.allow_tags = True
+ _occupe_par.short_description = "Occupé par"
+
+ def _region(self, poste):
+ return poste.implantation.region.code
+ _region.short_description = 'Région'
+ _region.admin_order_field = 'implantation__region__code'
+
+ def _implantation(self, poste):
+ return poste.implantation.nom
+ _implantation.short_description = 'Implantation'
+ _implantation.admin_order_field = 'implantation'
def _service(self, obj):
if obj.service.supprime:
<img src="%simg/poste-apercu.png"
title="Aperçu du poste" />
</a>
- <a href="%s">%s</a>
+ <a href="%s">%s [%d]</a>
<br />""" % \
(reverse('poste_apercu', args=(obj.responsable.id,)),
settings.STATIC_URL,
reverse('admin:rh_poste_change', args=(obj.responsable.id,)),
- obj.responsable.nom)
+ obj.responsable.nom,
+ obj.responsable.id)
except:
responsable = ''
_responsable.short_description = 'Responsable'
_responsable.allow_tags = True
- def _implantation(self, poste):
- return poste.implantation.nom
- _implantation.short_description = 'Implantation'
- _implantation.admin_order_field = 'implantation'
+ def _date_debut(self, obj):
+ return date_format(obj.date_debut)
+ _date_debut.short_description = u'Début'
+ _date_debut.admin_order_field = 'date_debut'
- def _nom(self, poste):
- return """<a href="%s">%s</a>""" % \
- (reverse('admin:rh_poste_change', args=(poste.id,)),
- poste.nom)
- _nom.allow_tags = True
- _nom.short_description = u'Poste'
- _nom.admin_order_field = 'nom'
+ def _date_fin(self, obj):
+ return date_format(obj.date_fin)
+ _date_fin.short_description = u'Fin'
+ _date_fin.admin_order_field = 'date_fin'
def _date_modification(self, obj):
return date(obj.date_modification)
_date_modification.short_description = u'date modification'
_date_modification.admin_order_field = 'date_modification'
- def _occupe_par(self, obj):
- """Formatte la méthode Poste.occupe_par() pour l'admin"""
- output = u"Vacant"
- if obj.date_fin is not None and obj.date_fin < datetime.date.today():
- return u"s/o"
- employes = obj.occupe_par()
- if employes:
- l = []
- for e in employes:
- link = u"""<a href='%s'
- title='Aperçu de l\'employé'
- onclick='return showAddAnotherPopup(this)'>
- <img src='%simg/employe-apercu.png' />
- </a>
- <a href='%s'>%s</a>""" % \
- (reverse('employe_apercu', args=(e.id,)),
- settings.STATIC_URL,
- reverse('admin:rh_employe_change', args=(e.id,)),
- e)
- l.append(link)
- output = "\n<br />".join(l)
- return output
- _occupe_par.allow_tags = True
- _occupe_par.short_description = "Occupé par"
+ def _dae(self, poste):
+ apercu_link = ""
+ postes_dae = poste.postes_dae.all()
+ if len(postes_dae) > 0:
+ poste_dae = postes_dae[0]
+ apercu_link = \
+ u'<a title="Aperçu du dossier" href="%s" ' \
+ u'onclick="return showAddAnotherPopup(this);">' \
+ u'<img src="%simg/loupe.png" /></a>' % (reverse(
+ 'poste_consulter', args=("dae-%s" % poste_dae.id,)
+ ), settings.STATIC_URL)
+ return apercu_link
+ _dae.allow_tags = True
+ _dae.short_description = u"DAE"
def save_formset(self, request, form, formset, change):
instances = formset.save(commit=False)
@login_required
@drh_or_admin_required
+def rapports_employes_sans_contrat(request):
+ """
+ Employé sans contrat = a un Dossier qui n'a pas de Contrat associé
+ Employé avec contrat échu = a un Dossier avec un Contrat se terminant hier
+ au plus tard... (aujourd'hui = ok, pas date de fin = illimité donc ok)
+ """
+ lookup_params = get_lookup_params(request)
+
+ # contrats échus
+ contrats_echus = rh.Contrat.objects.filter(
+ date_fin__lt=date.today()
+ ).filter(
+ **lookup_params
+ )
+
+ # dossiers en cours sans contrat ou contrats échus
+ dossiers = rh.Dossier.objects.filter(
+ Q(date_debut=None) | Q(date_debut__lte=date.today()),
+ ).filter(
+ Q(date_fin=None) | Q(date_fin__gte=date.today()),
+ ).exclude(
+ date_debut__gt=date.today()
+ ).filter(
+ # sans contrat | contrat échu
+ Q(rh_contrats=None) | Q(rh_contrats__in=contrats_echus)
+ ).distinct()
+
+ # employés sans contrat ou contrats échus
+ employes = rh.Employe.objects.filter(rh_dossiers__in=dossiers) \
+ .distinct().count()
+
+ # tri
+ if 'o' in request.GET:
+ dossiers = dossiers.order_by(
+ ('-' if request.GET.get('ot') == "desc" else '') + request.GET['o']
+ )
+
+ # affichage
+ headers = [
+ ("employe__id", u"#"),
+ ("employe__nom", u"Employé"),
+ ("dossier", u"Dossier : Poste"),
+ ("rh_contrats__type_contrat", u"Contrat"),
+ ("rh_contrats__date_debut", u"Début contrat"),
+ ("rh_contrats__date_fin", u"Fin contrat"),
+ ("statut_residence", u"Statut"),
+ ("poste__implantation__region__code", u"Région"),
+ ("poste__implantation__nom", u"Implantation"),
+ ]
+ h = SortHeaders(
+ request, headers, order_field_type="ot", order_field="o",
+ not_sortable=('dossier',)
+ )
+
+ c = {
+ 'title': u'Rapport des employés sans contrat ou contrat échu',
+ 'employes': employes,
+ 'dossiers': dossiers,
+ 'headers': list(h.headers()),
+ }
+
+ return render(request, 'rh/rapports/employes_sans_contrat.html', c)
+
+
+@login_required
+@drh_or_admin_required
def rapports_masse_salariale(request):
class RechercheTemporelle(forms.Form):
@login_required
@drh_or_admin_required
-def rapports_employes_sans_contrat(request):
- lookup_params = get_lookup_params(request)
-
- # contrats échus
- contrats_echus = rh.Contrat.objects.filter(
- date_fin__lt=date.today()
- ).filter(
- **lookup_params
- )
-
- # dossiers en cours sans contrat
- dossiers_sans_contrat = rh.Dossier.objects.filter(
- Q(date_fin=None) | Q(date_fin__gt=date.today()),
- ).exclude(
- date_debut__gt=date.today()
- ).filter(
- rh_contrats__in=contrats_echus
- )
-
- # employés sans contrat
- employes = rh.Employe.objects.filter(
- rh_dossiers__in=dossiers_sans_contrat
- ).distinct()
- if 'o' in request.GET:
- employes = employes.order_by(
- ('-' if request.GET.get('ot') == "desc" else '') + request.GET['o']
- )
-
- # affichage
- headers = [
- ("id", u"#"),
- ("nom", u"Employé"),
- ("dossier", u"Dossier : Poste"),
- ("dossier_date_debut", u"Début dossier"),
- ("dossier_date_fin", u"Fin dossier"),
- ]
- h = SortHeaders(
- request, headers, order_field_type="ot", order_field="o",
- not_sortable=('dossier','dossier_date_debut','dossier_date_fin',)
- )
-
- c = {
- 'title': u'Rapport des employés sans contrat',
- 'employes': employes,
- 'dossiers_sans_contrat':dossiers_sans_contrat,
- 'headers': list(h.headers()),
- }
-
- return render(request, 'rh/rapports/employes_sans_contrat.html', c)
-
-
-@login_required
-@drh_or_admin_required
def rapports_postes_modelisation(request):
c = {}
data = []