Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Supporter record management #65

Merged
merged 23 commits into from
Jun 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
68b614e
Simplify band type and add prospective band field
joemull May 8, 2024
504b173
Forms for editing supporters and bands #63
joemull May 8, 2024
e92d449
Views for finding and editing supporters and bands #63
joemull May 8, 2024
9f291d4
Billing manager can create a new supporter #63
joemull May 8, 2024
b06dec3
Command for matching RORs #63
joemull May 8, 2024
d496e96
Update other commands for Band.category
joemull May 8, 2024
e0c5c57
Completes 9f291d48 #63
joemull May 8, 2024
9b5286a
Touch up admin views for bands #63
joemull May 21, 2024
e985ede
Clarify facet name #63
joemull May 21, 2024
0a0e3d1
Fixture with example supporter data #63
joemull May 21, 2024
507a124
Document example data fixture #63
joemull May 21, 2024
416a0ff
Update inherited class; add category facet #63
joemull May 30, 2024
a59b48e
Move CSS to external stylesheet #63
joemull May 30, 2024
728a431
Check request response.ok rather than code 200 #63
joemull May 30, 2024
cbc5838
Handle API responses more robustly #63
joemull May 30, 2024
293347f
Handle edge cases in the autofill ROR button #63
joemull May 30, 2024
ee0d8d1
Refactor saving of bands and band forms #63
joemull May 30, 2024
76513a4
Remove deprecated country field on Supporter #63
joemull May 30, 2024
40d5744
Refactor supporter save pattern #63
joemull May 30, 2024
48cf2c3
Clean up templates #63
joemull May 30, 2024
3cc84f2
Allow getting ROR before saving supporter #63
joemull May 30, 2024
b9b9cd2
Add display facet to supporter list #63
joemull May 31, 2024
50fbcb7
Update example data #63
joemull May 31, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
# consortial-billing
This is a plugin for Janeway that handles consortial billing.

## Development

You can get up and running with example data by running the management
command `install_example_supporter_data`.
88 changes: 49 additions & 39 deletions admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from django.contrib import admin
from django.contrib import messages
from django.utils import timezone
from django.conf import settings

from plugins.consortial_billing import models
from core import files
Expand All @@ -21,15 +22,19 @@ class SupporterContactInline(admin.TabularInline):


class SupporterInline(admin.TabularInline):
fk_name = 'band'
model = models.Supporter
fields = ('name', 'country')
readonly_fields = ('name', 'country')
fields = ('name', '_country')
readonly_fields = ('name', '_country')
show_change_link = True
can_delete = False

def has_add_permission(self, request, obj):
return False

def _country(self, obj):
return obj.band.country.name if obj and obj.band else ''


class OldBandInline(admin.TabularInline):
model = models.OldBand
Expand All @@ -41,11 +46,33 @@ def has_add_permission(self, request, obj):
return False


class BaseBandInline(admin.TabularInline):
model = models.Band
extra = 0
verbose_name_plural = 'Base Bands (including Old Bands)'
exclude = ('warnings',)
readonly_fields = (
'size',
'country',
'currency',
'level',
'datetime',
'fee',
'category',
)
can_delete = False

def get_queryset(self, request):
queryset = super().get_queryset(request)
return queryset.filter(category='base').order_by('-datetime')


class BillingAgentAdmin(admin.ModelAdmin):
list_display = (
'name',
'_contacts',
'country',
'redirect_url',
'default',
)
list_editable = (
Expand All @@ -54,6 +81,7 @@ class BillingAgentAdmin(admin.ModelAdmin):
)
inlines = [
AgentContactInline,
BaseBandInline,
]

def _contacts(self, obj):
Expand All @@ -78,6 +106,9 @@ class SupporterSizeAdmin(admin.ModelAdmin):
'multiplier',
'internal_notes',
)
inlines = [
BaseBandInline,
]


class SupportLevelAdmin(admin.ModelAdmin):
Expand All @@ -96,6 +127,9 @@ class SupportLevelAdmin(admin.ModelAdmin):
'internal_notes',
'default',
)
inlines = [
BaseBandInline,
]


class CurrencyAdmin(admin.ModelAdmin):
Expand All @@ -116,6 +150,10 @@ class CurrencyAdmin(admin.ModelAdmin):
readonly_fields = (
'_exchange_rate',
)
inlines = [
BaseBandInline,
]


def _exchange_rate(self, obj):
if obj:
Expand All @@ -135,13 +173,10 @@ class BandAdmin(admin.ModelAdmin):
'fee',
'datetime',
'billing_agent',
'display',
'base',
'category',
)
list_filter = (
'base',
'display',
'fixed_fee',
'category',
'datetime',
'size',
'currency',
Expand All @@ -156,36 +191,6 @@ class BandAdmin(admin.ModelAdmin):
OldBandInline,
]

def get_readonly_fields(self, request, obj=None):
if obj and obj.fixed_fee:
return (
'size',
'country',
'currency',
'level',
'warnings',
'datetime',
'base',
)
elif obj:
return (
'size',
'country',
'currency',
'level',
'fee',
'fixed_fee',
'warnings',
'datetime',
'billing_agent',
'base',
)
else:
return (
'warnings',
'datetime',
)


class SupporterAdmin(admin.ModelAdmin):

Expand All @@ -197,7 +202,7 @@ class SupporterAdmin(admin.ModelAdmin):
'_contacts',
'address',
'postal_code',
'country',
'_country',
'size',
'level',
'fee',
Expand All @@ -208,6 +213,8 @@ class SupporterAdmin(admin.ModelAdmin):
)
search_fields = (
'name',
'id',
'ror',
'address',
'postal_code',
'supportercontact__account__first_name',
Expand All @@ -224,6 +231,7 @@ class SupporterAdmin(admin.ModelAdmin):
)
raw_id_fields = (
'band',
'prospective_band',
)

inlines = [
Expand All @@ -242,6 +250,9 @@ def _contacts(self, obj):
else:
return ''

def _country(self, obj):
return obj.band.country.name if obj and obj.band else ''

@admin.action(description="Export selected supporters")
def export_supporters(self, request, queryset):
"""
Expand All @@ -254,7 +265,6 @@ def export_supporters(self, request, queryset):
'ror',
'address',
'postal_code',
'country',
'display',
'active',
'size',
Expand Down
Loading