forked from DGNum/gestioCOF
Adapt checkout json view
This commit is contained in:
parent
d537fce257
commit
b7ebd77afb
3 changed files with 15 additions and 18 deletions
|
@ -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):
|
||||
|
|
|
@ -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",
|
||||
),
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue