From b0cf30b850eadf179744bc3c233190501b4f9a0b Mon Sep 17 00:00:00 2001 From: Eric Mc Sween Date: Fri, 21 Sep 2012 10:57:17 -0400 Subject: [PATCH] =?utf8?q?[#3165]=20Remplac=C3=A9=20les=20filtres=20et=20pro?= =?utf8?q?tection=20par=20r=C3=A9gion=20pour=20des=20filtres=20et=20protecti?= =?utf8?q?ons=20par=20zone=20administrative.?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- project/dae/catalogues.py | 13 ++--- project/dae/forms.py | 25 +++------ project/dae/managers.py | 3 +- project/dae/templates/dae/embauche-row.html | 2 +- .../dae/templates/dae/embauches_finalisees.html | 4 +- project/dae/templates/dae/poste-row.html | 2 +- project/dae/templatetags/dae.py | 8 --- project/dae/views.py | 6 +- project/decorators.py | 6 +- project/permissions.py | 4 +- project/rh/admin.py | 59 ++++++++++---------- project/rh/catalogues.py | 4 +- project/rh/forms.py | 16 ++++-- project/rh/managers.py | 13 +++-- project/rh/models.py | 43 +++++++------- project/rh/ods.py | 4 +- project/rh/templates/rh/include/dossier.html | 2 +- project/rh/templates/rh/rapports/contrats.html | 4 +- .../rh/rapports/employes_sans_contrat.html | 4 +- .../rh/templates/rh/rapports/masse_salariale.html | 2 +- project/rh/templatetags/rapports.py | 49 +++++++++++----- project/rh/views.py | 37 +++++++----- 22 files changed, 167 insertions(+), 143 deletions(-) diff --git a/project/dae/catalogues.py b/project/dae/catalogues.py index 3ca3d7e..ba2d0e3 100644 --- a/project/dae/catalogues.py +++ b/project/dae/catalogues.py @@ -72,12 +72,10 @@ class Dossier(object): Q(employe__nom__icontains=q) | \ Q(employe__prenom__icontains=q) - if groups.is_user_dans_services_centraux(request.user): - q_place = Q(**{prefixe_implantation: employe.implantation}) - else: - q_place = Q(**{ - prefixe_implantation + '__region': employe.implantation.region - }) + q_place = Q(**{ + prefixe_implantation + '__zone_administrative': + employe.implantation.zone_administrative + }) user_groupes = [g.name for g in request.user.groups.all()] if groups.DRH_NIVEAU_1 in user_groupes: @@ -119,7 +117,8 @@ class Poste(object): q_place = Q(**{prefixe_implantation: employe.implantation}) else: q_place = Q(**{ - prefixe_implantation + '__region': employe.implantation.region + prefixe_implantation + '__zone_administrative': + employe.implantation.zone_administrative }) user_groupes = [g.name for g in request.user.groups.all()] diff --git a/project/dae/forms.py b/project/dae/forms.py index 28de814..e2007a8 100644 --- a/project/dae/forms.py +++ b/project/dae/forms.py @@ -84,12 +84,7 @@ class BaseInlineFormSetWithInitial(BaseInlineFormSet): def _implantation_choices(obj, request): # TRAITEMENT NORMAL employe = groups.get_employe_from_user(request.user) - # SERVICE - if groups.is_user_dans_services_centraux(request.user): - q = Q(**{'id': employe.implantation_id}) - # REGION - else: - q = Q(**{'region': employe.implantation.region}) + q = Q(**{'zone_administrative': employe.implantation.zone_administrative}) # TRAITEMENT DRH user_groupes = [g.name for g in request.user.groups.all()] @@ -102,18 +97,16 @@ def _implantation_choices(obj, request): def _employe_choices(obj, request): # TRAITEMENT NORMAL employe = groups.get_employe_from_user(request.user) - # SERVICE - if groups.is_user_dans_services_centraux(request.user): - q_dae_region_service = Q(poste__implantation=employe.implantation) - q_rh_region_service = Q(poste__implantation=employe.implantation) - # REGION - else: - q_dae_region_service = Q( - poste__implantation__region=employe.implantation.region + q_dae_region_service = Q( + poste__implantation__zone_administrative=( + employe.implantation.zone_administrative ) - q_rh_region_service = Q( - poste__implantation__region=employe.implantation.region + ) + q_rh_region_service = Q( + poste__implantation__zone_administrative=( + employe.implantation.zone_administrative ) + ) # TRAITEMENT DRH user_groupes = [g.name for g in request.user.groups.all()] if groups.DRH_NIVEAU_1 in user_groupes: diff --git a/project/dae/managers.py b/project/dae/managers.py index ca64649..f4bc09e 100644 --- a/project/dae/managers.py +++ b/project/dae/managers.py @@ -32,7 +32,8 @@ class TodoManagerMixin(object): groups.DRH_NIVEAU_2, ): q2 &= Q(**{ - self.prefixe_implantation: employe.implantation.region + self.prefixe_implantation: + employe.implantation.zone_administrative }) q |= q2 diff --git a/project/dae/templates/dae/embauche-row.html b/project/dae/templates/dae/embauche-row.html index dc4584b..6027968 100644 --- a/project/dae/templates/dae/embauche-row.html +++ b/project/dae/templates/dae/embauche-row.html @@ -1,6 +1,6 @@ {% load dae %} - {{ dossier.poste.implantation|region_ou_service }} + {{ dossier.poste.implantation.zone_administrative }} {{ dossier.poste.implantation }} {{ dossier.poste.nom }} {{ dossier.employe }} diff --git a/project/dae/templates/dae/embauches_finalisees.html b/project/dae/templates/dae/embauches_finalisees.html index 90bf4c7..af4ec45 100644 --- a/project/dae/templates/dae/embauches_finalisees.html +++ b/project/dae/templates/dae/embauches_finalisees.html @@ -31,7 +31,7 @@ - {% sort_header "region" "Région" %} + {% sort_header "zone_administrative" "Zone administrative" %} {% sort_header "implantation" "Implantation" %} {% sort_header "poste" "Poste" %} {% sort_header "personne" "Personne" %} @@ -46,7 +46,7 @@ {% for dossier in embauches.object_list %} - {{ dossier.poste.implantation|region_ou_service }} + {{ dossier.poste.implantation.zone_administrative }} {{ dossier.poste.implantation }} {{ dossier.poste.nom }} {{ dossier.employe }} diff --git a/project/dae/templates/dae/poste-row.html b/project/dae/templates/dae/poste-row.html index 8118def..40a82aa 100644 --- a/project/dae/templates/dae/poste-row.html +++ b/project/dae/templates/dae/poste-row.html @@ -1,6 +1,6 @@ {% load dae %} - {{ poste.implantation|region_ou_service }} + {{ poste.implantation.zone_administrative }} {{ poste.implantation }} {{ poste.nom }} {{ poste.date_creation|date:"d-m-Y" }} diff --git a/project/dae/templatetags/dae.py b/project/dae/templatetags/dae.py index 2b69560..3fbe768 100644 --- a/project/dae/templatetags/dae.py +++ b/project/dae/templatetags/dae.py @@ -46,14 +46,6 @@ def est_editable(obj, user): return False @register.filter -def region_ou_service(implantation): - if implantation.id == 15: - return u"Services centraux de Montréal (SCM)" - if implantation.id == 19: - return u"Services centraux de Paris (SCP)" - return implantation.region - -@register.filter def basename(path): return os.path.basename(path) diff --git a/project/dae/views.py b/project/dae/views.py index 33838d4..08adf19 100644 --- a/project/dae/views.py +++ b/project/dae/views.py @@ -538,8 +538,8 @@ def embauches_finalisees(request): importees = search_form.cleaned_data.get('importees') if q: criteria = [ - Q(poste__implantation__region__nom__icontains=word) | - Q(poste__implantation__region__code=word) | + Q(poste__implantation__zone_administrative__nom__icontains=word) | + Q(poste__implantation__zone_administrative__code=word) | Q(poste__implantation__nom__icontains=word) | Q(poste__nom__icontains=word) | Q(employe__nom__icontains=word) | @@ -561,7 +561,7 @@ def embauches_finalisees(request): dir = '' if tri == 'region': embauches = embauches.order_by( - dir + 'poste__implantation__region__nom' + dir + 'poste__implantation__zone_administrative__nom' ) elif tri == 'implantation': embauches = embauches.order_by(dir + 'poste__implantation__nom') diff --git a/project/decorators.py b/project/decorators.py index d9d8ce9..c386666 100644 --- a/project/decorators.py +++ b/project/decorators.py @@ -69,7 +69,8 @@ def region_protected(model): groups.DIRECTEUR_DE_BUREAU in user_groups: employe = groups.get_employe_from_user(request.user) q = Q(**{ - model.prefix_implantation: employe.implantation.region + model.prefix_implantation: + employe.implantation.zone_administrative }) qs = model.objects.filter(q) if int(id) in [o.id for o in qs]: @@ -77,7 +78,8 @@ def region_protected(model): return redirect_interdiction(request) return wrapped return wrapper - + + def in_one_of_group(groups): """ Test si le user appartient au moins 1 des ces groupes diff --git a/project/permissions.py b/project/permissions.py index 213b55c..09db52e 100644 --- a/project/permissions.py +++ b/project/permissions.py @@ -38,11 +38,11 @@ def obj_in_region_user(user, obj): if isinstance(obj, rh.Dossier): return True if isinstance(obj, rh.Poste): - return obj.implantation.region == region_user + return obj.implantation.zone_administrative == region_user return False def get_region_user(user): # gère actuellement qu'une seule région par user employe = get_employe_from_user(user) - region_user = employe.implantation.region + region_user = employe.implantation.zone_administrative return region_user diff --git a/project/rh/admin.py b/project/rh/admin.py index 71679a8..64a26d9 100644 --- a/project/rh/admin.py +++ b/project/rh/admin.py @@ -40,6 +40,7 @@ class BaseAdmin(admin.ModelAdmin): 'jquery-autocomplete/jquery.autocomplete.min.js', ) + # Admin pour reversion class ArchivableAdmin(admin.ModelAdmin): @@ -365,7 +366,7 @@ class DossierAdmin(DateRangeMixin, ProtectRegionMixin, reversion.VersionAdmin, '_nom', '_employe', '_poste', - '_region', + '_zone_administrative', '_implantation', '_date_debut', '_date_fin', @@ -374,7 +375,7 @@ class DossierAdmin(DateRangeMixin, ProtectRegionMixin, reversion.VersionAdmin, ) list_display_links = ('_nom',) list_filter = ( - 'poste__implantation__region', + 'poste__implantation__zone_administrative', 'poste__implantation', 'poste__type_poste__categorie_emploi', 'poste__type_poste', @@ -415,7 +416,7 @@ class DossierAdmin(DateRangeMixin, ProtectRegionMixin, reversion.VersionAdmin, def lookup_allowed(self, key, value): if key in ( 'employe__nom__istartswith', - 'poste__implantation__region__id__exact', + 'poste__implantation__zone_administrative__code__exact', 'poste__implantation__id__exact', 'poste__type_poste__id__exact', 'poste__type_poste__categorie_emploi__id__exact', @@ -481,10 +482,10 @@ class DossierAdmin(DateRangeMixin, ProtectRegionMixin, reversion.VersionAdmin, _poste.short_description = u'Poste' _poste.admin_order_field = 'poste__nom' - def _region(self, obj): - return obj.poste.implantation.region.code - _region.short_description = u"Région" - _region.admin_order_field = 'poste__implantation__region__code' + def _zone_administrative(self, obj): + return obj.poste.implantation.zone_administrative.code + _zone_administrative.short_description = u"Zone administrative" + _zone_administrative.admin_order_field = 'poste__implantation__zone_administrative__code' def _implantation(self, obj): return obj.poste.implantation.nom @@ -548,14 +549,14 @@ class EmployeAdminBase(DateRangeMixin, ProtectRegionMixin, form = EmployeAdminForm list_display = ( '_id', '_apercu', '_nom', '_dossiers_postes', - #'_region', + #'_zone_administrative', #'_implantation', 'date_entree', 'derniere_modification' ) list_display_links = ('_nom',) list_filter = ( - 'rh_dossiers__poste__implantation__region', + 'rh_dossiers__poste__implantation__zone_administrative', 'rh_dossiers__poste__implantation', 'nb_postes' ) inlines = ( @@ -608,14 +609,14 @@ class EmployeAdminBase(DateRangeMixin, ProtectRegionMixin, _nom.short_description = u"Employé" _nom.admin_order_field = "nom" - def _region(self, obj): + def _zone_administrative(self, obj): try: d = rh.Dossier.objects.filter(employe=obj.id, principal=True)[0] - region = d.poste.implantation.region.code + zone = d.poste.implantation.zone_administrative.code except: - region = None - return region - _region.short_description = u"Région" + zone = None + return zone + _zone_administrative.short_description = u"Zone administrative" def _implantation(self, obj): try: @@ -793,8 +794,8 @@ class PosteAdmin(DateRangeMixin, ProtectRegionMixin, reversion.VersionAdmin, 'id', 'nom', 'implantation__nom', - 'implantation__region__code', - 'implantation__region__nom', + 'implantation__zone_administrative__code', + 'implantation__zone_administrative__nom', 'rh_dossiers__employe__id', 'rh_dossiers__employe__nom', 'rh_dossiers__employe__prenom', @@ -805,7 +806,7 @@ class PosteAdmin(DateRangeMixin, ProtectRegionMixin, reversion.VersionAdmin, '_dae' ) list_filter = ( - 'implantation__region', + 'implantation__zone_administrative', 'implantation', 'service', 'type_poste', @@ -871,7 +872,7 @@ class PosteAdmin(DateRangeMixin, ProtectRegionMixin, reversion.VersionAdmin, def lookup_allowed(self, key, value): return key in ( 'date_debut__gte', 'date_debut__isnull', 'date_fin__lte', - 'date_fin__isnull', 'implantation__region__id__exact', + 'date_fin__isnull', 'implantation__zone_administrative__code__exact', 'implantation__id__exact', 'type_poste__id__exact', 'type_poste__categorie_emploi__id__exact', 'service__id__exact', 'service__isnull', 'vacant__exact', 'vacant__isnull', @@ -927,10 +928,10 @@ class PosteAdmin(DateRangeMixin, ProtectRegionMixin, reversion.VersionAdmin, _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 _zone_administrative(self, poste): + return poste.implantation.zone_administrative.code + _zone_administrative.short_description = 'Zone administrative' + _zone_administrative.admin_order_field = 'implantation__zone_administrative__code' def _implantation(self, poste): return poste.implantation.nom @@ -1027,8 +1028,8 @@ class ResponsableImplantationAdmin(BaseAdmin): actions = None fields = ('nom', ) inlines = (ResponsableInline, ) - list_filter = ('region', 'statut', ) - list_display = ('_region', '_nom', 'statut', '_responsable', ) + list_filter = ('zone_administrative', 'statut', ) + list_display = ('_zone_administrative', '_nom', 'statut', '_responsable', ) list_display_links = ('_nom',) list_per_page = 500 readonly_fields = ('nom', ) @@ -1041,10 +1042,10 @@ class ResponsableImplantationAdmin(BaseAdmin): ordering = ('nom',) inlines = (ResponsableInline, ) - def _region(self, obj): - return obj.region.code - _region.short_description = u"Région" - _region.admin_order_field = 'region__code' + def _zone_administrative(self, obj): + return obj.zone_administrative.code + _zone_administrative.short_description = u"Zone administrative" + _zone_administrative.admin_order_field = 'zone_administrative__code' def _nom(self, obj): return obj.nom @@ -1207,7 +1208,7 @@ class ValeurPointAdmin(reversion.VersionAdmin, DerniereModificationAdmin, '_devise_code', '_devise_nom', 'annee', 'implantation', 'valeur', 'derniere_modification' ) - list_filter = ('annee', 'devise', 'implantation__region', ) + list_filter = ('annee', 'devise', 'implantation__zone_administrative', ) fieldsets = ( (None, {'fields': ('valeur', 'devise', 'implantation', 'annee')}), ) diff --git a/project/rh/catalogues.py b/project/rh/catalogues.py index c039911..96d745e 100644 --- a/project/rh/catalogues.py +++ b/project/rh/catalogues.py @@ -33,12 +33,12 @@ class Implantation(object): def get_query(self, q, request): implantations = ref.Implantation.objects.filter( Q(nom__icontains=q) | Q(nom_court__icontains=q) | - Q(nom_long__icontains=q) | Q(region__nom__icontains=q) + Q(nom_long__icontains=q) | Q(zone_administrative__nom__icontains=q) ) if user_gere_obj_de_sa_region(request.user): employe = get_employe_from_user(request.user) implantations = implantations.filter( - region=employe.implantation.region + zone_administrative=employe.implantation.zone_administrative ) return implantations diff --git a/project/rh/forms.py b/project/rh/forms.py index 272fecb..6333ffe 100644 --- a/project/rh/forms.py +++ b/project/rh/forms.py @@ -89,8 +89,9 @@ class ResponsableInlineForm(forms.ModelForm): class MasseSalarialeForm(forms.Form): - region = forms.ModelChoiceField( - label=u'Région', queryset=ref.Region.objects.all(), required=False + zone_administrative = forms.ModelChoiceField( + label=u'Région', queryset=ref.ZoneAdministrative.objects.all(), + required=False ) implantation = forms.ModelChoiceField( label=u'Implantation', queryset=ref.Implantation.objects.all(), @@ -112,10 +113,13 @@ class MasseSalarialeForm(forms.Form): ) if is_user_dans_region(user): employe = get_employe_from_user(user) - self.fields['region'].queryset = ref.Region.objects.filter( - id=employe.implantation.region.id - ) + self.fields['zone_administrative'].queryset = \ + ref.ZoneAdministrative.objects.filter( + code=employe.implantation.zone_administrative.code + ) self.fields['implantation'].queryset = \ ref.Implantation.objects.filter( - region=employe.implantation.region + zone_administrative=( + employe.implantation.zone_administrative + ) ) diff --git a/project/rh/managers.py b/project/rh/managers.py index a4bc601..bee3f71 100644 --- a/project/rh/managers.py +++ b/project/rh/managers.py @@ -27,7 +27,10 @@ class SecurityManager(models.Manager): # TRAITEMENT NORMAL ############################################ # REGION - q = Q(**{self.prefixe_implantation: employe.implantation.region}) + q = Q(**{ + self.prefixe_implantation: + employe.implantation.zone_administrative + }) # SERVICE if self.prefixe_service \ @@ -98,7 +101,7 @@ class PosteQuerySet(ActifsQuerySet): class PosteManager(SecurityManager): prefixe_service = "service" - prefixe_implantation = "implantation__region" + prefixe_implantation = "implantation__zone_administrative" def get_query_set(self): return PosteQuerySet(self.model).select_related('type_poste') @@ -116,7 +119,7 @@ class DossierQuerySet(ActifsQuerySet): class DossierManager(SecurityManager): prefixe_service = "poste__service" - prefixe_implantation = "poste__implantation__region" + prefixe_implantation = "poste__implantation__zone_administrative" def get_query_set(self): return DossierQuerySet(self.model) \ @@ -176,12 +179,12 @@ class EmployeManager(models.Manager): class PosteComparaisonManager(SecurityManager): use_for_related_fields = True - prefixe_implantation = "implantation__region" + prefixe_implantation = "implantation__zone_administrative" class DossierComparaisonManager(SecurityManager): use_for_related_fields = True - prefixe_implantation = "implantation__region" + prefixe_implantation = "implantation__zone_administrative" class DeviseManager(models.Manager): diff --git a/project/rh/models.py b/project/rh/models.py index daa714f..ada39b5 100644 --- a/project/rh/models.py +++ b/project/rh/models.py @@ -337,10 +337,10 @@ class Poste_( DateActiviteMixin, models.Model,): ) return representation - prefix_implantation = "implantation__region" + prefix_implantation = "implantation__zone_administrative" - def get_regions(self): - return [self.implantation.region] + def get_zones_administratives(self): + return [self.implantation.zone_administrative] def get_devise(self): vp = ValeurPoint.objects.filter( @@ -625,13 +625,14 @@ class Employe(models.Model): pass return poste - prefix_implantation = "rh_dossiers__poste__implantation__region" + prefix_implantation = \ + "rh_dossiers__poste__implantation__zone_administrative" - def get_regions(self): - regions = [] - for d in self.dossiers.all(): - regions.append(d.poste.implantation.region) - return regions + def get_zones_administratives(self): + return [ + d.poste.implantation.zone_administrative + for d in self.dossiers.all() + ] reversion.register(Employe, format='xml', follow=[ 'pieces', 'commentaires', 'ayantdroits' @@ -722,13 +723,14 @@ class AyantDroit(models.Model): def __unicode__(self): return u'%s %s' % (self.nom.upper(), self.prenom, ) - prefix_implantation = "employe__dossiers__poste__implantation__region" + prefix_implantation = \ + "employe__dossiers__poste__implantation__zone_administrative" - def get_regions(self): - regions = [] - for d in self.employe.dossiers.all(): - regions.append(d.poste.implantation.region) - return regions + def get_zones_administratives(self): + return [ + d.poste.implantation.zone_administrative + for d in self.employe.dossiers.all() + ] reversion.register(AyantDroit, format='xml', follow=['commentaires']) @@ -840,10 +842,10 @@ class Dossier_(DateActiviteMixin, models.Model, DevisableMixin,): poste = self.poste.nom_feminin return u'%s - %s' % (self.employe, poste) - prefix_implantation = "poste__implantation__region" + prefix_implantation = "poste__implantation__zone_administrative" - def get_regions(self): - return [self.poste.implantation.region] + def get_zones_administratives(self): + return [self.poste.implantation.zone_administrative] def remunerations(self): key = "%s_remunerations" % self._meta.app_label @@ -1431,11 +1433,6 @@ class OrganismeBstg(models.Model): def __unicode__(self): return u'%s (%s)' % (self.nom, self.get_type_display()) - prefix_implantation = "pays__region" - - def get_regions(self): - return [self.pays.region] - reversion.register(OrganismeBstg, format='xml') diff --git a/project/rh/ods.py b/project/rh/ods.py index ca731a9..af83eed 100644 --- a/project/rh/ods.py +++ b/project/rh/ods.py @@ -90,7 +90,7 @@ def masse_salariale(lignes, annee, titres_traitements, titres_indemnites, # GESTION de l'affichage des VACANTS if 'dossier' not in ligne.keys(): row.add_cells([ - ligne['poste'].implantation.region.code, + ligne['poste'].implantation.zone_administrative.code, ligne['poste'].implantation.adresse_physique_pays.nom, ligne['poste'].implantation.nom_court ]) @@ -158,7 +158,7 @@ def masse_salariale(lignes, annee, titres_traitements, titres_indemnites, continue row.add_cells([ - ligne['poste'].implantation.region.code, + ligne['poste'].implantation.zone_administrative.code, ligne['poste'].implantation.adresse_physique_pays.nom, ligne['poste'].implantation.nom_court ]) diff --git a/project/rh/templates/rh/include/dossier.html b/project/rh/templates/rh/include/dossier.html index de978f5..206e1d6 100644 --- a/project/rh/templates/rh/include/dossier.html +++ b/project/rh/templates/rh/include/dossier.html @@ -1,6 +1,6 @@

Localisation

- {% include "rh/form-row.html" with label="Région" value=dossier.poste.implantation.region %} + {% include "rh/form-row.html" with label="Zone administrative" value=dossier.poste.implantation.zone_administrative %} {% include "rh/form-row.html" with label="Implantation" value=dossier.poste.implantation %}
diff --git a/project/rh/templates/rh/rapports/contrats.html b/project/rh/templates/rh/rapports/contrats.html index 27afccf..19d5f5b 100644 --- a/project/rh/templates/rh/rapports/contrats.html +++ b/project/rh/templates/rh/rapports/contrats.html @@ -25,7 +25,7 @@

{% trans 'Filter' %}

- {% filter_region_contrat %} + {% filter_zone_administrative_contrat %} {% filter_implantation_contrat %} {% filter_type_contrat %} {% filter_echeance_contrat %} @@ -57,7 +57,7 @@ {{ contrat.date_debut }} {{ contrat.date_fin|default:'' }} {{ contrat.dossier.get_statut_residence_display }} - {{ contrat.dossier.poste.implantation.region.nom }} + {{ contrat.dossier.poste.implantation.zone_administrative.nom }} {{ contrat.dossier.poste.implantation.nom }} {% endfor %} diff --git a/project/rh/templates/rh/rapports/employes_sans_contrat.html b/project/rh/templates/rh/rapports/employes_sans_contrat.html index 56af714..ae74f3c 100644 --- a/project/rh/templates/rh/rapports/employes_sans_contrat.html +++ b/project/rh/templates/rh/rapports/employes_sans_contrat.html @@ -17,7 +17,7 @@ {% block contentrapport %}

{% trans 'Filter' %}

- {% filter_region_dossier %} + {% filter_zone_administrative_dossier %} {% filter_implantation_dossier %}
@@ -40,7 +40,7 @@ {{ d.dernier_contrat.date_debut|default_if_none:"" }} {{ d.dernier_contrat.date_fin|default_if_none:"" }} {{ d.get_statut_residence_display }} - {{ d.poste.implantation.region.code }} + {{ d.poste.implantation.zone_administrative.code }} {{ d.poste.implantation.nom }} {% endfor %} diff --git a/project/rh/templates/rh/rapports/masse_salariale.html b/project/rh/templates/rh/rapports/masse_salariale.html index 73c90fa..60a3f33 100644 --- a/project/rh/templates/rh/rapports/masse_salariale.html +++ b/project/rh/templates/rh/rapports/masse_salariale.html @@ -109,7 +109,7 @@ $(document).ready(function() { {% for ligne in lignes %} - {{ ligne.poste.implantation.region.code }} + {{ ligne.poste.implantation.zone_administrative.code }} {{ ligne.poste.implantation.adresse_physique_pays.nom }} {{ ligne.poste.implantation.nom_court }} diff --git a/project/rh/templatetags/rapports.py b/project/rh/templatetags/rapports.py index 7faf777..484326c 100644 --- a/project/rh/templatetags/rapports.py +++ b/project/rh/templatetags/rapports.py @@ -6,7 +6,8 @@ from django.utils.encoding import smart_unicode from django.template import Library from django.utils.http import urlencode -from auf.django.references.models import Implantation, Region +from auf.django.references.models import \ + Implantation, Region, ZoneAdministrative from project import groups @@ -39,6 +40,18 @@ def filter_region(context, prefix=None): @register.inclusion_tag('admin/filter.html', takes_context=True) +def filter_zone_administrative(context, prefix=None): + label = "".join([prefix or "", "implantation__zone_administrative"]) + return { + 'title': u"zone administrative", + 'choices': prepare_choices( + ZoneAdministrative.objects.values_list('code', 'nom'), label, context, + remove=['pays', 'nord_sud'] + ) + } + + +@register.inclusion_tag('admin/filter.html', takes_context=True) def filter_implantation(context, prefix=None): label = "".join([prefix or "", "implantation"]) return { @@ -50,27 +63,35 @@ def filter_implantation(context, prefix=None): @register.inclusion_tag('admin/filter.html', takes_context=True) -def filter_region_contrat(context): +def filter_zone_administrative_contrat(context): request = context['request'] user_groups = [g.name for g in request.user.groups.all()] if groups.CORRESPONDANT_RH in user_groups or\ groups.ADMINISTRATEURS in user_groups or\ groups.DIRECTEUR_DE_BUREAU in user_groups: employe = groups.get_employe_from_user(request.user) - regions = Region.objects.filter(id=employe.implantation.region.id) + zones = ZoneAdministrative.objects.filter( + code=employe.implantation.zone_administrative.code + ) else: - regions = Region.objects.all() - return {'title': u"région", - 'choices': prepare_choices(regions.values_list('id', 'nom'), 'dossier__poste__implantation__region', context, remove=['pays', 'nord_sud'])} + zones = ZoneAdministrative.objects.all() + return { + 'title': u"région", + 'choices': prepare_choices( + zones.values_list('code', 'nom'), + 'dossier__poste__implantation__zone_administrative', + context, remove=['pays', 'nord_sud'] + ) + } @register.inclusion_tag('admin/filter.html', takes_context=True) -def filter_region_dossier(context): +def filter_zone_administrative_dossier(context): return { 'title': u"région", 'choices': prepare_choices( - Region.objects.values_list('id', 'nom'), - 'poste__implantation__region', context, + ZoneAdministrative.objects.values_list('code', 'nom'), + 'poste__implantation__zone_administrative', context, remove=['pays', 'nord_sud'] ) } @@ -95,7 +116,9 @@ def filter_implantation_contrat(context): groups.ADMINISTRATEURS in user_groups or\ groups.DIRECTEUR_DE_BUREAU in user_groups: employe = groups.get_employe_from_user(request.user) - implantations = Implantation.objects.filter(region=employe.implantation.region) + implantations = Implantation.objects.filter( + zone_administrative=employe.implantation.zone_administrative + ) else: implantations = Implantation.objects.all() return {'title': u"implantation", @@ -193,12 +216,12 @@ def filter_a_venir(context): @register.inclusion_tag('admin/filter_select.html', takes_context=True) -def filter_region_remun(context): +def filter_zone_administrative_remun(context): return { 'title': u"région", 'choices': prepare_choices( - Region.objects.values_list('id', 'nom'), - 'dossiers__poste__implantation__region', context, + ZoneAdministrative.objects.values_list('code', 'nom'), + 'dossiers__poste__implantation__zone_administrative', context, remove=['pays', 'nord_sud'] ) } diff --git a/project/rh/views.py b/project/rh/views.py index 59b7e4b..5010814 100644 --- a/project/rh/views.py +++ b/project/rh/views.py @@ -110,7 +110,11 @@ def rapports_contrat(request): groups.ADMINISTRATEURS in user_groups or\ groups.DIRECTEUR_DE_BUREAU in user_groups: employe = get_employe_from_user(request.user) - q = q & Q(dossier__poste__implantation__region=employe.implantation.region) + q = q & Q( + dossier__poste__implantation__zone_administrative=( + employe.implantation.zone_administrative + ) + ) contrats = contrats.filter(q) @@ -130,7 +134,7 @@ def rapports_contrat(request): ("date_debut", u"Début contrat"), ("date_fin", u"Fin contrat"), ("dossier__statut_residence", u"Statut"), - ("dossier__poste__implantation__region", u"Région"), + ("dossier__poste__implantation__zone_administrative", u"Zone administrative"), ("dossier__poste__implantation", u"Implantation"), ] h = SortHeaders( @@ -168,7 +172,8 @@ def rapports_employes_sans_contrat(request): groups.ADMINISTRATEURS in user_groups or\ groups.DIRECTEUR_DE_BUREAU in user_groups: employe = get_employe_from_user(request.user) - lookup_params['poste__implantation__region'] = employe.implantation.region + lookup_params['poste__implantation__zone_administrative'] = \ + employe.implantation.zone_administrative dossiers = rh.Dossier.objects.sans_contrats_ou_echus(**lookup_params) @@ -190,7 +195,7 @@ def rapports_employes_sans_contrat(request): ("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__zone_administrative__code", u"Zone administrative"), ("poste__implantation__nom", u"Implantation"), ] h = SortHeaders( @@ -217,7 +222,7 @@ def rapports_employes_sans_contrat(request): def rapports_masse_salariale(request): form = MasseSalarialeForm(request.user, request.GET) if 'annee' in request.GET and form.is_valid(): - region = form.cleaned_data['region'] + zone_administrative = form.cleaned_data['zone_administrative'] implantation = form.cleaned_data['implantation'] annee = form.cleaned_data['annee'] debut_annee = date(annee, 1, 1) @@ -230,7 +235,7 @@ def rapports_masse_salariale(request): .actifs(annee=annee) \ .select_related( 'poste', 'poste__implantation', - 'poste__implantation__region', + 'poste__implantation__zone_administrative', 'poste__implantation__adresse_physique_pays', 'employe', 'poste__type_poste', 'classement', 'statut', 'organisme_bstg' @@ -251,8 +256,8 @@ def rapports_masse_salariale(request): ) } ) - if region: - dossiers = dossiers.filter(poste__implantation__region=region) + if zone_administrative: + dossiers = dossiers.filter(poste__implantation__zone_administrative=zone_administrative) if implantation: dossiers = dossiers.filter(poste__implantation=implantation) @@ -271,8 +276,8 @@ def rapports_masse_salariale(request): 'taux_change': 'rh_tauxchange.taux' } ) - if region: - remuns = remuns.filter(dossier__poste__implantation__region=region) + if zone_administrative: + remuns = remuns.filter(dossier__poste__implantation__zone_administrative=zone_administrative) if implantation: remuns = remuns.filter(dossier__poste__implantation=implantation) remuns_par_dossier = defaultdict(list) @@ -419,8 +424,8 @@ def rapports_masse_salariale(request): 'taux_change': 'rh_tauxchange.taux' } ) - if region: - postes = postes.filter(implantation__region=region) + if zone_administrative: + postes = postes.filter(implantation__zone_administrative=zone_administrative) if implantation: postes = postes.filter(implantation=implantation) postes = list(postes) @@ -666,8 +671,12 @@ def employe_apercu(request, employe_id): groups.ADMINISTRATEURS in user_groups or\ groups.DIRECTEUR_DE_BUREAU in user_groups: employe_connecte = get_employe_from_user(request.user) - q = Q(employe=employe) & Q(poste__implantation__region=employe_connecte.implantation.region) - + q = Q(employe=employe) & Q( + poste__implantation__zone_administrative=( + employe_connecte.implantation.zone_administrative + ) + ) + dossiers = rh.Dossier.objects.filter(q).order_by('-date_debut') c = { -- 1.7.10.4