From 8c8ffc4f0a594f5469a42b7767625dddbc753b0b Mon Sep 17 00:00:00 2001 From: =?utf8?q?Olivier=20Larchev=C3=AAque?= Date: Fri, 13 Apr 2012 16:14:34 -0400 Subject: [PATCH] responsables implantation --- project/rh/admin.py | 46 +++++++++++++++++++++++++++++++++++++++------- project/rh/models.py | 13 ++++++++++--- 2 files changed, 49 insertions(+), 10 deletions(-) diff --git a/project/rh/admin.py b/project/rh/admin.py index 05123ef..ca4d9eb 100644 --- a/project/rh/admin.py +++ b/project/rh/admin.py @@ -941,13 +941,45 @@ class RemunerationAdmin(admin.ModelAdmin): pass -class ResponsableImplantationAdmin(AUFMetadataAdminMixin, admin.ModelAdmin): - fieldsets = AUFMetadataAdminMixin.fieldsets + ( - (None, { - 'fields': ('employe', 'implantation', ), - }), - ) +class ResponsableInline(admin.TabularInline): + model = rh.ResponsableImplantation + extra = 0 + fk_name = "implantation" +class ResponsableImplantationAdmin(admin.ModelAdmin): + actions = None + list_filter = ('region', 'statut', ) + list_display = ('nom', 'statut', '_responsable', ) + readonly_fields = ('nom', ) + fields = ('nom', ) + inlines = (ResponsableInline, ) + + def _responsable(self, obj): + try: + employe = obj.responsable.employe + dossiers = employe.dossiers_encours() + if len(dossiers) == 0: + return u"%s %s " % ( + employe, u"sans dossier actif") + else: + return employe + except Exception, e: + if obj.statut in (1, 2): # ouverte, ouverture imminente + css = "style='color: red;'" + else: + css = "" + return u"Pas de responsable" % css + _responsable.allow_tags = True + _responsable.short_description = u"Responsable" + + def has_add_permission(self, request=None): + return False + + def has_change_permission(self, request, obj=None): + return in_drh_or_admin(request.user) + + def has_delete_permission(self, request, obj=None): + return False class ServiceAdmin(AUFMetadataAdminMixin, admin.ModelAdmin, ArchiveMixin): list_display = ( @@ -1196,7 +1228,7 @@ admin.site.register(rh.Employe, EmployeAdmin) admin.site.register(rh.FamilleEmploi, FamilleEmploiAdmin) admin.site.register(rh.OrganismeBstg, OrganismeBstgAdmin) admin.site.register(rh.Poste, PosteAdmin) -admin.site.register(rh.ResponsableImplantation, ResponsableImplantationAdmin) +admin.site.register(rh.ResponsableImplantationProxy, ResponsableImplantationAdmin) admin.site.register(rh.Service, ServiceAdmin) admin.site.register(rh.Statut, StatutAdmin) admin.site.register(rh.TauxChange, TauxChangeAdmin) diff --git a/project/rh/models.py b/project/rh/models.py index b621fa4..99d85a5 100644 --- a/project/rh/models.py +++ b/project/rh/models.py @@ -1384,15 +1384,22 @@ class TypeContrat(AUFMetadata): ### AUTRES -class ResponsableImplantation(AUFMetadata): +class ResponsableImplantationProxy(ref.Implantation): + class Meta: + proxy = True + verbose_name = u"Responsable d'implantation" + verbose_name_plural = u"Responsables d'implantation" + + +class ResponsableImplantation(models.Model): """Le responsable d'une implantation. Anciennement géré sur le Dossier du responsable. """ employe = models.ForeignKey('Employe', db_column='employe', related_name='+', null=True, blank=True) - implantation = models.ForeignKey(ref.Implantation, - db_column='implantation', related_name='+', + implantation = models.OneToOneField("ResponsableImplantationProxy", + db_column='implantation', related_name='responsable', unique=True) def __unicode__(self): -- 1.7.10.4