--- /dev/null
+# Generated by Django 4.0.8 on 2024-02-21 11:52
+
+from django.db import migrations, models
+import django.db.models.deletion
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('catalogue', '0046_alter_book_options_alter_bookmedia_options_and_more'),
+ ('funding', '0011_alter_funding_customer_ip_alter_funding_notify_key_and_more'),
+ ]
+
+ operations = [
+ migrations.AddField(
+ model_name='spent',
+ name='annotation',
+ field=models.CharField(blank=True, help_text="np. 'audiobook'", max_length=255, verbose_name='adnotacja'),
+ ),
+ migrations.AddField(
+ model_name='spent',
+ name='link',
+ field=models.URLField(blank=True, help_text='zamiast książki, np. kolekcja'),
+ ),
+ migrations.AlterField(
+ model_name='spent',
+ name='book',
+ field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, to='catalogue.book'),
+ ),
+ ]
--- /dev/null
+# Generated by Django 4.0.8 on 2024-02-21 11:55
+
+from django.db import migrations, models
+
+
+def populate_spent(apps, schema_editor):
+ Offer = apps.get_model('funding', 'Offer')
+ Spent = apps.get_model('funding', 'Spent')
+ Book = apps.get_model('catalogue', 'Book')
+ for o in Offer.objects.all():
+ if Spent.objects.filter(book__slug=o.slug).exists():
+ continue
+ s = o.funding_set.exclude(completed_at=None).aggregate(s=models.Sum('amount'))['s'] or 0
+ if s >= o.target:
+ try:
+ book = Book.objects.get(slug=o.slug)
+ link = ''
+ except Book.DoesNotExist:
+ book = None
+ link = o.slug
+ Spent.objects.create(
+ book=book,
+ link=link,
+ amount=o.target,
+ timestamp=o.end,
+ annotation='auto'
+ )
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('funding', '0012_spent_annotation_spent_link_alter_spent_book'),
+ ]
+
+ operations = [
+ migrations.RunPython(
+ populate_spent,
+ migrations.RunPython.noop
+ )
+ ]
class Spent(models.Model):
""" Some of the remaining money spent on a book. """
- book = models.ForeignKey(Book, models.PROTECT)
+ book = models.ForeignKey(Book, models.PROTECT, null=True, blank=True)
+ link = models.URLField(blank=True, help_text='zamiast książki, np. kolekcja')
amount = models.DecimalField('kwota', decimal_places=2, max_digits=10)
timestamp = models.DateField('kiedy')
+ annotation = models.CharField('adnotacja', max_length=255, blank=True, help_text="np. 'audiobook'")
class Meta:
verbose_name = 'pieniądze wydane na książkę'
<tr>
<td>{% trans "Data" %}:</td>
<td>{% trans "Rozdysponowanie środków" %}:</td>
- <td>{% trans "Kwota" %}:</td>
+ <td>{% trans "Zebrane" %}:</td>
+ <td>{% trans "Wydane" %}:</td>
<td>{% trans "Bilans" %}:</td>
</tr>
<tr class="funding-minus">
<td class="oneline">{{ entry.timestamp }}</td>
<td>
- {% trans "Pieniądze przeznaczone na opublikowanie książki" %}:
- <a href="{{ entry.book.get_absolute_url }}">{{ entry.book }}</a>
+ {% trans "Pieniądze przeznaczone na publikację" %}:
+ {% if entry.book %}
+ <a href="{{ entry.book.get_absolute_url }}">{{ entry.book }}</a>
+ {% if entry.annotation %}
+ ({{ entry.annotation }})
+ {% endif %}
+ {% else %}
+ <a href="{{ entry.link }}">{{ entry.annotation }}</a>
+ {% endif %}
</td>
- <td>-{{ entry.amount }} zł</td>
+ <td></td>
+ <td>{{ entry.amount }} zł</td>
<td>{{ entry.total }} zł</td>
</tr>
{% else %}
<tr class="funding-plus">
<td class="oneline">{{ entry.end }}</td>
<td>
- {% trans "Pieniądze pozostałe ze zbiórki na" %}:
+ {% trans "Zbiórka" %}:
<a href="{{ entry.get_absolute_url }}">{{ entry }}</a>
</td>
- <td>+{{ entry.wlfund }} zł</td>
+ <td>{{ entry.wlfund }} zł</td>
+ <td></td>
<td>{{ entry.total }} zł</td>
</tr>
{% endif %}
offers = []
for o in Offer.past():
- if o.is_win():
- o.wlfund = o.sum() - o.target
- if o.wlfund > 0:
- offers.append(o)
- else:
- o.wlfund = o.sum()
- if o.wlfund > 0:
- offers.append(o)
+ o.wlfund = o.sum()
+ if o.wlfund > 0:
+ offers.append(o)
amount = sum(o.wlfund for o in offers) - sum(o.amount for o in Spent.objects.all())
ctx['amount'] = amount
ctx['log'] = add_total(amount, mix(
- (offers, lambda x: x.end, 'offer'),
(Spent.objects.all().select_related(), lambda x: x.timestamp, 'spent'),
+ (offers, lambda x: x.end, 'offer'),
))
return ctx