Added the records property to Transaction to manage the records temporarily instead of record_set that requires the records to be saved first in the accounting application.

This commit is contained in:
依瑪貓 2020-07-24 19:42:48 +08:00
parent 75b5e53900
commit dc4d301891

View File

@ -96,10 +96,27 @@ class Transaction(models.Model):
db_column="updatedby",
related_name="updated_accounting_transactions")
_records = None
@property
def records(self):
"""The records of the transaction.
Returns:
list[Record]: The records.
"""
if self._records is None:
self._records = self.record_set.all()
return self._records
@records.setter
def records(self, value):
self._records = value
@property
def debit_records(self):
"""The debit records of this transaction."""
return [x for x in self.record_set.all() if not x.is_credit]
return [x for x in self.records if not x.is_credit]
@property
def debit_total(self):
@ -109,7 +126,7 @@ class Transaction(models.Model):
@property
def credit_records(self):
"""The credit records of this transaction."""
return [x for x in self.record_set.all() if x.is_credit]
return [x for x in self.records if x.is_credit]
@property
def credit_total(self):