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,
|
settings.AUTH_USER_MODEL, on_delete=models.PROTECT,
|
||||||
db_column="updatedby",
|
db_column="updatedby",
|
||||||
related_name="updated_accounting_accounts")
|
related_name="updated_accounting_accounts")
|
||||||
|
CASH = "1111"
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
super(Account, self).__init__(*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."""
|
"""Whether this transaction is a cash income transaction."""
|
||||||
debit_records = self.debit_records
|
debit_records = self.debit_records
|
||||||
return (len(debit_records) == 1
|
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)
|
and debit_records[0].summary is None)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@ -233,7 +234,7 @@ class Transaction(DirtyFieldsMixin, models.Model):
|
|||||||
"""Whether this transaction is a cash expense transaction."""
|
"""Whether this transaction is a cash expense transaction."""
|
||||||
credit_records = self.credit_records
|
credit_records = self.credit_records
|
||||||
return (len(credit_records) == 1
|
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)
|
and credit_records[0].summary is None)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
@ -185,7 +185,8 @@ class Populator:
|
|||||||
the credit records.
|
the credit records.
|
||||||
"""
|
"""
|
||||||
amount = sum([x[2] for x in credit])
|
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):
|
def add_expense_transaction(self, date, debit):
|
||||||
"""Adds a cash income transaction.
|
"""Adds a cash income transaction.
|
||||||
@ -197,7 +198,8 @@ class Populator:
|
|||||||
the debit records.
|
the debit records.
|
||||||
"""
|
"""
|
||||||
amount = sum([x[2] for x in debit])
|
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():
|
def get_cash_accounts():
|
||||||
@ -325,8 +327,7 @@ def fill_txn_from_post(txn_type, txn, post):
|
|||||||
else:
|
else:
|
||||||
record = txn.debit_records[0]
|
record = txn.debit_records[0]
|
||||||
record.ord = 1
|
record.ord = 1
|
||||||
# TODO: Store 1111 in the settings file
|
record.account = Account.objects.get(code=Account.CASH)
|
||||||
record.account = Account.objects.get(code="1111")
|
|
||||||
record.summary = None
|
record.summary = None
|
||||||
record.amount = sum([x.amount for x in records])
|
record.amount = sum([x.amount for x in records])
|
||||||
records.append(record)
|
records.append(record)
|
||||||
|
Loading…
Reference in New Issue
Block a user