|
@@ -57,48 +57,49 @@ class PaymentInline(GenericTabularInline):
|
|
|
|
|
|
### Filters
|
|
|
|
|
|
-#class PaymentTypeFilter(admin.SimpleListFilter):
|
|
|
-# title = 'type de paiement'
|
|
|
-# parameter_name = 'type'
|
|
|
-#
|
|
|
-# def lookups(self, request, model_admin):
|
|
|
-# choices = [
|
|
|
-# ('membership', 'Cotisation'),
|
|
|
-# ('service', 'Service'),
|
|
|
-# ]
|
|
|
-# service_types = ServiceType.objects.all()
|
|
|
-# if not (request.user.is_superuser or request.user.has_perm('banking.validate_payment')):
|
|
|
-# service_types = service_types.filter(group__in=request.user.groups.all())
|
|
|
-# for stype in service_types:
|
|
|
-# choices.append((stype.pk, 'Service (%s)' % stype.name))
|
|
|
-# return choices
|
|
|
-#
|
|
|
-# def queryset(self, request, queryset):
|
|
|
-# if self.value() == 'membership':
|
|
|
-# return queryset.filter(reason_type__app_label='adhesions',
|
|
|
-# reason_type__model='adherent')
|
|
|
-# if self.value() == 'service':
|
|
|
-# return queryset.filter(reason_type__app_label='services',
|
|
|
-# reason_type__model='service')
|
|
|
-# try:
|
|
|
-# service_type = ServiceType.objects.get(pk=int(self.value()))
|
|
|
-# except (ValueError, TypeError, ServiceType.DoesNotExist,):
|
|
|
-# return queryset
|
|
|
-# else:
|
|
|
-# return queryset.filter(service__service_type=service_type)
|
|
|
-#
|
|
|
-#
|
|
|
+class PaymentTypeFilter(admin.SimpleListFilter):
|
|
|
+ title = 'type de paiement'
|
|
|
+ parameter_name = 'type'
|
|
|
+
|
|
|
+ def lookups(self, request, model_admin):
|
|
|
+ choices = [
|
|
|
+ ('membership', 'Cotisation'),
|
|
|
+ ('service', 'Service'),
|
|
|
+ ]
|
|
|
+ service_types = ServiceType.objects.all()
|
|
|
+ if not (request.user.is_superuser or request.user.has_perm('banking.validate_payment')):
|
|
|
+ service_types = service_types.filter(group__in=request.user.groups.all())
|
|
|
+ for stype in service_types:
|
|
|
+ choices.append((stype.pk, 'Service (%s)' % stype.name))
|
|
|
+ return choices
|
|
|
+
|
|
|
+ def queryset(self, request, queryset):
|
|
|
+ if self.value() == 'membership':
|
|
|
+ return queryset.filter(reason_type__app_label='adhesions',
|
|
|
+ reason_type__model='adhesion')
|
|
|
+ if self.value() == 'service':
|
|
|
+ return queryset.filter(reason_type__app_label='services',
|
|
|
+ reason_type__model='service')
|
|
|
+ try:
|
|
|
+ service_type = ServiceType.objects.get(pk=int(self.value()))
|
|
|
+ except (ValueError, TypeError, ServiceType.DoesNotExist,):
|
|
|
+ return queryset
|
|
|
+ else:
|
|
|
+ return queryset.filter(service__service_type=service_type)
|
|
|
+
|
|
|
+
|
|
|
#### Actions
|
|
|
#
|
|
|
#def validate_payment(payment, request, queryset):
|
|
|
# queryset.update(validated=True)
|
|
|
-#
|
|
|
-#
|
|
|
-#### ModelAdmin
|
|
|
-#
|
|
|
-#class PaymentAdmin(admin.ModelAdmin):
|
|
|
+
|
|
|
+
|
|
|
+### ModelAdmin
|
|
|
+
|
|
|
+class PaymentAdmin(admin.ModelAdmin):
|
|
|
+ list_display = ('id', 'type_verbose', 'get_adhesion', 'amount', 'period', 'start_display', 'end_display',)
|
|
|
# #list_display_links = None
|
|
|
-# list_filter = (PaymentTypeFilter, 'payment_method', 'validated',)
|
|
|
+ list_filter = (PaymentTypeFilter, 'payment_method', 'validated',)
|
|
|
#
|
|
|
# def get_list_display(self, request):
|
|
|
# list_display = ()
|
|
@@ -114,13 +115,13 @@ class PaymentInline(GenericTabularInline):
|
|
|
# # list_display += ('change_pending',)
|
|
|
# return list_display
|
|
|
#
|
|
|
-# def start_display(self, obj):
|
|
|
-# return obj.start
|
|
|
-# start_display.short_description = 'Début'
|
|
|
-#
|
|
|
-# def end_display(self, obj):
|
|
|
-# return obj.end
|
|
|
-# end_display.short_description = 'Fin'
|
|
|
+ def start_display(self, obj):
|
|
|
+ return obj.start
|
|
|
+ start_display.short_description = 'Début'
|
|
|
+
|
|
|
+ def end_display(self, obj):
|
|
|
+ return obj.end
|
|
|
+ end_display.short_description = 'Fin'
|
|
|
#
|
|
|
# def validated_display(self, obj):
|
|
|
# return obj.validated
|
|
@@ -166,6 +167,6 @@ class PaymentInline(GenericTabularInline):
|
|
|
# if obj and not request.user.has_perm('banking.validate_payment'):
|
|
|
# return not obj.validated
|
|
|
# return False
|
|
|
-#
|
|
|
-#
|
|
|
-#admin.site.register(Payment, PaymentAdmin)
|
|
|
+
|
|
|
+
|
|
|
+admin.site.register(Payment, PaymentAdmin)
|