[payments] add quick and dirty invoice listing
It also implements some pagination.
This commit is contained in:
parent
311bea1674
commit
40733e9867
|
@ -1,5 +1,8 @@
|
|||
import time
|
||||
import pprint
|
||||
import locale
|
||||
import decimal
|
||||
import datetime
|
||||
|
||||
from quixote import get_request, get_response, get_session, redirect
|
||||
from quixote.directory import Directory, AccessControlled
|
||||
|
@ -147,6 +150,8 @@ class RegieDirectory(Directory):
|
|||
'%s %s' % (_('Payment notification URL:'), url)
|
||||
'</div>'
|
||||
|
||||
self.invoice_listing()
|
||||
|
||||
def get_sidebar [html] (self):
|
||||
'<ul>'
|
||||
'<li><a href="edit">%s</a></li>' % _('Edit')
|
||||
|
@ -316,6 +321,109 @@ class RegieDirectory(Directory):
|
|||
self.regie.store()
|
||||
return True
|
||||
|
||||
PAGINATION = 50
|
||||
|
||||
def monetary_amount(self, val):
|
||||
if isinstance(val, basestring):
|
||||
val = val.replace(',', '.')
|
||||
return '%.2f' % decimal.Decimal(val)
|
||||
|
||||
def get_sort_by(self):
|
||||
request = get_request()
|
||||
sort_by = request.form.get('sort_by')
|
||||
if sort_by not in ('date', 'paid_date', 'username'):
|
||||
sort_by = 'date'
|
||||
return sort_by
|
||||
|
||||
def get_invoices(self):
|
||||
sort_by = self.get_sort_by()
|
||||
invoices = Invoice.get_with_indexed_value('regie_id', self.regie.id,
|
||||
ignore_errors=True)
|
||||
if 'date' in sort_by:
|
||||
reverse = True
|
||||
key = lambda i: getattr(i, sort_by) or datetime.datetime.now()
|
||||
else:
|
||||
reverse = False
|
||||
key = lambda i: getattr(i, sort_by) or ''
|
||||
invoices.sort(reverse=reverse, key=key)
|
||||
return invoices
|
||||
|
||||
def invoice_listing [html] (self):
|
||||
request = get_request()
|
||||
get_response().add_css_include('../../themes/auquotidien/admin.css')
|
||||
if request.get_method() == 'POST':
|
||||
if 'unpay' in request.form:
|
||||
invoice_id = request.form.get('id')
|
||||
invoice = Invoice.get(invoice_id, ignore_errors=True)
|
||||
if invoice:
|
||||
invoice.paid = False
|
||||
invoice.paid_date = None
|
||||
invoice.store()
|
||||
return redirect('')
|
||||
try:
|
||||
offset = int(request.form.get('offset', 0))
|
||||
except ValueError:
|
||||
offset = 0
|
||||
'<table id="invoice-listing" borderspacing="0">'
|
||||
'<thead>'
|
||||
'<tr>'
|
||||
'<td><a href="?sort_by=date&offset=%d">Creation</a></td>' % offset
|
||||
'<td>Amount</td>'
|
||||
'<td><a href="?sort_by=paid_date&offset=%d">Paid</a></td>' % offset
|
||||
'<td><a href="?sort_by=username&offset=%d">User</a></td>' % offset
|
||||
'<td>Titre</td>'
|
||||
'<td></td>'
|
||||
'</tr>'
|
||||
'</thead>'
|
||||
invoices = self.get_invoices()
|
||||
for invoice in invoices[offset:offset+self.PAGINATION]:
|
||||
'<tbody class="invoice-rows">'
|
||||
'<tr class="invoice-row"><td>'
|
||||
misc.localstrftime(invoice.date)
|
||||
'</td><td class="amount">'
|
||||
self.monetary_amount(invoice.amount)
|
||||
'</td><td>'
|
||||
if invoice.paid:
|
||||
misc.localstrftime(invoice.paid_date)
|
||||
else:
|
||||
''
|
||||
'</td><td>'
|
||||
user = invoice.get_user()
|
||||
if user:
|
||||
user.name
|
||||
'</td><td class="subject">%s</td>' % (invoice.subject or '')
|
||||
'<td>'
|
||||
if invoice.paid:
|
||||
'<form method="post">'
|
||||
'<input type="hidden" name="id" value="%s"/> ' % invoice.id
|
||||
'<input type="submit" name="unpay" value="%s"/>' % _('Unpay')
|
||||
'</form>'
|
||||
|
||||
'</td></tr>'
|
||||
transactions = Transaction.get_with_indexed_value('invoice_ids',
|
||||
invoice.id)
|
||||
for transaction in sorted(transactions, key=lambda x: x.start):
|
||||
'<tr>'
|
||||
'<td></td>'
|
||||
'<td colspan="5">'
|
||||
'OrderID: %s' % transaction.order_id
|
||||
' Start: %s' % transaction.start
|
||||
if transaction.end:
|
||||
' End: %s' % transaction.end
|
||||
if transaction.bank_data:
|
||||
' Bank data: %r' % transaction.bank_data
|
||||
'</td>'
|
||||
'</tr>'
|
||||
'</tbody>'
|
||||
'</tbody></table>'
|
||||
if offset != 0:
|
||||
'<a href="?offset=%d>%s</a> ' % (
|
||||
max(0, offset-self.PAGINATION), _('Previous'))
|
||||
if offset + self.PAGINATION < len(invoices):
|
||||
'<a href="?offset=%d>%s</a> ' % (
|
||||
max(0, offset-self.PAGINATION), _('Previous'))
|
||||
|
||||
|
||||
class RegiesDirectory(Directory):
|
||||
_q_exports = ['', 'new']
|
||||
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
/* Regie invoice listing */
|
||||
#invoice-listing tbody {
|
||||
font-size: smaller
|
||||
}
|
||||
#invoice-listing input {
|
||||
margin: 0px;
|
||||
}
|
||||
#invoice-listing thead tr {
|
||||
margin-bottom: 5px;
|
||||
}
|
||||
#invoice-listing {
|
||||
border-spacing: 0px;
|
||||
width: 100%;
|
||||
}
|
||||
#invoice-listing tbody td {
|
||||
padding: 3px;
|
||||
}
|
||||
#invoice-listing thead td {
|
||||
border-bottom: 1px solid black;
|
||||
}
|
||||
#invoice-listing tbody:nth-child(even) {
|
||||
background: #777;
|
||||
color: white;
|
||||
}
|
||||
#invoice-listing tbody td.amount {
|
||||
text-align: right;
|
||||
}
|
|
@ -1048,5 +1048,3 @@ table#strongbox-items tr.even {
|
|||
table#strongbox-items tr.odd {
|
||||
background: #eeeeee;
|
||||
}
|
||||
|
||||
|
||||
|
|
Reference in New Issue