You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
132 lines
3.6 KiB
132 lines
3.6 KiB
# -*- coding: utf-8 -*-
|
|
from django.contrib import admin
|
|
from django.utils import timezone
|
|
from robokassa.models import SuccessNotification
|
|
|
|
from customer import forms
|
|
from customer import models
|
|
|
|
|
|
@admin.register(models.License)
|
|
class LicenseAdmin(admin.ModelAdmin):
|
|
list_display = (
|
|
'user_email',
|
|
'license_owner',
|
|
'term_display',
|
|
'status',
|
|
'order_date',
|
|
'date_from',
|
|
'date_to',
|
|
'balance_days',
|
|
'deleted'
|
|
)
|
|
|
|
list_display_links = list_display
|
|
search_fields = ('company__email',)
|
|
list_filter = ('status', 'term', 'order_date', 'date_from', 'date_to', 'deleted')
|
|
readonly_fields = ('company', 'term', )
|
|
|
|
def user_email(self, obj):
|
|
if obj.company.users.first():
|
|
return obj.company.users.first().email
|
|
else:
|
|
return 'Нет пользователя'
|
|
|
|
user_email.short_description = 'Email пользователя'
|
|
|
|
def term_display(self, obj):
|
|
return obj.get_term()
|
|
|
|
term_display.short_description = 'Срок лицензии'
|
|
|
|
def license_owner(self, obj):
|
|
return obj.get_company()
|
|
|
|
license_owner.short_description = 'Компания'
|
|
|
|
def balance_days(self, obj):
|
|
if obj.date_to:
|
|
delta = obj.date_to - timezone.now().date()
|
|
return delta.days
|
|
else:
|
|
return '-'
|
|
|
|
balance_days.short_description = 'Остаток дней'
|
|
|
|
|
|
class UserProfileAdmin(admin.ModelAdmin):
|
|
search_fields = ('inn', 'email_admin', 'name')
|
|
list_display = ('email_admin', 'profile_type', 'name', 'inn', 'active')
|
|
list_display_links = list_display
|
|
form = forms.UserProfileAdminForm
|
|
|
|
list_filter = (
|
|
'profile_type',
|
|
'active'
|
|
)
|
|
|
|
def email_admin(self, obj):
|
|
return obj.get_email()
|
|
|
|
email_admin.short_description = 'Email пользователя'
|
|
email_admin.admin_order_field = 'users__email'
|
|
|
|
|
|
class BankAccountAdmin(admin.ModelAdmin):
|
|
class Media:
|
|
css = {'all': ('css/custom_admin.css',)}
|
|
|
|
list_display = ('company', 'is_main', 'name', 'account', 'created_at',)
|
|
list_display_links = list_display
|
|
form = forms.BankAccountAdminForm
|
|
|
|
|
|
class ClientAdmin(admin.ModelAdmin):
|
|
class Media:
|
|
css = {'all': ('css/custom_admin.css',)}
|
|
|
|
list_display = ('company', 'name', 'inn',)
|
|
list_display_links = list_display
|
|
form = forms.ClientAdminForm
|
|
|
|
fieldsets = [
|
|
(None, {'fields': ['company']}),
|
|
(None, {'fields': ['name', 'inn', 'address', 'ogrn']}),
|
|
(u'ИП', {'fields': ['okpo']}),
|
|
(u'Организация', {'fields': ['kpp', ]}),
|
|
(u'Банковские реквизиты',
|
|
{'fields': ['bank_bik', 'bank_name', 'bank_korr_account', 'bank_account']}),
|
|
(u'Контакты',
|
|
{'fields': ['contact_name', 'contact_email',
|
|
'contact_phone', 'contact_skype', 'contact_other']}),
|
|
]
|
|
|
|
|
|
@admin.register(models.Payment)
|
|
class PaymentAdmin(admin.ModelAdmin):
|
|
list_display = (
|
|
'admin_pk',
|
|
'admin_user',
|
|
'order_amount',
|
|
'order_number',
|
|
'status'
|
|
)
|
|
|
|
def admin_pk(self, obj):
|
|
return obj.pk
|
|
|
|
admin_pk.short_description = 'Ключ'
|
|
admin_pk.admin_order_field = 'pk'
|
|
|
|
def admin_user(self, obj):
|
|
return obj.user.email
|
|
|
|
admin_user.short_description = 'Email'
|
|
admin_user.admin_order_field = 'user__email'
|
|
|
|
|
|
admin.site.register(models.UserProfile, UserProfileAdmin)
|
|
admin.site.register(models.BankAccount, BankAccountAdmin)
|
|
admin.site.register(models.Client, ClientAdmin)
|
|
admin.site.register(models.LicensePrice)
|
|
admin.site.register(SuccessNotification)
|
|
|