Added the transaction sorting in the accounting application.

This commit is contained in:
2020-08-06 23:51:20 +08:00
parent 9d49815462
commit f970974e71
8 changed files with 385 additions and 27 deletions

View File

@ -179,6 +179,16 @@ class Transaction(DirtyFieldsMixin, models.Model):
return sum([x.amount for x in self.debit_records
if isinstance(x.amount, int)])
@property
def debit_summaries(self):
"""The summaries of the debit records.
Returns:
list[str]: The summaries of the debit records.
"""
return [x.account.title if x.summary is None else x.summary
for x in self.debit_records]
@property
def credit_records(self):
"""The credit records of this transaction.
@ -193,6 +203,25 @@ class Transaction(DirtyFieldsMixin, models.Model):
return sum([x.amount for x in self.credit_records
if isinstance(x.amount, int)])
@property
def credit_summaries(self):
"""The summaries of the credit records.
Returns:
list[str]: The summaries of the credit records.
"""
return [x.account.title if x.summary is None else x.summary
for x in self.credit_records]
@property
def amount(self):
"""The amount of this transaction.
Returns:
int: The amount of this transaction.
"""
return self.debit_total()
@property
def is_balanced(self):
"""Whether the sum of the amounts of the debit records is the