fix checkout data error on k-psul
This commit is contained in:
parent
e1713a1d4f
commit
a98c6b233e
1 changed files with 27 additions and 21 deletions
|
@ -841,34 +841,40 @@ def account_read_json(request):
|
|||
'trigramme': account.trigramme }
|
||||
return JsonResponse(data)
|
||||
|
||||
|
||||
@teamkfet_required
|
||||
def kpsul_checkout_data(request):
|
||||
pk = request.POST.get('pk', 0)
|
||||
if not pk:
|
||||
pk = 0
|
||||
data = (Checkout.objects
|
||||
.annotate(
|
||||
last_statement_by_first_name=F('statements__by__profile__user__first_name'),
|
||||
last_statement_by_last_name=F('statements__by__profile__user__last_name'),
|
||||
last_statement_by_trigramme=F('statements__by__trigramme'),
|
||||
last_statement_balance=F('statements__balance_new'),
|
||||
last_statement_at=F('statements__at'))
|
||||
.values(
|
||||
'id', 'name', 'balance', 'valid_from', 'valid_to',
|
||||
'last_statement_balance', 'last_statement_at',
|
||||
'last_statement_by_trigramme', 'last_statement_by_last_name',
|
||||
'last_statement_by_first_name')
|
||||
.select_related(
|
||||
'statements'
|
||||
'statements__by',
|
||||
'statements__by__profile__user')
|
||||
.filter(pk=pk)
|
||||
.order_by('statements__at')
|
||||
.last())
|
||||
if data is None:
|
||||
raise Http404
|
||||
|
||||
checkout = get_object_or_404(Checkout, pk=pk)
|
||||
data = {
|
||||
'id': checkout.id, 'name': checkout.name, 'balance': checkout.balance,
|
||||
'valid_from': checkout.valid_from, 'valid_to': checkout.valid_to
|
||||
}
|
||||
|
||||
try:
|
||||
last_statement = (
|
||||
CheckoutStatement
|
||||
.objects
|
||||
.select_related('by', 'by__profile', 'by__profile__user')
|
||||
.filter(checkout=checkout)
|
||||
.latest('at')
|
||||
)
|
||||
data['last_statement_balance'] = last_statement.balance_new
|
||||
data['last_statement_at'] = last_statement.at
|
||||
data['last_statement_by_trigramme'] = last_statement.by.trigramme
|
||||
data['last_statement_by_last_name'] = \
|
||||
last_statement.by.profile.user.last_name
|
||||
data['last_statement_by_first_name'] = \
|
||||
last_statement.by.profile.user.first_name
|
||||
except CheckoutStatement.DoesNotExist:
|
||||
pass
|
||||
|
||||
return JsonResponse(data)
|
||||
|
||||
|
||||
@teamkfet_required
|
||||
def kpsul_update_addcost(request):
|
||||
addcost_form = AddcostForm(request.POST)
|
||||
|
|
Loading…
Reference in a new issue