From e756e7466a2c8b7a639985b942b2cbe9b5b5a99e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-S=C3=A9bastien=20Caux?= <git@jscaux.org> Date: Wed, 20 Mar 2024 11:54:31 +0100 Subject: [PATCH] Relabel undivided to associated in Support history --- scipost_django/organizations/models.py | 71 ++++++++++++------- .../organizations/_organization_card.html | 42 +++++------ 2 files changed, 68 insertions(+), 45 deletions(-) diff --git a/scipost_django/organizations/models.py b/scipost_django/organizations/models.py index 22e8d3bd7..4ffeb46ac 100644 --- a/scipost_django/organizations/models.py +++ b/scipost_django/organizations/models.py @@ -474,9 +474,9 @@ class Organization(models.Model): cumulative_self_compensated = 0 cumulative_ally_compensated = 0 cumulative_uncompensated = 0 - cumulative_undivided_expenditures = 0 - cumulative_undivided_compensated = 0 - cumulative_undivided_uncompensated = 0 + cumulative_associated_expenditures = 0 + cumulative_associated_compensated = 0 + cumulative_associated_uncompensated = 0 cumulative_subsidy_income = 0 cumulative_reserved = 0 cumulative_balance = 0 @@ -487,14 +487,14 @@ class Organization(models.Model): subsidy_income = self.total_subsidies_in_year(year) rep[str(year)]["subsidy_income"] = subsidy_income year_nap = 0 - year_undivided_expenditures = 0 + year_associated_expenditures = 0 year_pubfracs = 0 year_expenditures = 0 year_self_compensated = 0 year_ally_compensated = 0 year_uncompensated = 0 - year_undivided_compensated = 0 - year_undivided_uncompensated = 0 + year_associated_compensated = 0 + year_associated_uncompensated = 0 year_reserved = 0 rep[str(year)]["expenditures"] = { "per_journal": {}, @@ -549,14 +549,14 @@ class Organization(models.Model): or 0 ) uncompensated = expenditures - self_compensated - ally_compensated - undivided_compensated = int( + associated_compensated = int( sum( p.compensated_expenditures for p in self.get_publications(year=year, journal=journal) ) ) - undivided_uncompensated = nap * costperpaper - undivided_compensated - if sum_pf > 0 or undivided_uncompensated > 0: + associated_uncompensated = nap * costperpaper - associated_compensated + if sum_pf > 0 or associated_uncompensated > 0: rep[str(year)]["expenditures"]["per_journal"][journal_label] = { "costperpaper": costperpaper, "nap": nap, @@ -565,19 +565,24 @@ class Organization(models.Model): "self_compensated": self_compensated, "ally_compensated": ally_compensated, "uncompensated": uncompensated, - "undivided_expenditures": nap * costperpaper, - "undivided_compensated": undivided_compensated, - "undivided_uncompensated": undivided_uncompensated, + "associated_expenditures": nap * costperpaper, + "associated_compensated": associated_compensated, + "associated_uncompensated": associated_uncompensated, + "freeriding_percentage": ( + int(100 * associated_uncompensated / (nap * costperpaper)) + if nap * costperpaper > 0 + else "N/A" + ), } year_nap += nap - year_undivided_expenditures += nap * costperpaper year_pubfracs += float(sum_pf) year_expenditures += expenditures year_self_compensated += self_compensated year_ally_compensated += ally_compensated year_uncompensated += uncompensated - year_undivided_compensated += undivided_compensated - year_undivided_uncompensated += undivided_uncompensated + year_associated_expenditures += nap * costperpaper + year_associated_compensated += associated_compensated + year_associated_uncompensated += associated_uncompensated rep[str(year)]["expenditures"]["total"] = { "nap": year_nap, "pubfracs": year_pubfracs, @@ -585,34 +590,52 @@ class Organization(models.Model): "self_compensated": year_self_compensated, "ally_compensated": year_ally_compensated, "uncompensated": year_uncompensated, - "undivided_expenditures": year_undivided_expenditures, - "undivided_compensated": year_undivided_compensated, - "undivided_uncompensated": year_undivided_uncompensated, + "associated_expenditures": year_associated_expenditures, + "associated_compensated": year_associated_compensated, + "associated_uncompensated": year_associated_uncompensated, + "freeriding_percentage": ( + int( + 100 + * year_associated_uncompensated + / year_associated_expenditures + ) + if year_associated_expenditures > 0 + else "N/A" + ), } rep[str(year)]["reserved"] = subsidy_income - year_self_compensated rep[str(year)]["balance"] = subsidy_income - year_expenditures cumulative_nap += year_nap - cumulative_undivided_expenditures += year_undivided_expenditures cumulative_pubfracs += year_pubfracs cumulative_expenditures += year_expenditures cumulative_self_compensated += year_self_compensated cumulative_ally_compensated += year_ally_compensated cumulative_uncompensated += year_uncompensated - cumulative_undivided_compensated += year_undivided_compensated - cumulative_undivided_uncompensated += year_undivided_uncompensated + cumulative_associated_expenditures += year_associated_expenditures + cumulative_associated_compensated += year_associated_compensated + cumulative_associated_uncompensated += year_associated_uncompensated cumulative_subsidy_income += subsidy_income cumulative_balance += subsidy_income - year_expenditures cumulative_reserved += subsidy_income - year_self_compensated rep["cumulative"] = { "nap": cumulative_nap, - "undivided_expenditures": cumulative_undivided_expenditures, "pubfracs": cumulative_pubfracs, "expenditures": cumulative_expenditures, "self_compensated": cumulative_self_compensated, "ally_compensated": cumulative_ally_compensated, "uncompensated": cumulative_uncompensated, - "undivided_compensated": cumulative_undivided_compensated, - "undivided_uncompensated": cumulative_undivided_uncompensated, + "associated_expenditures": cumulative_associated_expenditures, + "associated_compensated": cumulative_associated_compensated, + "associated_uncompensated": cumulative_associated_uncompensated, + "freeriding_percentage": ( + int( + 100 + * cumulative_associated_uncompensated + / cumulative_associated_expenditures + ) + if cumulative_associated_expenditures > 0 + else "N/A" + ), "subsidy_income": cumulative_subsidy_income, "reserved": cumulative_reserved, "balance": cumulative_balance, diff --git a/scipost_django/organizations/templates/organizations/_organization_card.html b/scipost_django/organizations/templates/organizations/_organization_card.html index e3fa5d3a8..99a96cecb 100644 --- a/scipost_django/organizations/templates/organizations/_organization_card.html +++ b/scipost_django/organizations/templates/organizations/_organization_card.html @@ -278,10 +278,10 @@ <tr> <th>Year (click to toggle details)</th> <th class="text-end">NAP</th> - <th class="text-end">Undivided<br>expenditures</th> + <th class="text-end">Total associated<br>expenditures</th> {% if 'finadmin' in user_roles %} - <th class="text-end">Undivided<br>compensations</th> - <th class="text-end">Undivided<br>uncompensated</th> + <th class="text-end">Total associated<br>compensations</th> + <th class="text-end">Total associated<br>uncompensated</th> <th class="text-end">Freeriding<br>percentage</th> {% endif %} {% if organization.has_pubfracs %} @@ -302,16 +302,16 @@ <tr class="table-light border border-2" style="font-weight: bold;"> <td>Cumulative</td> <td class="text-end">{{ balance.cumulative.nap }}</td> - <td class="text-end">€{{ balance.cumulative.undivided_expenditures }}</td> + <td class="text-end">€{{ balance.cumulative.associated_expenditures }}</td> {% if 'finadmin' in user_roles %} - <td class="text-end">€{{ balance.cumulative.undivided_compensated }}</td> - {% if balance.cumulative.undivided_uncompensated > 0 %} + <td class="text-end">€{{ balance.cumulative.associated_compensated }}</td> + {% if balance.cumulative.associated_uncompensated > 0 %} <td class="text-end bg-danger bg-opacity-25"> - €{{ balance.cumulative.undivided_uncompensated }} + €{{ balance.cumulative.associated_uncompensated }} </td> {% else %} <td class="text-end bg-success bg-opacity-25"> - €{{ balance.cumulative.undivided_uncompensated }} + €{{ balance.cumulative.associated_uncompensated }} </td> {% endif %} <td class="text-end">{{ balance.cumulative.freeriding_percentage }}</td> @@ -341,19 +341,19 @@ </td> <td class="text-end">{{ val.expenditures.total.nap }}</td> <td class="text-end"> - €{{ val.expenditures.total.undivided_expenditures }} + €{{ val.expenditures.total.associated_expenditures }} </td> {% if 'finadmin' in user_roles %} <td class="text-end"> - €{{ val.expenditures.total.undivided_compensated }} + €{{ val.expenditures.total.associated_compensated }} </td> - {% if val.expenditures.total.undivided_uncompensated > 0 %} + {% if val.expenditures.total.associated_uncompensated > 0 %} <td class="text-end bg-danger bg-opacity-25"> - €{{ val.expenditures.total.undivided_uncompensated }} + €{{ val.expenditures.total.associated_uncompensated }} </td> {% else %} <td class="text-end bg-success bg-opacity-25"> - €{{ val.expenditures.total.undivided_uncompensated }} + €{{ val.expenditures.total.associated_uncompensated }} </td> {% endif %} <td class="text-end"> @@ -406,10 +406,10 @@ <th>Journal</th> <th class="text-end">APEX</th> <th class="text-end">NAP</th> - <th class="text-end">Undivided<br>expenditures</th> + <th class="text-end">Total associated<br>expenditures</th> {% if 'finadmin' in user_roles %} - <th class="text-end">Undivided<br>compensations</th> - <th class="text-end">Undivided<br>uncompensated</th> + <th class="text-end">Total associated<br>compensations</th> + <th class="text-end">Total associated<br>uncompensated</th> <th class="text-end">Freeriding<br>percentage</th> {% endif %} {% if organization.has_pubfracs %} @@ -429,13 +429,13 @@ <td>{{ journal }}</td> <td class="text-end">€{{ journaldata.costperpaper }}</td> <td class="text-end">{{ journaldata.nap }}</td> - <td class="text-end">€{{ journaldata.undivided_expenditures }}</td> + <td class="text-end">€{{ journaldata.associated_expenditures }}</td> {% if 'finadmin' in user_roles %} - <td class="text-end">€{{ journaldata.undivided_compensated }}</td> - {% if journaldata.undivided_uncompensated > 0 %} - <td class="bg-danger bg-opacity-25 text-end">€{{ journaldata.undivided_uncompensated }}</td> + <td class="text-end">€{{ journaldata.associated_compensated }}</td> + {% if journaldata.associated_uncompensated > 0 %} + <td class="bg-danger bg-opacity-25 text-end">€{{ journaldata.associated_uncompensated }}</td> {% else %} - <td class="bg-success bg-opacity-25 text-end">€{{ journaldata.undivided_uncompensated }}</td> + <td class="bg-success bg-opacity-25 text-end">€{{ journaldata.associated_uncompensated }}</td> {% endif %} <td class="text-end">{{ journaldata.freeriding_percentage }}</td> {% endif %} -- GitLab