lingo: add regie's label to transaction's CSV report (#58134)

This commit is contained in:
Benjamin Dauvergne 2021-10-23 12:03:53 +02:00
parent bbaa7de67c
commit 74e33cdc80
2 changed files with 16 additions and 9 deletions

View File

@ -182,11 +182,15 @@ def download_transactions_csv(request):
response = HttpResponse(content_type='text/csv')
response['Content-Disposition'] = 'attachment; filename="transactions.csv"'
writer = csv.writer(response)
transactions = Transaction.objects.filter(
status__in=(eopayment.PAID, eopayment.ACCEPTED),
start_date__date__gte=form.cleaned_data['start_date'],
start_date__date__lte=form.cleaned_data['end_date'],
).order_by('-start_date')
transactions = (
Transaction.objects.filter(
status__in=(eopayment.PAID, eopayment.ACCEPTED),
start_date__date__gte=form.cleaned_data['start_date'],
start_date__date__lte=form.cleaned_data['end_date'],
)
.select_related('regie')
.order_by('-start_date')
)
for transaction in transactions:
row = [
transaction.order_id,
@ -194,6 +198,7 @@ def download_transactions_csv(request):
transaction.start_date.strftime('%Y-%m-%d %H:%M:%S'),
transaction.get_user_name(),
str(transaction.amount),
transaction.regie.label,
]
for item in transaction.items.all():
row.extend([item.subject, str(item.amount)])

View File

@ -213,8 +213,9 @@ def test_download_transaction(app, admin_user, regie):
assert row[1] == trans2.bank_transaction_id
assert row[3] == '%s %s' % (user.first_name, user.last_name)
assert Decimal(row[4]) == Decimal(trans2.amount)
assert row[5] == b_item.subject
assert Decimal(row[6]) == b_item.amount
assert row[5] == regie.label
assert row[6] == b_item.subject
assert Decimal(row[7]) == b_item.amount
resp = app.get('/manage/lingo/transactions/download-csv/', status=200)
resp.forms[0]['start_date'] = datetime.date(2019, 7, 1)
@ -229,8 +230,9 @@ def test_download_transaction(app, admin_user, regie):
assert row[1] == trans1.bank_transaction_id
assert row[3] == '%s %s' % (user.first_name, user.last_name)
assert Decimal(row[4]) == Decimal(trans1.amount)
assert row[5] == b_item.subject
assert Decimal(row[6]) == b_item.amount
assert row[5] == regie.label
assert row[6] == b_item.subject
assert Decimal(row[7]) == b_item.amount
def test_transactions_search(app, admin_user, payment_backend, regie):