Revised the has_order_hole attribute of the accounting transaction data model.

This commit is contained in:
依瑪貓 2020-07-07 19:33:34 +08:00
parent 83f97a6467
commit a26247f752
2 changed files with 15 additions and 2 deletions

View File

@ -117,8 +117,10 @@ class Transaction(models.Model):
1, 2, 3, 4, 5..., and should be reordered. """ 1, 2, 3, 4, 5..., and should be reordered. """
if self._has_order_hole is None: if self._has_order_hole is None:
orders = [x.ord for x in Transaction.objects.filter( orders = [x.ord for x in Transaction.objects.filter(
date=self.date).order_by("-ord")] date=self.date)]
if orders[0] != len(orders): if max(orders) != len(orders):
self._has_order_hole = True
elif min(orders) != 1:
self._has_order_hole = True self._has_order_hole = True
elif len(orders) != len(set(orders)): elif len(orders) != len(set(orders)):
self._has_order_hole = True self._has_order_hole = True

View File

@ -110,6 +110,7 @@ class BaseReportView(generic.ListView):
return HttpResponseRedirect( return HttpResponseRedirect(
str(UrlBuilder(request.get_full_path()) str(UrlBuilder(request.get_full_path())
.del_param("page"))) .del_param("page")))
print("accounting.views.BaseReportView.get() 1 before")
try: try:
r = super(BaseReportView, self) \ r = super(BaseReportView, self) \
.get(request, *args, **kwargs) .get(request, *args, **kwargs)
@ -117,6 +118,14 @@ class BaseReportView(generic.ListView):
return HttpResponseRedirect( return HttpResponseRedirect(
str(UrlBuilder(request.get_full_path()) str(UrlBuilder(request.get_full_path())
.del_param("page"))) .del_param("page")))
print("accounting.views.BaseReportView.get() 2 after")
return r
def get_context_data(self, **kwargs):
print("accounting.views.BaseReportView.get_context_data() 1 before")
r = super(BaseReportView, self).get_context_data(**kwargs)
print("accounting.views.BaseReportView.get_context_data() 2 after")
print(r)
return r return r
@ -132,6 +141,7 @@ class CashReportView(BaseReportView):
Returns: Returns:
List[Record]: The accounting records for the cash report List[Record]: The accounting records for the cash report
""" """
print("accounting.views.CashReportView.get_queryset() 1 before")
period = PeriodParser(self.kwargs["period_spec"]) period = PeriodParser(self.kwargs["period_spec"])
if self.kwargs["subject_code"] == "0": if self.kwargs["subject_code"] == "0":
records = Record.objects.raw( records = Record.objects.raw(
@ -197,4 +207,5 @@ ORDER BY
pagination = Pagination( pagination = Pagination(
len(records), self.page_no, self.page_size, True) len(records), self.page_no, self.page_size, True)
start_no = pagination.page_size * (pagination.page_no - 1) start_no = pagination.page_size * (pagination.page_no - 1)
print("accounting.views.CashReportView.get_queryset() 2 after")
return records[start_no:start_no + pagination.page_size] return records[start_no:start_no + pagination.page_size]