add a "recent transactions" combo cell
This commit is contained in:
parent
5c933b7e43
commit
949d65208b
|
@ -0,0 +1,40 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import models, migrations
|
||||
from django.conf import settings
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('auth', '0001_initial'),
|
||||
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
|
||||
('data', '0005_auto_20150226_0903'),
|
||||
('lingo', '0004_basketitem_notification_date'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='LingoRecentTransactionsCell',
|
||||
fields=[
|
||||
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
|
||||
('placeholder', models.CharField(max_length=20)),
|
||||
('order', models.PositiveIntegerField()),
|
||||
('slug', models.SlugField(verbose_name='Slug', blank=True)),
|
||||
('public', models.BooleanField(default=True, verbose_name='Public')),
|
||||
('groups', models.ManyToManyField(to='auth.Group', verbose_name='Groups', blank=True)),
|
||||
('page', models.ForeignKey(to='data.Page')),
|
||||
],
|
||||
options={
|
||||
'verbose_name': 'Recent Transactions',
|
||||
},
|
||||
bases=(models.Model,),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='transaction',
|
||||
name='user',
|
||||
field=models.ForeignKey(default=0, to=settings.AUTH_USER_MODEL),
|
||||
preserve_default=False,
|
||||
),
|
||||
]
|
|
@ -93,6 +93,7 @@ class Transaction(models.Model):
|
|||
end_date = models.DateTimeField(null=True)
|
||||
bank_data = JSONField(blank=True)
|
||||
order_id = models.CharField(max_length=200)
|
||||
user = models.ForeignKey(settings.AUTH_USER_MODEL)
|
||||
|
||||
|
||||
@register_cell_class
|
||||
|
@ -114,3 +115,25 @@ class LingoBasketCell(CellBase):
|
|||
).exclude(cancellation_date__isnull=False)
|
||||
context['total'] = sum([x.amount for x in context['items']])
|
||||
return basket_template.render(context)
|
||||
|
||||
|
||||
@register_cell_class
|
||||
class LingoRecentTransactionsCell(CellBase):
|
||||
|
||||
class Meta:
|
||||
verbose_name = _('Recent Transactions')
|
||||
|
||||
def is_relevant(self, context):
|
||||
transactions = Transaction.objects.filter(
|
||||
user=context['request'].user,
|
||||
start_date__gte=timezone.now()-datetime.timedelta(days=7))
|
||||
return len(transactions) > 0
|
||||
|
||||
def render(self, context):
|
||||
recent_transactions_template = template.loader.get_template(
|
||||
'lingo/combo/recent_transactions.html')
|
||||
context['transactions'] = Transaction.objects.filter(
|
||||
user=context['request'].user,
|
||||
start_date__gte=timezone.now()-datetime.timedelta(days=7)
|
||||
).order_by('-start_date')
|
||||
return recent_transactions_template.render(context)
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
{% load i18n %}
|
||||
<h3>{% trans "Recent Transactions" %}</h3>
|
||||
{% csrf_token %}
|
||||
<ul>
|
||||
{% for transaction in transactions %}
|
||||
<li>{{ transaction.start_date|date:"d E o H:i"|lower }}
|
||||
<ul>
|
||||
{% for item in transaction.items.all %}
|
||||
<li>{{ item.subject }}: {{ item.amount }} €</label> (<a href="{{ item.source_url}}">voir</a>)</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ul>
|
|
@ -92,6 +92,7 @@ class PayView(View):
|
|||
# XXX: check all items are going to the same regie
|
||||
|
||||
transaction = Transaction()
|
||||
transaction.user = request.user
|
||||
transaction.save()
|
||||
transaction.items = items
|
||||
transaction.save()
|
||||
|
|
Reference in New Issue