django-orchestra-test/orchestra/apps/bills/admin.py

62 lines
2.0 KiB
Python
Raw Normal View History

2014-07-23 16:24:56 +00:00
from django.contrib import admin
from django.core.urlresolvers import reverse
from django.utils.translation import ugettext_lazy as _
2014-08-19 18:59:23 +00:00
from orchestra.admin import ExtendedModelAdmin
2014-07-23 16:24:56 +00:00
from orchestra.admin.utils import admin_link, admin_date
from orchestra.apps.accounts.admin import AccountAdminMixin
2014-08-19 18:59:23 +00:00
from .actions import generate_bill
2014-07-23 16:24:56 +00:00
from .filters import BillTypeListFilter
from .models import (Bill, Invoice, AmendmentInvoice, Fee, AmendmentFee, Budget,
BillLine, BudgetLine)
class BillLineInline(admin.TabularInline):
model = BillLine
fields = (
'description', 'initial_date', 'final_date', 'price', 'amount', 'tax'
)
2014-07-23 16:24:56 +00:00
class BudgetLineInline(admin.TabularInline):
model = Budget
fields = (
'description', 'initial_date', 'final_date', 'price', 'amount', 'tax'
)
2014-07-23 16:24:56 +00:00
2014-08-19 18:59:23 +00:00
class BillAdmin(AccountAdminMixin, ExtendedModelAdmin):
2014-07-23 16:24:56 +00:00
list_display = (
2014-08-19 18:59:23 +00:00
'ident', 'status', 'type_link', 'account_link', 'created_on_display'
2014-07-23 16:24:56 +00:00
)
list_filter = (BillTypeListFilter, 'status',)
2014-08-19 18:59:23 +00:00
change_view_actions = [generate_bill]
change_readonly_fields = ('account', 'type', 'status')
2014-07-23 16:24:56 +00:00
readonly_fields = ('ident',)
inlines = [BillLineInline]
account_link = admin_link('account')
created_on_display = admin_date('created_on')
2014-08-19 18:59:23 +00:00
def type_link(self, bill):
bill_type = bill.type.lower()
2014-07-23 16:24:56 +00:00
url = reverse('admin:bills_%s_changelist' % bill_type)
2014-08-19 18:59:23 +00:00
return '<a href="%s">%s</a>' % (url, bill.get_type_display())
type_link.allow_tags = True
type_link.short_description = _("type")
type_link.admin_order_field = 'type'
2014-07-23 16:24:56 +00:00
def get_inline_instances(self, request, obj=None):
if self.model is Budget:
self.inlines = [BudgetLineInline]
return super(BillAdmin, self).get_inline_instances(request, obj=obj)
admin.site.register(Bill, BillAdmin)
admin.site.register(Invoice, BillAdmin)
admin.site.register(AmendmentInvoice, BillAdmin)
admin.site.register(Fee, BillAdmin)
admin.site.register(AmendmentFee, BillAdmin)
admin.site.register(Budget, BillAdmin)