Revised the code of the views of the account application with PEP8.

This commit is contained in:
依瑪貓 2020-07-21 20:57:59 +08:00
parent b353a3fba8
commit 7a6879951a

View File

@ -114,10 +114,8 @@ def cash(request, account_code, period_spec):
Q(transaction__in=Transaction.objects.filter( Q(transaction__in=Transaction.objects.filter(
Q(date__gte=period.start), Q(date__gte=period.start),
Q(date__lte=period.end), Q(date__lte=period.end),
Q(record__account__code__startswith= Q(record__account__code__startswith=account_code))),
current_account.code))), ~Q(account__code__startswith=account_code))
~Q(account__code__startswith=
current_account.code))
.order_by("transaction__date", "is_credit", "ord")) .order_by("transaction__date", "is_credit", "ord"))
balance_before = Record.objects\ balance_before = Record.objects\
.filter( .filter(
@ -215,10 +213,10 @@ def cash_summary(request, account_code):
~Q(account__code__startswith="11"), ~Q(account__code__startswith="11"),
~Q(account__code__startswith="12"), ~Q(account__code__startswith="12"),
~Q(account__code__startswith="21"), ~Q(account__code__startswith="21"),
~Q(account__code__startswith="22")) \ ~Q(account__code__startswith="22"))
.annotate(month=TruncMonth("transaction__date")) \ .annotate(month=TruncMonth("transaction__date"))
.values("month") \ .values("month")
.order_by("month") \ .order_by("month")
.annotate( .annotate(
debit=Coalesce( debit=Coalesce(
Sum(Case(When(is_credit=False, then=F("amount")))), Sum(Case(When(is_credit=False, then=F("amount")))),
@ -233,12 +231,11 @@ def cash_summary(request, account_code):
months = [RecordSummary(**x) for x in Record.objects months = [RecordSummary(**x) for x in Record.objects
.filter( .filter(
Q(transaction__in=Transaction.objects.filter( Q(transaction__in=Transaction.objects.filter(
record__account__code__startswith= record__account__code__startswith=account_code)),
current_account.code)), ~Q(account__code__startswith=account_code))
~Q(account__code__startswith=current_account.code)) \ .annotate(month=TruncMonth("transaction__date"))
.annotate(month=TruncMonth("transaction__date")) \ .values("month")
.values("month") \ .order_by("month")
.order_by("month") \
.annotate( .annotate(
debit=Coalesce( debit=Coalesce(
Sum(Case(When(is_credit=False, then=F("amount")))), Sum(Case(When(is_credit=False, then=F("amount")))),
@ -289,7 +286,8 @@ def ledger_default(request):
account_code = settings.ACCOUNTING["DEFAULT_LEDGER_ACCOUNT"] account_code = settings.ACCOUNTING["DEFAULT_LEDGER_ACCOUNT"]
period_spec = dateformat.format(timezone.localdate(), "Y-m") period_spec = dateformat.format(timezone.localdate(), "Y-m")
return HttpResponseRedirect( return HttpResponseRedirect(
reverse("accounting:ledger", args=(account_code, period_spec))) reverse("accounting:ledger",
args=(account_code, period_spec)))
@require_GET @require_GET
@ -400,11 +398,11 @@ def ledger_summary(request, account_code):
if current_account is None: if current_account is None:
raise Http404() raise Http404()
# The month summaries # The month summaries
months = [RecordSummary(**x) for x in Record.objects\ months = [RecordSummary(**x) for x in Record.objects
.filter(account__code__startswith=current_account.code)\ .filter(account__code__startswith=current_account.code)
.annotate(month=TruncMonth("transaction__date"))\ .annotate(month=TruncMonth("transaction__date"))
.values("month")\ .values("month")
.order_by("month")\ .order_by("month")
.annotate( .annotate(
debit=Coalesce( debit=Coalesce(
Sum(Case(When(is_credit=False, then=F("amount")))), Sum(Case(When(is_credit=False, then=F("amount")))),
@ -942,9 +940,11 @@ def _find_order_holes(records):
""" """
holes = [x["date"] for x in Transaction.objects holes = [x["date"] for x in Transaction.objects
.values("date") .values("date")
.annotate(count=Count("ord"), max=Max("ord"), min=Min("ord")) .annotate(count=Count("ord"),
.filter(~(Q(max=F("count")) & Q(min=1)))]\ max=Max("ord"),
+ [x["date"] for x in Transaction.objects min=Min("ord"))
.filter(~(Q(max=F("count")) & Q(min=1)))] +\
[x["date"] for x in Transaction.objects
.values("date", "ord") .values("date", "ord")
.annotate(count=Count("sn")) .annotate(count=Count("sn"))
.filter(~Q(count=1))] .filter(~Q(count=1))]