From 52105508b104ae224871217bbd1cb0877caace4f Mon Sep 17 00:00:00 2001 From: "J.-S. Caux" <J.S.Caux@uva.nl> Date: Sun, 7 Oct 2018 15:38:33 +0200 Subject: [PATCH] Work on finances and subsidies --- finances/models.py | 6 +++ .../templates/finances/_subsidy_card.html | 42 +++++++++++++++ finances/templates/finances/finances.html | 4 +- .../templates/finances/subsidy_detail.html | 22 ++++++++ finances/templates/finances/subsidy_list.html | 48 +++++++++-------- finances/urls.py | 5 ++ finances/views.py | 4 ++ organizations/models.py | 11 ++++ .../organizations/_organization_card.html | 51 +++++++++++++++++-- .../organizations/organization_list.html | 20 ++++---- 10 files changed, 174 insertions(+), 39 deletions(-) create mode 100644 finances/templates/finances/_subsidy_card.html create mode 100644 finances/templates/finances/subsidy_detail.html diff --git a/finances/models.py b/finances/models.py index 2e9c9ddf2..af67dc7a0 100644 --- a/finances/models.py +++ b/finances/models.py @@ -6,6 +6,7 @@ from django.conf import settings from django.contrib.contenttypes.models import ContentType from django.contrib.contenttypes.fields import GenericForeignKey from django.db import models +from django.urls import reverse from django.utils import timezone from django.utils.html import format_html @@ -24,6 +25,7 @@ class Subsidy(models.Model): - an incidental grant - a development grant for a specific purpose - a Collaboration Agreement + - a donation """ organization = models.ForeignKey('organizations.Organization', on_delete=models.CASCADE) subsidy_type = models.CharField(max_length=256, choices=SUBSIDY_TYPES) @@ -40,6 +42,10 @@ class Subsidy(models.Model): return format_html('{}: €{} from {}, for {}', self.date, self.amount, self.organization, self.description) + def get_absolute_url(self): + return reverse('finances:subsidy_details', args=(self.id,)) + + class WorkLog(models.Model): user = models.ForeignKey(settings.AUTH_USER_MODEL) comments = models.TextField(blank=True) diff --git a/finances/templates/finances/_subsidy_card.html b/finances/templates/finances/_subsidy_card.html new file mode 100644 index 000000000..3d1ffc36a --- /dev/null +++ b/finances/templates/finances/_subsidy_card.html @@ -0,0 +1,42 @@ +{% load bootstrap %} + +{% load user_groups %} + +<div class="card-body"> + <div class="row"> + <div class="col-12"> + + <h3 class="highlight">Subsidy details</h3> + {% if perms.scipost.can_manage_subsidies %} + <ul class="list-inline"><li class="list-inline-item"><strong>Admin actions:</strong></li> + <li class="list-inline-item"><a href="{% url 'finances:subsidy_update' pk=subsidy.id %}"><span class="text-warning">Update</span></a></li> + <li class="list-inline-item"><a href="{% url 'finances:subsidy_delete' pk=subsidy.id %}"><span class="text-danger">Delete</span></a></li> + </ul> + {% endif %} + + <table class="table"> + <tr> + <td>From:</td><td><a href="{{ subsidy.organization.get_absolute_url }}">{{ subsidy.organization }}</a></td> + </tr> + <tr> + <td>Type:</td><td>{{ subsidy.get_subsidy_type_display }}</td> + </tr> + <tr> + <td>Description:</td><td>{{ subsidy.description }}</td> + </tr> + <tr> + <td>Amount:</td><td>€{{ subsidy.amount }}</td> + </tr> + <tr> + <td>Date:</td><td>{{ subsidy.date }}</td> + </tr> + {% if subsidy.duration %} + <tr> + <td>Duration:</td><td>{{ subsidy.get_duration_display }}</td> + </tr> + {% endif %} + </table> + </div> + </div> + +</div> diff --git a/finances/templates/finances/finances.html b/finances/templates/finances/finances.html index 3422bebb6..1a6698429 100644 --- a/finances/templates/finances/finances.html +++ b/finances/templates/finances/finances.html @@ -14,8 +14,10 @@ <div class="col-12"> <h3 class="highlight">Finances</h3> <ul> - <li><a href="{% url 'finances:subsidies' %}">Manage Subsidies</a></li> + <li><a href="{% url 'finances:subsidies' %}">View {% if perms.scipost.can_manage_subsidies %}(and manage) {% endif %}info on Subsidies obtained by SciPost</a></li> + {% if perms.scipost.can_view_timesheets %} <li><a href="{% url 'finances:timesheets' %}">Manage Timesheets</a></li> + {% endif %} </ul> </div> </div> diff --git a/finances/templates/finances/subsidy_detail.html b/finances/templates/finances/subsidy_detail.html new file mode 100644 index 000000000..ab90b4673 --- /dev/null +++ b/finances/templates/finances/subsidy_detail.html @@ -0,0 +1,22 @@ +{% extends 'finances/base.html' %} + +{% load bootstrap %} + +{% block pagetitle %}: Subsidy details{% endblock pagetitle %} + +{% block breadcrumb_items %} +{{ block.super }} +<span class="breadcrumb-item"><a href="{% url 'finances:subsidies' %}">Subsidies</a></span> +<span class="breadcrumb-item">{{ subsidy }}</span> +{% endblock %} + + +{% block content %} + +<div class="row"> + <div class="col-12"> + {% include 'finances/_subsidy_card.html' with subsidy=subsidy %} + </div> +</div> + +{% endblock content %} diff --git a/finances/templates/finances/subsidy_list.html b/finances/templates/finances/subsidy_list.html index 0540cb603..286716e4b 100644 --- a/finances/templates/finances/subsidy_list.html +++ b/finances/templates/finances/subsidy_list.html @@ -2,6 +2,19 @@ {% block pagetitle %}: Subsidies{% endblock pagetitle %} +{% load staticfiles %} + + +{% block headsup %} +<script type="text/javascript"> +$(document).ready(function($) { + $(".table-row").click(function() { + window.document.location = $(this).data("href"); + }); +}); +</script> +{% endblock headsup %} + {% block breadcrumb_items %} {{ block.super }} @@ -18,10 +31,14 @@ <li><a href="{% url 'finances:subsidy_create' %}">Add a Subsidy</a></li> </ul> {% endif %} + </div> +</div> +<div class="row"> + <div class="col-12"> <h4>Subsidies obtained:</h4> <table class="table table-hover mb-5"> - <thead> + <thead class="thead-default"> <tr> <th>From Organization</th> <th>Type</th> @@ -29,32 +46,13 @@ <th>Date</th> </tr> </thead> - <tbody id="accordion" role="tablist" aria-multiselectable="true"> + <tbody> {% for subsidy in object_list %} - <tr data-toggle="collapse" data-parent="#accordion" href="#collapse{{ subsidy.id }}" aria-expanded="false" aria-controls="collapse{{ subsidy.id }}" style="cursor: pointer;"> + <tr class="table-row" data-href="{% url 'finances:subsidy_details' pk=subsidy.id %}" style="cursor: pointer;"> <td>{{ subsidy.organization }}</td> - <td>{{ subsidy.get_type_display }}</td> - <td>{{ subsidy.amount }}</td> - <td>{{ subside.date|date:"Y-m-d" }}</td> - </tr> - <tr id="collapse{{ subsidy.id }}" class="collapse" role="tabpanel" aria-labelledby="heading{{ subsidy.id }}" style="background-color: #fff;"> - <td colspan="3"> - <h5>Description:</h5> - <p>{{ subsidy.description }}</p> - {% if subsidy.duration %} - <h5>Duration:</h5> - {{ subsidy.get_duration_display }} - {% endif %} - </td> - <td> - {% if perms.scipost.can_manage_subsidies %} - <h5>Admin actions:</h5> - <ul> - <li><a href="{% url 'finances:subsidy_update' pk=subsidy.id %}"><span class="text-warning">Update</span></a></li> - <li><a href="{% url 'finances:subsidy_delete' pk=subsidy.id %}"><span class="text-danger">Delete</span></a></li> - </ul> - {% endif %} - </td> + <td>{{ subsidy.get_subsidy_type_display }}</td> + <td>€{{ subsidy.amount }}</td> + <td>{{ subsidy.date }}</td> </tr> {% empty %} <tr> diff --git a/finances/urls.py b/finances/urls.py index 429317d01..b7027f8c2 100644 --- a/finances/urls.py +++ b/finances/urls.py @@ -35,6 +35,11 @@ urlpatterns = [ views.SubsidyDeleteView.as_view(), name='subsidy_delete' ), + url( + r'^subsidies/(?P<pk>[0-9]+)/$', + views.SubsidyDetailView.as_view(), + name='subsidy_details' + ), # Timesheets url( diff --git a/finances/views.py b/finances/views.py index a87360cf6..5178e84f4 100644 --- a/finances/views.py +++ b/finances/views.py @@ -59,6 +59,10 @@ class SubsidyListView(ListView): model = Subsidy +class SubsidyDetailView(DetailView): + model = Subsidy + + ############################ # Timesheets and Work Logs # ############################ diff --git a/organizations/models.py b/organizations/models.py index 2890f1391..cae00816f 100644 --- a/organizations/models.py +++ b/organizations/models.py @@ -142,6 +142,17 @@ class Organization(models.Model): return False return self.partner.agreements.now_active().exists() + def get_total_subsidies_obtained(self, n_years_part=None): + """ + Computes the total amount received by SciPost, in the form + of subsidies from this Organization. + """ + contrib = 0 + now = timezone.now().date() + for subsidy in self.subsidy_set.all(): + contrib += subsidy.amount + return contrib + def get_total_contribution_obtained(self, n_years_past=None): """ Computes the contribution obtained from this organization, diff --git a/organizations/templates/organizations/_organization_card.html b/organizations/templates/organizations/_organization_card.html index ade2208cd..2ad2a7d12 100644 --- a/organizations/templates/organizations/_organization_card.html +++ b/organizations/templates/organizations/_organization_card.html @@ -3,6 +3,16 @@ {% load user_groups %} {% load organizations_extras %} +{% block headsup %} +<script type="text/javascript"> +$(document).ready(function($) { + $(".table-row").click(function() { + window.document.location = $(this).data("href"); + }); +}); +</script> +{% endblock headsup %} + {% is_scipost_admin request.user as is_scipost_admin %} <div class="card-body"> @@ -91,9 +101,9 @@ {% empty %} <li>No Funder Registry instance found<br/><br/> <strong class="text-danger">Without a Funder Registry instance, we cannot record funding acknowledgements to this Organization with Crossref.</strong> - <p>Are you a representative of this Organization? Please:</p> + <p>Are you a representative of this Organization? Then <em>for <strong>your Organization's</strong> benefit, not SciPost's</em>, you really should:</p> <ol> - <li>Make sure your Organization is included in <a href="https://www.crossref.org/services/funder-registry/" target="_blank">Crossref's Funder Registry</a></li> + <li>Make sure your Organization gets included in <a href="https://www.crossref.org/services/funder-registry/" target="_blank">Crossref's Funder Registry</a></li> <li>After inclusion, <a href="mailto:admin@scipost.org?subject=Inclusion of {{ organization }} {% if organization.acronym %}({{ organization.acronym }}){% endif %} in the Funder Registry">contact our administration</a> with this information so that we can update our records.</li> </ol> </li> @@ -102,6 +112,40 @@ </div> <div class="tab-pane pt-4" id="support-{{ org.id }}" role="tabpanel" aria-labelledby="support-{{ org.id }}-tab"> + <h3>Support history</h3> + {% if org.subsidy_set.all|length > 0 %} + <p>List of the subsidies (in one form or another) which SciPost has received from this Organization. Click on a row to see more details.</p> + <table class="table table-hover mb-5"> + <thead class="thead-default"> + <tr> + <th>Type</th> + <th>Amount</th> + <th>Date</th> + <th>Duration</th> + </tr> + </thead> + <tbody> + {% for subsidy in org.subsidy_set.all %} + <tr class="table-row" data-href="{% url 'finances:subsidy_details' pk=subsidy.id %}" style="cursor: pointer;"> + <td>{{ subsidy.get_subsidy_type_display }}</td> + <td>€{{ subsidy.amount }}</td> + <td>{{ subsidy.date }}</td> + <td>{{ subsidy.get_duration_display }}</td> + </tr> + {% endfor %} + <tr style="border-top: 2px solid black"> + <td>Total support obtained:</td> + <td>€{{ org.get_total_subsidies_obtained }}</td> + <td colspan="2"> + </tr> + </tbody> + </table> + {% else %} + <p><strong>This Organization has <span class="text-danger">not yet</span> subsidized SciPost</strong></p> + {% endif %} + + {% if is_scipost_admin %} + <h3 class="text-danger">To be removed (Admin view only):</h3> <h3>Supporting Partner Agreements history:</h3> {% with agreement=org.partner.get_latest_active_agreement %} {% if agreement %} @@ -122,7 +166,7 @@ <td>{{ agreement.get_status_display }}</td> <td>{{ agreement.get_duration_display }}</td> <td>{{ agreement.start_date }}</td> - <td>€ {{ agreement.offered_yearly_contribution }}</td> + <td>€{{ agreement.offered_yearly_contribution }}</td> </tr> {% endfor %} <tr style="border-top: 2px solid black"> @@ -133,6 +177,7 @@ <p>This organization has <span class="text-danger">not yet</span> been a SciPost Supporting Partner.</p> {% endif %} </div> + {% endif %} <div class="tab-pane pt-4" id="manage-{{ org.id }}" role="tabpanel" aria-labelledby="manage-{{ org.id }}-tab"> {% if perms.scipost.can_manage_organizations %} diff --git a/organizations/templates/organizations/organization_list.html b/organizations/templates/organizations/organization_list.html index 4e65d3922..df0c71bc2 100644 --- a/organizations/templates/organizations/organization_list.html +++ b/organizations/templates/organizations/organization_list.html @@ -25,16 +25,16 @@ $(document).ready(function($) { {% block content %} <div class="row"> - <div class="col-12"> - <h1 class="highlight">Organizations</h1> - {% if perms.scipost.can_manage_organizations %} - <h3>Management actions:</h3> - <ul> - <li><a href="{% url 'organizations:organization_create' %}">Create a new Organization instance</a></li> - <li><a href="{% url 'funders:funders_dashboard' %}">Link Funders to Organizations</a> ({{ nr_funders_wo_organization }} found in need of linking)</li> - </ul> - {% endif %} - </div> + <div class="col-12"> + <h1 class="highlight">Organizations</h1> + {% if perms.scipost.can_manage_organizations %} + <h3>Management actions:</h3> + <ul> + <li><a href="{% url 'organizations:organization_create' %}">Create a new Organization instance</a></li> + <li><a href="{% url 'funders:funders_dashboard' %}">Link Funders to Organizations</a> ({{ nr_funders_wo_organization }} found in need of linking)</li> + </ul> + {% endif %} + </div> </div> -- GitLab