Moved the account code of cash from hard-coded in the codes to a class constant in the Account data model in the accounting application.
This commit is contained in:
parent
377b25f669
commit
da3e7912de
@ -51,6 +51,7 @@ class Account(DirtyFieldsMixin, models.Model):
|
||||
settings.AUTH_USER_MODEL, on_delete=models.PROTECT,
|
||||
db_column="updatedby",
|
||||
related_name="updated_accounting_accounts")
|
||||
CASH = "1111"
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(Account, self).__init__(*args, **kwargs)
|
||||
@ -225,7 +226,7 @@ class Transaction(DirtyFieldsMixin, models.Model):
|
||||
"""Whether this transaction is a cash income transaction."""
|
||||
debit_records = self.debit_records
|
||||
return (len(debit_records) == 1
|
||||
and debit_records[0].account.code == "1111"
|
||||
and debit_records[0].account.code == Account.CASH
|
||||
and debit_records[0].summary is None)
|
||||
|
||||
@property
|
||||
@ -233,7 +234,7 @@ class Transaction(DirtyFieldsMixin, models.Model):
|
||||
"""Whether this transaction is a cash expense transaction."""
|
||||
credit_records = self.credit_records
|
||||
return (len(credit_records) == 1
|
||||
and credit_records[0].account.code == "1111"
|
||||
and credit_records[0].account.code == Account.CASH
|
||||
and credit_records[0].summary is None)
|
||||
|
||||
@property
|
||||
|
@ -185,7 +185,8 @@ class Populator:
|
||||
the credit records.
|
||||
"""
|
||||
amount = sum([x[2] for x in credit])
|
||||
self.add_transfer_transaction(date, (("1111", None, amount),), credit)
|
||||
self.add_transfer_transaction(
|
||||
date, ((Account.CASH, None, amount),), credit)
|
||||
|
||||
def add_expense_transaction(self, date, debit):
|
||||
"""Adds a cash income transaction.
|
||||
@ -197,7 +198,8 @@ class Populator:
|
||||
the debit records.
|
||||
"""
|
||||
amount = sum([x[2] for x in debit])
|
||||
self.add_transfer_transaction(date, debit, (("1111", None, amount),))
|
||||
self.add_transfer_transaction(
|
||||
date, debit, ((Account.CASH, None, amount),))
|
||||
|
||||
|
||||
def get_cash_accounts():
|
||||
@ -325,8 +327,7 @@ def fill_txn_from_post(txn_type, txn, post):
|
||||
else:
|
||||
record = txn.debit_records[0]
|
||||
record.ord = 1
|
||||
# TODO: Store 1111 in the settings file
|
||||
record.account = Account.objects.get(code="1111")
|
||||
record.account = Account.objects.get(code=Account.CASH)
|
||||
record.summary = None
|
||||
record.amount = sum([x.amount for x in records])
|
||||
records.append(record)
|
||||
|
Loading…
Reference in New Issue
Block a user