Revised the code according to the PyCharm and PEP8 inspection.

This commit is contained in:
依瑪貓 2020-07-02 09:45:11 +08:00
parent dc14f2e27a
commit 0243289946
5 changed files with 24 additions and 17 deletions

View File

@ -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"

View File

@ -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"),
] ]

View File

@ -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())

View File

@ -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