Revised the code according to the PyCharm and PEP8 inspection.
This commit is contained in:
parent
dc14f2e27a
commit
0243289946
@ -80,8 +80,8 @@ class Transaction(models.Model):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def is_balanced(self):
|
def is_balanced(self):
|
||||||
"""Whether the sum of the amounts of the debit records is the same as the sum of the amounts of the credit
|
"""Whether the sum of the amounts of the debit records is the
|
||||||
records. """
|
same as the sum of the amounts of the credit records. """
|
||||||
debit_sum = sum([x.amount for x in self.debit_records])
|
debit_sum = sum([x.amount for x in self.debit_records])
|
||||||
credit_sum = sum([x.amount for x in self.credit_records])
|
credit_sum = sum([x.amount for x in self.credit_records])
|
||||||
return debit_sum == credit_sum
|
return debit_sum == credit_sum
|
||||||
@ -105,11 +105,14 @@ class Transaction(models.Model):
|
|||||||
def get_absolute_url(self):
|
def get_absolute_url(self):
|
||||||
"""Returns the URL to view this transaction."""
|
"""Returns the URL to view this transaction."""
|
||||||
if self.is_cash_expense:
|
if self.is_cash_expense:
|
||||||
return reverse("accounting:transaction", args=("expense", self.sn))
|
return reverse(
|
||||||
|
"accounting:transaction", args=("expense", self.sn))
|
||||||
elif self.is_cash_income:
|
elif self.is_cash_income:
|
||||||
return reverse("accounting:transaction", args=("income", self.sn))
|
return reverse(
|
||||||
|
"accounting:transaction", args=("income", self.sn))
|
||||||
else:
|
else:
|
||||||
return reverse("accounting:transaction", args=("transfer", self.sn))
|
return reverse(
|
||||||
|
"accounting:transaction", args=("transfer", self.sn))
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
"""Returns the string representation of this accounting
|
"""Returns the string representation of this accounting
|
||||||
@ -163,10 +166,11 @@ class Record(models.Model):
|
|||||||
def __str__(self):
|
def __str__(self):
|
||||||
"""Returns the string representation of this accounting
|
"""Returns the string representation of this accounting
|
||||||
record."""
|
record."""
|
||||||
return self.transaction.date.__str__() + " " \
|
return "%s %s %s %s" % (
|
||||||
+ self.subject.title_zhtw.__str__() \
|
self.transaction.date,
|
||||||
+ " " + self.summary.__str__() \
|
self.subject.title_zhtw,
|
||||||
+ " " + self.amount.__str__()
|
self.summary,
|
||||||
|
self.amount)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
db_table = "accounting_records"
|
db_table = "accounting_records"
|
||||||
|
@ -41,7 +41,10 @@ app_name = "accounting"
|
|||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path("", views.home, name="home"),
|
path("", views.home, name="home"),
|
||||||
path("cash", views.cash_home, name="cash.home"),
|
path("cash", views.cash_home, name="cash.home"),
|
||||||
path("cash/<str:subject_code>/<str:period_spec>", views.CashReportView.as_view(), name="cash"),
|
path("cash/<str:subject_code>/<str:period_spec>",
|
||||||
path("transactions/<txn-type:type>/<int:pk>", views.CashReportView.as_view(), name="transaction"),
|
views.CashReportView.as_view(), name="cash"),
|
||||||
path("transactions/<txn-type:type>/<int:pk>/edit", views.CashReportView.as_view(), name="transaction.edit"),
|
path("transactions/<txn-type:type>/<int:pk>",
|
||||||
|
views.CashReportView.as_view(), name="transaction"),
|
||||||
|
path("transactions/<txn-type:type>/<int:pk>/edit",
|
||||||
|
views.CashReportView.as_view(), name="transaction.edit"),
|
||||||
]
|
]
|
||||||
|
@ -61,7 +61,7 @@ class Pagination:
|
|||||||
|
|
||||||
DEFAULT_PAGE_SIZE = 10
|
DEFAULT_PAGE_SIZE = 10
|
||||||
|
|
||||||
def __init__(self, count, page_no, page_size, is_reverse = False):
|
def __init__(self, count, page_no, page_size, is_reverse=False):
|
||||||
self.page_size = page_size \
|
self.page_size = page_size \
|
||||||
if page_size is not None \
|
if page_size is not None \
|
||||||
else self.DEFAULT_PAGE_SIZE
|
else self.DEFAULT_PAGE_SIZE
|
||||||
|
@ -104,7 +104,8 @@ class BaseReportView(generic.ListView):
|
|||||||
str(UrlBuilder(request.get_full_path())
|
str(UrlBuilder(request.get_full_path())
|
||||||
.del_param("page")))
|
.del_param("page")))
|
||||||
try:
|
try:
|
||||||
r = super(BaseReportView, self).get(request, *args, **kwargs)
|
r = super(BaseReportView, self) \
|
||||||
|
.get(request, *args, **kwargs)
|
||||||
except PageNoOutOfRangeError:
|
except PageNoOutOfRangeError:
|
||||||
return HttpResponseRedirect(
|
return HttpResponseRedirect(
|
||||||
str(UrlBuilder(request.get_full_path())
|
str(UrlBuilder(request.get_full_path())
|
||||||
@ -143,7 +144,7 @@ FROM accounting_records AS r
|
|||||||
OR s1.code LIKE '21%%'
|
OR s1.code LIKE '21%%'
|
||||||
OR s1.code LIKE '22%%')
|
OR s1.code LIKE '22%%')
|
||||||
AND t1.date >= %s
|
AND t1.date >= %s
|
||||||
AND t1.date <= %s
|
AND t1.date <= %s
|
||||||
GROUP BY t1.sn) AS t
|
GROUP BY t1.sn) AS t
|
||||||
ON r.transaction_sn=t.sn
|
ON r.transaction_sn=t.sn
|
||||||
LEFT JOIN accounting_subjects AS s ON r.subject_sn = s.sn
|
LEFT JOIN accounting_subjects AS s ON r.subject_sn = s.sn
|
||||||
@ -171,7 +172,7 @@ FROM accounting_records AS r
|
|||||||
LEFT JOIN accounting_subjects AS s1
|
LEFT JOIN accounting_subjects AS s1
|
||||||
ON r1.subject_sn = s1.sn
|
ON r1.subject_sn = s1.sn
|
||||||
WHERE t1.date >= %s
|
WHERE t1.date >= %s
|
||||||
AND t1.date <= %s
|
AND t1.date <= %s
|
||||||
AND s1.code LIKE %s
|
AND s1.code LIKE %s
|
||||||
GROUP BY t1.sn) AS t
|
GROUP BY t1.sn) AS t
|
||||||
ON r.transaction_sn=t.sn
|
ON r.transaction_sn=t.sn
|
||||||
|
@ -14,7 +14,6 @@
|
|||||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
import locale
|
|
||||||
from datetime import date
|
from datetime import date
|
||||||
|
|
||||||
from django import template
|
from django import template
|
||||||
|
Loading…
Reference in New Issue
Block a user