SciPost Code Repository

Skip to content
Snippets Groups Projects
Commit f68f9076 authored by Jean-Sébastien Caux's avatar Jean-Sébastien Caux
Browse files

Add renewal ManyToMany to Subsidy

parent 0ae6ee7b
No related branches found
No related tags found
No related merge requests found
......@@ -25,7 +25,7 @@ class SubsidyForm(forms.ModelForm):
model = Subsidy
fields = ['organization', 'subsidy_type', 'description',
'amount', 'amount_publicly_shown', 'status',
'date', 'date_until']
'date', 'date_until', 'renewal_of']
class SubsidyAttachmentForm(forms.ModelForm):
......
# -*- coding: utf-8 -*-
# Generated by Django 1.11.4 on 2019-02-23 10:49
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('finances', '0012_subsidyattachment'),
]
operations = [
migrations.AddField(
model_name='subsidy',
name='renewal_of',
field=models.ManyToManyField(blank=True, related_name='renewed_by', to='finances.Subsidy'),
),
]
......@@ -44,6 +44,8 @@ class Subsidy(models.Model):
status = models.CharField(max_length=32, choices=SUBSIDY_STATUS)
date = models.DateField()
date_until = models.DateField(blank=True, null=True)
renewal_of = models.ManyToManyField('self', related_name='renewed_by',
symmetrical=False, blank=True)
class Meta:
verbose_name_plural = 'subsidies'
......@@ -65,6 +67,8 @@ class Subsidy(models.Model):
@property
def renewal_action_date_color_class(self):
if self.date_until and self.subsidy_type == SUBSIDY_TYPE_SPONSORSHIPAGREEMENT:
if self.renewed_by.exists():
return 'transparent'
today = datetime.date.today()
if self.date_until < today + datetime.timedelta(days=122):
return 'danger'
......@@ -76,6 +80,8 @@ class Subsidy(models.Model):
@property
def date_until_color_class(self):
if self.date_until and self.subsidy_type == SUBSIDY_TYPE_SPONSORSHIPAGREEMENT:
if self.renewed_by.exists():
return 'transparent'
today = datetime.date.today()
if self.date_until < today:
return 'warning'
......
......@@ -36,6 +36,18 @@
</tr>
{% endif %}
</table>
{% if subsidy.renewal_of.all|length > 0 %}
<p>
Renewal of:<ul>{% for prevsub in subsidy.renewal_of.all %}<li><a href="{% url 'finances:subsidy_details' pk=prevsub.id %}">{{ prevsub }}</a></li>{% endfor %}</ul>
</p>
{% endif %}
{% if subsidy.renewed_by.all|length > 0 %}
<p>
Renewed by:<ul>{% for newsub in subsidy.renewed_by.all %}<li><a href="{% url 'finances:subsidy_details' pk=newsub.id %}">{{ newsub }}</a></li>{% endfor %}</ul>
</p>
{% endif %}
</div>
</div>
......
......@@ -86,7 +86,9 @@ $(document).ready(function($) {
{% for subsidy in object_list %}
<tr class="table-row" data-href="{% url 'finances:subsidy_details' pk=subsidy.id %}" style="cursor: pointer;">
<td>{{ subsidy.organization }}</td>
<td>{{ subsidy.get_subsidy_type_display }}</td>
<td>{{ subsidy.get_subsidy_type_display }}
{% if subsidy.renewal_of.all|length > 0 %}<br/><span class="small text-muted">Renewal of:<ul class="list-unstyled">{% for prevsub in subsidy.renewal_of.all %}<li>{{ prevsub }}</li>{% endfor %}</ul></span>{% endif %}
{% if subsidy.renewed_by.all|length > 0 %}<br/><span class="small text-muted">Renewed by:<ul class="list-unstyled">{% for newsub in subsidy.renewed_by.all %}<li>{{ newsub }}</li>{% endfor %}</ul></span>{% endif %} </td>
<td>{% if subsidy.amount_publicly_shown or perms.scipost.can_manage_subsidies %}&euro;{{ subsidy.amount }}{% else %}-{% endif %}</td>
<td>{{ subsidy.date }}</td>
<td class="bg-{{ subsidy.date_until_color_class }}">{{ subsidy.date_until }}</td>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment