Fixed and replaced the incorrect class property declaration with the instance property declaration, and replaced unnecessary pseudo properties with instance properties.

This commit is contained in:
2020-08-02 01:04:47 +08:00
parent fda8a2c523
commit 1b89fef01c
4 changed files with 236 additions and 282 deletions

@ -51,10 +51,17 @@ class Account(models.Model):
db_column="updatedby",
related_name="updated_accounting_accounts")
def __init__(self, *args, **kwargs):
super(Account, self).__init__(*args, **kwargs)
self.url = None
def __str__(self):
"""Returns the string representation of this account."""
return self.code.__str__() + " " + self.title
class Meta:
db_table = "accounting_accounts"
@property
def title(self):
return get_multi_lingual_attr(self, "title")
@ -63,19 +70,6 @@ class Account(models.Model):
def title(self, value):
set_multi_lingual_attr(self, "title", value)
_url = None
@property
def url(self):
return self._url
@url.setter
def url(self, value):
self._url = value
class Meta:
db_table = "accounting_accounts"
class Transaction(models.Model):
"""An accounting transaction."""
@ -96,7 +90,19 @@ class Transaction(models.Model):
db_column="updatedby",
related_name="updated_accounting_transactions")
_records = None
def __init__(self, *args, **kwargs):
super(Transaction, self).__init__(*args, **kwargs)
self._records = None
self._is_balanced = None
self._has_order_hole = None
def __str__(self):
"""Returns the string representation of this accounting
transaction."""
return self.date.__str__() + " #" + self.ord.__str__()
class Meta:
db_table = "accounting_transactions"
@property
def records(self):
@ -143,8 +149,6 @@ class Transaction(models.Model):
return sum([x.amount for x in self.credit_records
if isinstance(x.amount, int)])
_is_balanced = None
@property
def is_balanced(self):
"""Whether the sum of the amounts of the debit records is the
@ -165,8 +169,6 @@ class Transaction(models.Model):
so that the user can sort their orders. """
return Transaction.objects.filter(date=self.date).count() > 1
_has_order_hole = None
@property
def has_order_hole(self):
"""Whether the order of the transactions on this day is not
@ -228,14 +230,6 @@ class Transaction(models.Model):
return reverse(
"accounting:transactions.show", args=("transfer", self))
def __str__(self):
"""Returns the string representation of this accounting
transaction."""
return self.date.__str__() + " #" + self.ord.__str__()
class Meta:
db_table = "accounting_transactions"
class Record(models.Model):
"""An accounting record."""
@ -262,94 +256,15 @@ class Record(models.Model):
db_column="updatedby",
related_name="updated_accounting_records")
_debit_amount = None
@property
def debit_amount(self):
"""The debit amount of this accounting record"""
if self._debit_amount is not None:
return self._debit_amount
return self.amount if not self.is_credit else None
@debit_amount.setter
def debit_amount(self, value):
self._debit_amount = value
_credit_amount = None
@property
def credit_amount(self):
"""The credit amount of this accounting record"""
if self._credit_amount is not None:
return self._credit_amount
return self.amount if self.is_credit else None
@credit_amount.setter
def credit_amount(self, value):
self._credit_amount = value
_balance = None
@property
def balance(self):
return self._balance
@balance.setter
def balance(self, value):
self._balance = value
_is_balanced = None
@property
def is_balanced(self):
"""Whether the transaction of this record is balanced. """
if self._is_balanced is None:
self._is_balanced = self.transaction.is_balanced
return self._is_balanced
@is_balanced.setter
def is_balanced(self, value):
self._is_balanced = value
_has_order_hole = None
@property
def has_order_hole(self):
"""Whether the order of the transactions on this day is not
1, 2, 3, 4, 5..., and should be reordered. """
if self._has_order_hole is None:
self._has_order_hole = self.transaction.has_order_hole
return self._has_order_hole
@has_order_hole.setter
def has_order_hole(self, value):
self._has_order_hole = value
_is_credit_card_paid = None
@property
def is_credit_card_paid(self):
# TODO: To be done
if self._is_credit_card_paid is None:
self._is_credit_card_paid = True
return self._is_credit_card_paid
@is_credit_card_paid.setter
def is_credit_card_paid(self, value):
self._is_credit_card_paid = value
_is_existing_equipment = None
@property
def is_existing_equipment(self):
# TODO: To be done
if self._is_existing_equipment is None:
self._is_existing_equipment = False
return self._is_existing_equipment
@is_existing_equipment.setter
def is_existing_equipment(self, value):
self._is_existing_equipment = value
def __init__(self, *args, **kwargs):
super(Record, self).__init__(*args, **kwargs)
self._debit_amount = None
self._credit_amount = None
self._balance = None
self._is_balanced = None
self._has_order_hole = None
self._is_credit_card_paid = None
self._is_existing_equipment = None
def __str__(self):
"""Returns the string representation of this accounting
@ -363,6 +278,81 @@ class Record(models.Model):
class Meta:
db_table = "accounting_records"
@property
def debit_amount(self):
"""The debit amount of this accounting record"""
if self._debit_amount is not None:
return self._debit_amount
return self.amount if not self.is_credit else None
@debit_amount.setter
def debit_amount(self, value):
self._debit_amount = value
@property
def credit_amount(self):
"""The credit amount of this accounting record"""
if self._credit_amount is not None:
return self._credit_amount
return self.amount if self.is_credit else None
@credit_amount.setter
def credit_amount(self, value):
self._credit_amount = value
@property
def balance(self):
return self._balance
@balance.setter
def balance(self, value):
self._balance = value
@property
def is_balanced(self):
"""Whether the transaction of this record is balanced. """
if self._is_balanced is None:
self._is_balanced = self.transaction.is_balanced
return self._is_balanced
@is_balanced.setter
def is_balanced(self, value):
self._is_balanced = value
@property
def has_order_hole(self):
"""Whether the order of the transactions on this day is not
1, 2, 3, 4, 5..., and should be reordered. """
if self._has_order_hole is None:
self._has_order_hole = self.transaction.has_order_hole
return self._has_order_hole
@has_order_hole.setter
def has_order_hole(self, value):
self._has_order_hole = value
@property
def is_credit_card_paid(self):
# TODO: To be done
if self._is_credit_card_paid is None:
self._is_credit_card_paid = True
return self._is_credit_card_paid
@is_credit_card_paid.setter
def is_credit_card_paid(self, value):
self._is_credit_card_paid = value
@property
def is_existing_equipment(self):
# TODO: To be done
if self._is_existing_equipment is None:
self._is_existing_equipment = False
return self._is_existing_equipment
@is_existing_equipment.setter
def is_existing_equipment(self, value):
self._is_existing_equipment = value
class RecordSummary(models.Model):
"""A summary record."""
@ -371,7 +361,14 @@ class RecordSummary(models.Model):
debit = models.PositiveIntegerField()
balance = models.IntegerField()
_label = None
def __init__(self, *args, **kwargs):
super(RecordSummary, self).__init__(*args, **kwargs)
self._label = None
self._cumulative_balance = None
class Meta:
db_table = None
managed = False
@property
def label(self):
@ -383,8 +380,6 @@ class RecordSummary(models.Model):
def label(self, value):
self._label = value
_cumulative_balance = None
@property
def cumulative_balance(self):
return self._cumulative_balance
@ -392,7 +387,3 @@ class RecordSummary(models.Model):
@cumulative_balance.setter
def cumulative_balance(self, value):
self._cumulative_balance = value
class Meta:
db_table = None
managed = False

@ -54,9 +54,6 @@ class ReportUrl:
income_statement (str): The URL of the income statement.
balance_sheet (str): The URL of the balance sheet.
"""
_period = None
_cash = None
_ledger = None
def __init__(self, **kwargs):
if "period" in kwargs:
@ -74,37 +71,29 @@ class ReportUrl:
self._ledger = Account.objects.get(
code=settings.ACCOUNTING["DEFAULT_LEDGER_ACCOUNT"])
@property
def cash(self):
return reverse(
"accounting:cash", args=(self._cash, self._period))
@property
def cash_summary(self):
return reverse("accounting:cash-summary", args=(self._cash,))
@property
def ledger(self):
return reverse(
"accounting:ledger", args=(self._ledger, self._period))
@property
def ledger_summary(self):
return reverse("accounting:ledger-summary", args=(self._ledger,))
@property
def journal(self):
return reverse("accounting:journal", args=(self._period,))
@property
def trial_balance(self):
return reverse("accounting:trial-balance", args=(self._period,))
@property
def income_statement(self):
return reverse("accounting:income-statement", args=(self._period,))
@property
def balance_sheet(self):
return reverse("accounting:balance-sheet", args=(self._period,))
@ -118,7 +107,6 @@ class Populator:
Attributes:
user (User): The user in action.
"""
user = None
def __init__(self, user):
self.user = user