Adapt checkout json view

This commit is contained in:
Ludovic Stephan 2021-02-28 23:03:37 +01:00
parent d537fce257
commit b7ebd77afb
3 changed files with 15 additions and 18 deletions

View file

@ -360,7 +360,9 @@ class KPsulAccountForm(forms.ModelForm):
class KPsulCheckoutForm(forms.Form):
checkout = forms.ModelChoiceField(
queryset=None, widget=forms.Select(attrs={"id": "id_checkout_select"})
queryset=None,
widget=forms.Select(attrs={"id": "id_checkout_select"}),
empty_label=None,
)
def __init__(self, *args, **kwargs):

View file

@ -208,7 +208,7 @@ urlpatterns = [
# -----
path("k-psul/", views.kpsul, name="kfet.kpsul"),
path(
"k-psul/checkout_data",
"k-psul/checkout_data/<int:pk>",
views.kpsul_checkout_data,
name="kfet.kpsul.checkout_data",
),

View file

@ -927,20 +927,10 @@ def account_read_json(request, trigramme):
@teamkfet_required
def kpsul_checkout_data(request):
pk = request.POST.get("pk", 0)
if not pk:
pk = 0
def kpsul_checkout_data(request, pk):
data = (
Checkout.objects.annotate(
last_statement_by_first_name=F(
"statements__by__cofprofile__user__first_name"
),
last_statement_by_last_name=F(
"statements__by__cofprofile__user__last_name"
),
last_statement_by_trigramme=F("statements__by__trigramme"),
last_statement_by=F("statements__by__trigramme"),
last_statement_balance=F("statements__balance_new"),
last_statement_at=F("statements__at"),
)
@ -951,20 +941,25 @@ def kpsul_checkout_data(request):
.order_by("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",
"last_statement_by",
)
.last()
)
if data is None:
raise Http404
prefix = "last_statement_"
ls_dict = {}
for (key, value) in data.items():
if key.startswith(prefix):
ls_dict[key[len(prefix) :]] = value
data["last_statement"] = ls_dict
return JsonResponse(data)