Added the BaseTestData class in testlib_offset.py to simplify the test data, and changed the TestData, DifferentTestData, and SameTestData classes to its subclasses.
This commit is contained in:
parent
51f0185bcf
commit
87f9063ceb
@ -26,9 +26,7 @@ from flask.testing import FlaskCliRunner
|
|||||||
|
|
||||||
from test_site import db
|
from test_site import db
|
||||||
from testlib import create_test_app, get_client, Accounts
|
from testlib import create_test_app, get_client, Accounts
|
||||||
from testlib_journal_entry import match_journal_entry_detail
|
from testlib_offset import BaseTestData, JournalEntryData, CurrencyData
|
||||||
from testlib_offset import JournalEntryData, CurrencyData, \
|
|
||||||
JournalEntryLineItemData
|
|
||||||
|
|
||||||
PREFIX: str = "/accounting/unmatched-offsets"
|
PREFIX: str = "/accounting/unmatched-offsets"
|
||||||
"""The URL prefix for the unmatched offset management."""
|
"""The URL prefix for the unmatched offset management."""
|
||||||
@ -408,51 +406,28 @@ class UnmatchedOffsetTestCase(unittest.TestCase):
|
|||||||
self.assertEqual(line_item.original_line_item_id, data.l_p_or4c.id)
|
self.assertEqual(line_item.original_line_item_id, data.l_p_or4c.id)
|
||||||
|
|
||||||
|
|
||||||
class DifferentTestData:
|
class DifferentTestData(BaseTestData):
|
||||||
"""The test data for different descriptions and amounts."""
|
"""The test data for different descriptions and amounts."""
|
||||||
|
|
||||||
def __init__(self, app: Flask, client: httpx.Client, csrf_token: str):
|
def _init_data(self) -> None:
|
||||||
"""Constructs the test data.
|
|
||||||
|
|
||||||
:param app: The Flask application.
|
|
||||||
:param client: The client.
|
|
||||||
:param csrf_token: The CSRF token.
|
|
||||||
"""
|
|
||||||
self.app: Flask = app
|
|
||||||
self.client: httpx.Client = client
|
|
||||||
self.csrf_token: str = csrf_token
|
|
||||||
|
|
||||||
def couple(description: str, amount: str, debit: str, credit: str) \
|
|
||||||
-> tuple[JournalEntryLineItemData, JournalEntryLineItemData]:
|
|
||||||
"""Returns a couple of debit-credit line items.
|
|
||||||
|
|
||||||
:param description: The description.
|
|
||||||
:param amount: The amount.
|
|
||||||
:param debit: The debit account code.
|
|
||||||
:param credit: The credit account code.
|
|
||||||
:return: The debit line item and credit line item.
|
|
||||||
"""
|
|
||||||
return JournalEntryLineItemData(debit, description, amount),\
|
|
||||||
JournalEntryLineItemData(credit, description, amount)
|
|
||||||
|
|
||||||
# Receivable original line items
|
# Receivable original line items
|
||||||
self.l_r_or1d, self.l_r_or1c = couple(
|
self.l_r_or1d, self.l_r_or1c = self._couple(
|
||||||
"Accountant", "1200", Accounts.RECEIVABLE, Accounts.SERVICE)
|
"Accountant", "1200", Accounts.RECEIVABLE, Accounts.SERVICE)
|
||||||
self.l_r_or2d, self.l_r_or2c = couple(
|
self.l_r_or2d, self.l_r_or2c = self._couple(
|
||||||
"Toy", "600", Accounts.RECEIVABLE, Accounts.SALES)
|
"Toy", "600", Accounts.RECEIVABLE, Accounts.SALES)
|
||||||
self.l_r_or3d, self.l_r_or3c = couple(
|
self.l_r_or3d, self.l_r_or3c = self._couple(
|
||||||
"Noodles", "100", Accounts.RECEIVABLE, Accounts.SALES)
|
"Noodles", "100", Accounts.RECEIVABLE, Accounts.SALES)
|
||||||
self.l_r_or4d, self.l_r_or4c = couple(
|
self.l_r_or4d, self.l_r_or4c = self._couple(
|
||||||
"Interest", "3.4", Accounts.RECEIVABLE, Accounts.INTEREST)
|
"Interest", "3.4", Accounts.RECEIVABLE, Accounts.INTEREST)
|
||||||
|
|
||||||
# Payable original line items
|
# Payable original line items
|
||||||
self.l_p_or1d, self.l_p_or1c = couple(
|
self.l_p_or1d, self.l_p_or1c = self._couple(
|
||||||
"Airplane", "2000", Accounts.TRAVEL, Accounts.PAYABLE)
|
"Airplane", "2000", Accounts.TRAVEL, Accounts.PAYABLE)
|
||||||
self.l_p_or2d, self.l_p_or2c = couple(
|
self.l_p_or2d, self.l_p_or2c = self._couple(
|
||||||
"Phone", "900", Accounts.OFFICE, Accounts.PAYABLE)
|
"Phone", "900", Accounts.OFFICE, Accounts.PAYABLE)
|
||||||
self.l_p_or3d, self.l_p_or3c = couple(
|
self.l_p_or3d, self.l_p_or3c = self._couple(
|
||||||
"Steak", "120", Accounts.MEAL, Accounts.PAYABLE)
|
"Steak", "120", Accounts.MEAL, Accounts.PAYABLE)
|
||||||
self.l_p_or4d, self.l_p_or4c = couple(
|
self.l_p_or4d, self.l_p_or4c = self._couple(
|
||||||
"Envelop", "0.9", Accounts.OFFICE, Accounts.PAYABLE)
|
"Envelop", "0.9", Accounts.OFFICE, Accounts.PAYABLE)
|
||||||
|
|
||||||
# Original journal entries
|
# Original journal entries
|
||||||
@ -469,33 +444,33 @@ class DifferentTestData:
|
|||||||
20, [CurrencyData("USD", [self.l_p_or2d, self.l_p_or3d],
|
20, [CurrencyData("USD", [self.l_p_or2d, self.l_p_or3d],
|
||||||
[self.l_p_or2c, self.l_p_or3c])])
|
[self.l_p_or2c, self.l_p_or3c])])
|
||||||
|
|
||||||
self.__add_journal_entry(self.j_r_or1)
|
self._add_journal_entry(self.j_r_or1)
|
||||||
self.__add_journal_entry(self.j_r_or2)
|
self._add_journal_entry(self.j_r_or2)
|
||||||
self.__add_journal_entry(self.j_p_or1)
|
self._add_journal_entry(self.j_p_or1)
|
||||||
self.__add_journal_entry(self.j_p_or2)
|
self._add_journal_entry(self.j_p_or2)
|
||||||
|
|
||||||
# Receivable offset items
|
# Receivable offset items
|
||||||
self.l_r_of1d, self.l_r_of1c = couple(
|
self.l_r_of1d, self.l_r_of1c = self._couple(
|
||||||
"Accountant", "500", Accounts.CASH, Accounts.RECEIVABLE)
|
"Accountant", "500", Accounts.CASH, Accounts.RECEIVABLE)
|
||||||
self.l_r_of2d, self.l_r_of2c = couple(
|
self.l_r_of2d, self.l_r_of2c = self._couple(
|
||||||
"Accountant", "200", Accounts.CASH, Accounts.RECEIVABLE)
|
"Accountant", "200", Accounts.CASH, Accounts.RECEIVABLE)
|
||||||
self.l_r_of3d, self.l_r_of3c = couple(
|
self.l_r_of3d, self.l_r_of3c = self._couple(
|
||||||
"Accountant", "100", Accounts.CASH, Accounts.RECEIVABLE)
|
"Accountant", "100", Accounts.CASH, Accounts.RECEIVABLE)
|
||||||
self.l_r_of4d, self.l_r_of4c = couple(
|
self.l_r_of4d, self.l_r_of4c = self._couple(
|
||||||
"Toy", "240", Accounts.CASH, Accounts.RECEIVABLE)
|
"Toy", "240", Accounts.CASH, Accounts.RECEIVABLE)
|
||||||
self.l_r_of5d, self.l_r_of5c = couple(
|
self.l_r_of5d, self.l_r_of5c = self._couple(
|
||||||
"Interest", "3.4", Accounts.CASH, Accounts.RECEIVABLE)
|
"Interest", "3.4", Accounts.CASH, Accounts.RECEIVABLE)
|
||||||
|
|
||||||
# Payable offset items
|
# Payable offset items
|
||||||
self.l_p_of1d, self.l_p_of1c = couple(
|
self.l_p_of1d, self.l_p_of1c = self._couple(
|
||||||
"Airplane", "800", Accounts.PAYABLE, Accounts.CASH)
|
"Airplane", "800", Accounts.PAYABLE, Accounts.CASH)
|
||||||
self.l_p_of2d, self.l_p_of2c = couple(
|
self.l_p_of2d, self.l_p_of2c = self._couple(
|
||||||
"Airplane", "300", Accounts.PAYABLE, Accounts.CASH)
|
"Airplane", "300", Accounts.PAYABLE, Accounts.CASH)
|
||||||
self.l_p_of3d, self.l_p_of3c = couple(
|
self.l_p_of3d, self.l_p_of3c = self._couple(
|
||||||
"Airplane", "100", Accounts.PAYABLE, Accounts.CASH)
|
"Airplane", "100", Accounts.PAYABLE, Accounts.CASH)
|
||||||
self.l_p_of4d, self.l_p_of4c = couple(
|
self.l_p_of4d, self.l_p_of4c = self._couple(
|
||||||
"Phone", "400", Accounts.PAYABLE, Accounts.CASH)
|
"Phone", "400", Accounts.PAYABLE, Accounts.CASH)
|
||||||
self.l_p_of5d, self.l_p_of5c = couple(
|
self.l_p_of5d, self.l_p_of5c = self._couple(
|
||||||
"Envelop", "0.9", Accounts.PAYABLE, Accounts.CASH)
|
"Envelop", "0.9", Accounts.PAYABLE, Accounts.CASH)
|
||||||
|
|
||||||
# Offset journal entries
|
# Offset journal entries
|
||||||
@ -516,112 +491,48 @@ class DifferentTestData:
|
|||||||
self.j_p_of3: JournalEntryData = JournalEntryData(
|
self.j_p_of3: JournalEntryData = JournalEntryData(
|
||||||
5, [CurrencyData("USD", [self.l_p_of5d], [self.l_p_of5c])])
|
5, [CurrencyData("USD", [self.l_p_of5d], [self.l_p_of5c])])
|
||||||
|
|
||||||
self.__set_is_need_offset(False)
|
self._set_is_need_offset({Accounts.RECEIVABLE, Accounts.PAYABLE},
|
||||||
self.__add_journal_entry(self.j_r_of1)
|
False)
|
||||||
self.__add_journal_entry(self.j_r_of2)
|
self._add_journal_entry(self.j_r_of1)
|
||||||
self.__add_journal_entry(self.j_r_of3)
|
self._add_journal_entry(self.j_r_of2)
|
||||||
self.__add_journal_entry(self.j_p_of1)
|
self._add_journal_entry(self.j_r_of3)
|
||||||
self.__add_journal_entry(self.j_p_of2)
|
self._add_journal_entry(self.j_p_of1)
|
||||||
self.__add_journal_entry(self.j_p_of3)
|
self._add_journal_entry(self.j_p_of2)
|
||||||
self.__set_is_need_offset(True)
|
self._add_journal_entry(self.j_p_of3)
|
||||||
|
self._set_is_need_offset({Accounts.RECEIVABLE, Accounts.PAYABLE},
|
||||||
def __set_is_need_offset(self, is_need_offset: bool) -> None:
|
True)
|
||||||
"""Sets whether the payables and receivables need offset.
|
|
||||||
|
|
||||||
:param is_need_offset: True if payables and receivables need offset, or
|
|
||||||
False otherwise.
|
|
||||||
:return:
|
|
||||||
"""
|
|
||||||
from accounting.models import Account
|
|
||||||
with self.app.app_context():
|
|
||||||
for code in {Accounts.RECEIVABLE, Accounts.PAYABLE}:
|
|
||||||
account: Account | None = Account.find_by_code(code)
|
|
||||||
assert account is not None
|
|
||||||
account.is_need_offset = is_need_offset
|
|
||||||
db.session.commit()
|
|
||||||
|
|
||||||
def __add_journal_entry(self, journal_entry_data: JournalEntryData) \
|
|
||||||
-> None:
|
|
||||||
"""Adds a journal entry.
|
|
||||||
|
|
||||||
:param journal_entry_data: The journal entry data.
|
|
||||||
:return: None.
|
|
||||||
"""
|
|
||||||
from accounting.models import JournalEntry
|
|
||||||
store_uri: str = "/accounting/journal-entries/store/transfer"
|
|
||||||
|
|
||||||
response: httpx.Response = self.client.post(
|
|
||||||
store_uri, data=journal_entry_data.new_form(self.csrf_token))
|
|
||||||
assert response.status_code == 302
|
|
||||||
journal_entry_id: int \
|
|
||||||
= match_journal_entry_detail(response.headers["Location"])
|
|
||||||
journal_entry_data.id = journal_entry_id
|
|
||||||
with self.app.app_context():
|
|
||||||
journal_entry: JournalEntry | None \
|
|
||||||
= db.session.get(JournalEntry, journal_entry_id)
|
|
||||||
assert journal_entry is not None
|
|
||||||
for i in range(len(journal_entry.currencies)):
|
|
||||||
for j in range(len(journal_entry.currencies[i].debit)):
|
|
||||||
journal_entry_data.currencies[i].debit[j].id \
|
|
||||||
= journal_entry.currencies[i].debit[j].id
|
|
||||||
for j in range(len(journal_entry.currencies[i].credit)):
|
|
||||||
journal_entry_data.currencies[i].credit[j].id \
|
|
||||||
= journal_entry.currencies[i].credit[j].id
|
|
||||||
|
|
||||||
|
|
||||||
class SameTestData:
|
class SameTestData(BaseTestData):
|
||||||
"""The test data with same descriptions and amounts."""
|
"""The test data with same descriptions and amounts."""
|
||||||
|
|
||||||
def __init__(self, app: Flask, client: httpx.Client, csrf_token: str):
|
def _init_data(self) -> None:
|
||||||
"""Constructs the test data.
|
|
||||||
|
|
||||||
:param app: The Flask application.
|
|
||||||
:param client: The client.
|
|
||||||
:param csrf_token: The CSRF token.
|
|
||||||
"""
|
|
||||||
self.app: Flask = app
|
|
||||||
self.client: httpx.Client = client
|
|
||||||
self.csrf_token: str = csrf_token
|
|
||||||
|
|
||||||
def couple(description: str, amount: str, debit: str, credit: str) \
|
|
||||||
-> tuple[JournalEntryLineItemData, JournalEntryLineItemData]:
|
|
||||||
"""Returns a couple of debit-credit line items.
|
|
||||||
|
|
||||||
:param description: The description.
|
|
||||||
:param amount: The amount.
|
|
||||||
:param debit: The debit account code.
|
|
||||||
:param credit: The credit account code.
|
|
||||||
:return: The debit line item and credit line item.
|
|
||||||
"""
|
|
||||||
return JournalEntryLineItemData(debit, description, amount),\
|
|
||||||
JournalEntryLineItemData(credit, description, amount)
|
|
||||||
|
|
||||||
# Receivable original line items
|
# Receivable original line items
|
||||||
self.l_r_or1d, self.l_r_or1c = couple(
|
self.l_r_or1d, self.l_r_or1c = self._couple(
|
||||||
"Noodles", "100", Accounts.RECEIVABLE, Accounts.SALES)
|
"Noodles", "100", Accounts.RECEIVABLE, Accounts.SALES)
|
||||||
self.l_r_or2d, self.l_r_or2c = couple(
|
self.l_r_or2d, self.l_r_or2c = self._couple(
|
||||||
"Noodles", "100", Accounts.RECEIVABLE, Accounts.SALES)
|
"Noodles", "100", Accounts.RECEIVABLE, Accounts.SALES)
|
||||||
self.l_r_or3d, self.l_r_or3c = couple(
|
self.l_r_or3d, self.l_r_or3c = self._couple(
|
||||||
"Noodles", "100", Accounts.RECEIVABLE, Accounts.SALES)
|
"Noodles", "100", Accounts.RECEIVABLE, Accounts.SALES)
|
||||||
self.l_r_or4d, self.l_r_or4c = couple(
|
self.l_r_or4d, self.l_r_or4c = self._couple(
|
||||||
"Noodles", "100", Accounts.RECEIVABLE, Accounts.SALES)
|
"Noodles", "100", Accounts.RECEIVABLE, Accounts.SALES)
|
||||||
self.l_r_or5d, self.l_r_or5c = couple(
|
self.l_r_or5d, self.l_r_or5c = self._couple(
|
||||||
"Noodles", "100", Accounts.RECEIVABLE, Accounts.SALES)
|
"Noodles", "100", Accounts.RECEIVABLE, Accounts.SALES)
|
||||||
self.l_r_or6d, self.l_r_or6c = couple(
|
self.l_r_or6d, self.l_r_or6c = self._couple(
|
||||||
"Noodles", "100", Accounts.RECEIVABLE, Accounts.SALES)
|
"Noodles", "100", Accounts.RECEIVABLE, Accounts.SALES)
|
||||||
|
|
||||||
# Payable original line items
|
# Payable original line items
|
||||||
self.l_p_or1d, self.l_p_or1c = couple(
|
self.l_p_or1d, self.l_p_or1c = self._couple(
|
||||||
"Steak", "120", Accounts.MEAL, Accounts.PAYABLE)
|
"Steak", "120", Accounts.MEAL, Accounts.PAYABLE)
|
||||||
self.l_p_or2d, self.l_p_or2c = couple(
|
self.l_p_or2d, self.l_p_or2c = self._couple(
|
||||||
"Steak", "120", Accounts.MEAL, Accounts.PAYABLE)
|
"Steak", "120", Accounts.MEAL, Accounts.PAYABLE)
|
||||||
self.l_p_or3d, self.l_p_or3c = couple(
|
self.l_p_or3d, self.l_p_or3c = self._couple(
|
||||||
"Steak", "120", Accounts.MEAL, Accounts.PAYABLE)
|
"Steak", "120", Accounts.MEAL, Accounts.PAYABLE)
|
||||||
self.l_p_or4d, self.l_p_or4c = couple(
|
self.l_p_or4d, self.l_p_or4c = self._couple(
|
||||||
"Steak", "120", Accounts.MEAL, Accounts.PAYABLE)
|
"Steak", "120", Accounts.MEAL, Accounts.PAYABLE)
|
||||||
self.l_p_or5d, self.l_p_or5c = couple(
|
self.l_p_or5d, self.l_p_or5c = self._couple(
|
||||||
"Steak", "120", Accounts.MEAL, Accounts.PAYABLE)
|
"Steak", "120", Accounts.MEAL, Accounts.PAYABLE)
|
||||||
self.l_p_or6d, self.l_p_or6c = couple(
|
self.l_p_or6d, self.l_p_or6c = self._couple(
|
||||||
"Steak", "120", Accounts.MEAL, Accounts.PAYABLE)
|
"Steak", "120", Accounts.MEAL, Accounts.PAYABLE)
|
||||||
|
|
||||||
# Original journal entries
|
# Original journal entries
|
||||||
@ -650,47 +561,47 @@ class SameTestData:
|
|||||||
self.j_p_or6: JournalEntryData = JournalEntryData(
|
self.j_p_or6: JournalEntryData = JournalEntryData(
|
||||||
10, [CurrencyData("USD", [self.l_p_or6d], [self.l_p_or6c])])
|
10, [CurrencyData("USD", [self.l_p_or6d], [self.l_p_or6c])])
|
||||||
|
|
||||||
self.__add_journal_entry(self.j_r_or1)
|
self._add_journal_entry(self.j_r_or1)
|
||||||
self.__add_journal_entry(self.j_r_or2)
|
self._add_journal_entry(self.j_r_or2)
|
||||||
self.__add_journal_entry(self.j_r_or3)
|
self._add_journal_entry(self.j_r_or3)
|
||||||
self.__add_journal_entry(self.j_r_or4)
|
self._add_journal_entry(self.j_r_or4)
|
||||||
self.__add_journal_entry(self.j_r_or5)
|
self._add_journal_entry(self.j_r_or5)
|
||||||
self.__add_journal_entry(self.j_r_or6)
|
self._add_journal_entry(self.j_r_or6)
|
||||||
self.__add_journal_entry(self.j_p_or1)
|
self._add_journal_entry(self.j_p_or1)
|
||||||
self.__add_journal_entry(self.j_p_or2)
|
self._add_journal_entry(self.j_p_or2)
|
||||||
self.__add_journal_entry(self.j_p_or3)
|
self._add_journal_entry(self.j_p_or3)
|
||||||
self.__add_journal_entry(self.j_p_or4)
|
self._add_journal_entry(self.j_p_or4)
|
||||||
self.__add_journal_entry(self.j_p_or5)
|
self._add_journal_entry(self.j_p_or5)
|
||||||
self.__add_journal_entry(self.j_p_or6)
|
self._add_journal_entry(self.j_p_or6)
|
||||||
|
|
||||||
# Receivable offset items
|
# Receivable offset items
|
||||||
self.l_r_of1d, self.l_r_of1c = couple(
|
self.l_r_of1d, self.l_r_of1c = self._couple(
|
||||||
"Noodles", "100", Accounts.CASH, Accounts.RECEIVABLE)
|
"Noodles", "100", Accounts.CASH, Accounts.RECEIVABLE)
|
||||||
self.l_r_of2d, self.l_r_of2c = couple(
|
self.l_r_of2d, self.l_r_of2c = self._couple(
|
||||||
"Noodles", "100", Accounts.CASH, Accounts.RECEIVABLE)
|
"Noodles", "100", Accounts.CASH, Accounts.RECEIVABLE)
|
||||||
self.l_r_of3d, self.l_r_of3c = couple(
|
self.l_r_of3d, self.l_r_of3c = self._couple(
|
||||||
"Noodles", "100", Accounts.CASH, Accounts.RECEIVABLE)
|
"Noodles", "100", Accounts.CASH, Accounts.RECEIVABLE)
|
||||||
self.l_r_of3c.original_line_item = self.l_r_or2d
|
self.l_r_of3c.original_line_item = self.l_r_or2d
|
||||||
self.l_r_of4d, self.l_r_of4c = couple(
|
self.l_r_of4d, self.l_r_of4c = self._couple(
|
||||||
"Noodles", "100", Accounts.CASH, Accounts.RECEIVABLE)
|
"Noodles", "100", Accounts.CASH, Accounts.RECEIVABLE)
|
||||||
self.l_r_of5d, self.l_r_of5c = couple(
|
self.l_r_of5d, self.l_r_of5c = self._couple(
|
||||||
"Noodles", "100", Accounts.CASH, Accounts.RECEIVABLE)
|
"Noodles", "100", Accounts.CASH, Accounts.RECEIVABLE)
|
||||||
self.l_r_of6d, self.l_r_of6c = couple(
|
self.l_r_of6d, self.l_r_of6c = self._couple(
|
||||||
"Noodles", "100", Accounts.CASH, Accounts.RECEIVABLE)
|
"Noodles", "100", Accounts.CASH, Accounts.RECEIVABLE)
|
||||||
|
|
||||||
# Payable offset items
|
# Payable offset items
|
||||||
self.l_p_of1d, self.l_p_of1c = couple(
|
self.l_p_of1d, self.l_p_of1c = self._couple(
|
||||||
"Steak", "120", Accounts.PAYABLE, Accounts.CASH)
|
"Steak", "120", Accounts.PAYABLE, Accounts.CASH)
|
||||||
self.l_p_of2d, self.l_p_of2c = couple(
|
self.l_p_of2d, self.l_p_of2c = self._couple(
|
||||||
"Steak", "120", Accounts.PAYABLE, Accounts.CASH)
|
"Steak", "120", Accounts.PAYABLE, Accounts.CASH)
|
||||||
self.l_p_of3d, self.l_p_of3c = couple(
|
self.l_p_of3d, self.l_p_of3c = self._couple(
|
||||||
"Steak", "120", Accounts.PAYABLE, Accounts.CASH)
|
"Steak", "120", Accounts.PAYABLE, Accounts.CASH)
|
||||||
self.l_p_of3d.original_line_item = self.l_p_or2c
|
self.l_p_of3d.original_line_item = self.l_p_or2c
|
||||||
self.l_p_of4d, self.l_p_of4c = couple(
|
self.l_p_of4d, self.l_p_of4c = self._couple(
|
||||||
"Steak", "120", Accounts.PAYABLE, Accounts.CASH)
|
"Steak", "120", Accounts.PAYABLE, Accounts.CASH)
|
||||||
self.l_p_of5d, self.l_p_of5c = couple(
|
self.l_p_of5d, self.l_p_of5c = self._couple(
|
||||||
"Steak", "120", Accounts.PAYABLE, Accounts.CASH)
|
"Steak", "120", Accounts.PAYABLE, Accounts.CASH)
|
||||||
self.l_p_of6d, self.l_p_of6c = couple(
|
self.l_p_of6d, self.l_p_of6c = self._couple(
|
||||||
"Steak", "120", Accounts.PAYABLE, Accounts.CASH)
|
"Steak", "120", Accounts.PAYABLE, Accounts.CASH)
|
||||||
|
|
||||||
# Offset journal entries
|
# Offset journal entries
|
||||||
@ -719,60 +630,19 @@ class SameTestData:
|
|||||||
self.j_p_of6: JournalEntryData = JournalEntryData(
|
self.j_p_of6: JournalEntryData = JournalEntryData(
|
||||||
15, [CurrencyData("USD", [self.l_p_of6d], [self.l_p_of6c])])
|
15, [CurrencyData("USD", [self.l_p_of6d], [self.l_p_of6c])])
|
||||||
|
|
||||||
self.__set_is_need_offset(False)
|
self._set_is_need_offset({Accounts.RECEIVABLE, Accounts.PAYABLE},
|
||||||
self.__add_journal_entry(self.j_r_of1)
|
False)
|
||||||
self.__add_journal_entry(self.j_r_of2)
|
self._add_journal_entry(self.j_r_of1)
|
||||||
self.__add_journal_entry(self.j_r_of4)
|
self._add_journal_entry(self.j_r_of2)
|
||||||
self.__add_journal_entry(self.j_r_of5)
|
self._add_journal_entry(self.j_r_of4)
|
||||||
self.__add_journal_entry(self.j_r_of6)
|
self._add_journal_entry(self.j_r_of5)
|
||||||
self.__add_journal_entry(self.j_p_of1)
|
self._add_journal_entry(self.j_r_of6)
|
||||||
self.__add_journal_entry(self.j_p_of2)
|
self._add_journal_entry(self.j_p_of1)
|
||||||
self.__add_journal_entry(self.j_p_of4)
|
self._add_journal_entry(self.j_p_of2)
|
||||||
self.__add_journal_entry(self.j_p_of5)
|
self._add_journal_entry(self.j_p_of4)
|
||||||
self.__add_journal_entry(self.j_p_of6)
|
self._add_journal_entry(self.j_p_of5)
|
||||||
self.__set_is_need_offset(True)
|
self._add_journal_entry(self.j_p_of6)
|
||||||
self.__add_journal_entry(self.j_r_of3)
|
self._set_is_need_offset({Accounts.RECEIVABLE, Accounts.PAYABLE},
|
||||||
self.__add_journal_entry(self.j_p_of3)
|
True)
|
||||||
|
self._add_journal_entry(self.j_r_of3)
|
||||||
def __set_is_need_offset(self, is_need_offset: bool) -> None:
|
self._add_journal_entry(self.j_p_of3)
|
||||||
"""Sets whether the payables and receivables need offset.
|
|
||||||
|
|
||||||
:param is_need_offset: True if payables and receivables need offset, or
|
|
||||||
False otherwise.
|
|
||||||
:return:
|
|
||||||
"""
|
|
||||||
from accounting.models import Account
|
|
||||||
with self.app.app_context():
|
|
||||||
for code in {Accounts.RECEIVABLE, Accounts.PAYABLE}:
|
|
||||||
account: Account | None = Account.find_by_code(code)
|
|
||||||
assert account is not None
|
|
||||||
account.is_need_offset = is_need_offset
|
|
||||||
db.session.commit()
|
|
||||||
|
|
||||||
def __add_journal_entry(self, journal_entry_data: JournalEntryData) \
|
|
||||||
-> None:
|
|
||||||
"""Adds a journal entry.
|
|
||||||
|
|
||||||
:param journal_entry_data: The journal entry data.
|
|
||||||
:return: None.
|
|
||||||
"""
|
|
||||||
from accounting.models import JournalEntry
|
|
||||||
store_uri: str = "/accounting/journal-entries/store/transfer"
|
|
||||||
|
|
||||||
response: httpx.Response = self.client.post(
|
|
||||||
store_uri, data=journal_entry_data.new_form(self.csrf_token))
|
|
||||||
assert response.status_code == 302
|
|
||||||
journal_entry_id: int \
|
|
||||||
= match_journal_entry_detail(response.headers["Location"])
|
|
||||||
journal_entry_data.id = journal_entry_id
|
|
||||||
with self.app.app_context():
|
|
||||||
journal_entry: JournalEntry | None \
|
|
||||||
= db.session.get(JournalEntry, journal_entry_id)
|
|
||||||
assert journal_entry is not None
|
|
||||||
for i in range(len(journal_entry.currencies)):
|
|
||||||
for j in range(len(journal_entry.currencies[i].debit)):
|
|
||||||
journal_entry_data.currencies[i].debit[j].id \
|
|
||||||
= journal_entry.currencies[i].debit[j].id
|
|
||||||
for j in range(len(journal_entry.currencies[i].credit)):
|
|
||||||
journal_entry_data.currencies[i].credit[j].id \
|
|
||||||
= journal_entry.currencies[i].credit[j].id
|
|
||||||
|
@ -19,6 +19,7 @@
|
|||||||
"""
|
"""
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from abc import ABC, abstractmethod
|
||||||
from datetime import date, timedelta
|
from datetime import date, timedelta
|
||||||
from decimal import Decimal
|
from decimal import Decimal
|
||||||
|
|
||||||
@ -161,8 +162,8 @@ class JournalEntryData:
|
|||||||
return form
|
return form
|
||||||
|
|
||||||
|
|
||||||
class TestData:
|
class BaseTestData(ABC):
|
||||||
"""The test data."""
|
"""The base test data."""
|
||||||
|
|
||||||
def __init__(self, app: Flask, client: httpx.Client, csrf_token: str):
|
def __init__(self, app: Flask, client: httpx.Client, csrf_token: str):
|
||||||
"""Constructs the test data.
|
"""Constructs the test data.
|
||||||
@ -174,8 +175,17 @@ class TestData:
|
|||||||
self.app: Flask = app
|
self.app: Flask = app
|
||||||
self.client: httpx.Client = client
|
self.client: httpx.Client = client
|
||||||
self.csrf_token: str = csrf_token
|
self.csrf_token: str = csrf_token
|
||||||
|
self._init_data()
|
||||||
|
|
||||||
def couple(description: str, amount: str, debit: str, credit: str) \
|
@abstractmethod
|
||||||
|
def _init_data(self) -> None:
|
||||||
|
"""Initializes the test data.
|
||||||
|
|
||||||
|
:return: None
|
||||||
|
"""
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def _couple(description: str, amount: str, debit: str, credit: str) \
|
||||||
-> tuple[JournalEntryLineItemData, JournalEntryLineItemData]:
|
-> tuple[JournalEntryLineItemData, JournalEntryLineItemData]:
|
||||||
"""Returns a couple of debit-credit line items.
|
"""Returns a couple of debit-credit line items.
|
||||||
|
|
||||||
@ -188,106 +198,7 @@ class TestData:
|
|||||||
return JournalEntryLineItemData(debit, description, amount),\
|
return JournalEntryLineItemData(debit, description, amount),\
|
||||||
JournalEntryLineItemData(credit, description, amount)
|
JournalEntryLineItemData(credit, description, amount)
|
||||||
|
|
||||||
# Receivable original line items
|
def _add_journal_entry(self, journal_entry_data: JournalEntryData) -> None:
|
||||||
self.l_r_or1d, self.l_r_or1c = couple(
|
|
||||||
"Accountant", "1200", Accounts.RECEIVABLE, Accounts.SERVICE)
|
|
||||||
self.l_r_or2d, self.l_r_or2c = couple(
|
|
||||||
"Toy", "600", Accounts.RECEIVABLE, Accounts.SALES)
|
|
||||||
self.l_r_or3d, self.l_r_or3c = couple(
|
|
||||||
"Noodles", "100", Accounts.RECEIVABLE, Accounts.SALES)
|
|
||||||
self.l_r_or4d, self.l_r_or4c = couple(
|
|
||||||
"Interest", "3.4", Accounts.RECEIVABLE, Accounts.INTEREST)
|
|
||||||
|
|
||||||
# Payable original line items
|
|
||||||
self.l_p_or1d, self.l_p_or1c = couple(
|
|
||||||
"Airplane", "2000", Accounts.TRAVEL, Accounts.PAYABLE)
|
|
||||||
self.l_p_or2d, self.l_p_or2c = couple(
|
|
||||||
"Phone", "900", Accounts.OFFICE, Accounts.PAYABLE)
|
|
||||||
self.l_p_or3d, self.l_p_or3c = couple(
|
|
||||||
"Steak", "120", Accounts.MEAL, Accounts.PAYABLE)
|
|
||||||
self.l_p_or4d, self.l_p_or4c = couple(
|
|
||||||
"Envelop", "0.9", Accounts.OFFICE, Accounts.PAYABLE)
|
|
||||||
|
|
||||||
# Original journal entries
|
|
||||||
self.j_r_or1: JournalEntryData = JournalEntryData(
|
|
||||||
50, [CurrencyData("USD", [self.l_r_or1d, self.l_r_or4d],
|
|
||||||
[self.l_r_or1c, self.l_r_or4c])])
|
|
||||||
self.j_r_or2: JournalEntryData = JournalEntryData(
|
|
||||||
30, [CurrencyData("USD", [self.l_r_or2d, self.l_r_or3d],
|
|
||||||
[self.l_r_or2c, self.l_r_or3c])])
|
|
||||||
self.j_p_or1: JournalEntryData = JournalEntryData(
|
|
||||||
40, [CurrencyData("USD", [self.l_p_or1d, self.l_p_or4d],
|
|
||||||
[self.l_p_or1c, self.l_p_or4c])])
|
|
||||||
self.j_p_or2: JournalEntryData = JournalEntryData(
|
|
||||||
20, [CurrencyData("USD", [self.l_p_or2d, self.l_p_or3d],
|
|
||||||
[self.l_p_or2c, self.l_p_or3c])])
|
|
||||||
|
|
||||||
self.__add_journal_entry(self.j_r_or1)
|
|
||||||
self.__add_journal_entry(self.j_r_or2)
|
|
||||||
self.__add_journal_entry(self.j_p_or1)
|
|
||||||
self.__add_journal_entry(self.j_p_or2)
|
|
||||||
|
|
||||||
# Receivable offset items
|
|
||||||
self.l_r_of1d, self.l_r_of1c = couple(
|
|
||||||
"Accountant", "500", Accounts.CASH, Accounts.RECEIVABLE)
|
|
||||||
self.l_r_of1c.original_line_item = self.l_r_or1d
|
|
||||||
self.l_r_of2d, self.l_r_of2c = couple(
|
|
||||||
"Accountant", "200", Accounts.CASH, Accounts.RECEIVABLE)
|
|
||||||
self.l_r_of2c.original_line_item = self.l_r_or1d
|
|
||||||
self.l_r_of3d, self.l_r_of3c = couple(
|
|
||||||
"Accountant", "100", Accounts.CASH, Accounts.RECEIVABLE)
|
|
||||||
self.l_r_of3c.original_line_item = self.l_r_or1d
|
|
||||||
self.l_r_of4d, self.l_r_of4c = couple(
|
|
||||||
"Toy", "240", Accounts.CASH, Accounts.RECEIVABLE)
|
|
||||||
self.l_r_of4c.original_line_item = self.l_r_or2d
|
|
||||||
self.l_r_of5d, self.l_r_of5c = couple(
|
|
||||||
"Interest", "3.4", Accounts.CASH, Accounts.RECEIVABLE)
|
|
||||||
self.l_r_of5c.original_line_item = self.l_r_or4d
|
|
||||||
|
|
||||||
# Payable offset items
|
|
||||||
self.l_p_of1d, self.l_p_of1c = couple(
|
|
||||||
"Airplane", "800", Accounts.PAYABLE, Accounts.CASH)
|
|
||||||
self.l_p_of1d.original_line_item = self.l_p_or1c
|
|
||||||
self.l_p_of2d, self.l_p_of2c = couple(
|
|
||||||
"Airplane", "300", Accounts.PAYABLE, Accounts.CASH)
|
|
||||||
self.l_p_of2d.original_line_item = self.l_p_or1c
|
|
||||||
self.l_p_of3d, self.l_p_of3c = couple(
|
|
||||||
"Airplane", "100", Accounts.PAYABLE, Accounts.CASH)
|
|
||||||
self.l_p_of3d.original_line_item = self.l_p_or1c
|
|
||||||
self.l_p_of4d, self.l_p_of4c = couple(
|
|
||||||
"Phone", "400", Accounts.PAYABLE, Accounts.CASH)
|
|
||||||
self.l_p_of4d.original_line_item = self.l_p_or2c
|
|
||||||
self.l_p_of5d, self.l_p_of5c = couple(
|
|
||||||
"Envelop", "0.9", Accounts.PAYABLE, Accounts.CASH)
|
|
||||||
self.l_p_of5d.original_line_item = self.l_p_or4c
|
|
||||||
|
|
||||||
# Offset journal entries
|
|
||||||
self.j_r_of1: JournalEntryData = JournalEntryData(
|
|
||||||
25, [CurrencyData("USD", [self.l_r_of1d], [self.l_r_of1c])])
|
|
||||||
self.j_r_of2: JournalEntryData = JournalEntryData(
|
|
||||||
20, [CurrencyData("USD",
|
|
||||||
[self.l_r_of2d, self.l_r_of3d, self.l_r_of4d],
|
|
||||||
[self.l_r_of2c, self.l_r_of3c, self.l_r_of4c])])
|
|
||||||
self.j_r_of3: JournalEntryData = JournalEntryData(
|
|
||||||
15, [CurrencyData("USD", [self.l_r_of5d], [self.l_r_of5c])])
|
|
||||||
self.j_p_of1: JournalEntryData = JournalEntryData(
|
|
||||||
15, [CurrencyData("USD", [self.l_p_of1d], [self.l_p_of1c])])
|
|
||||||
self.j_p_of2: JournalEntryData = JournalEntryData(
|
|
||||||
10, [CurrencyData("USD",
|
|
||||||
[self.l_p_of2d, self.l_p_of3d, self.l_p_of4d],
|
|
||||||
[self.l_p_of2c, self.l_p_of3c, self.l_p_of4c])])
|
|
||||||
self.j_p_of3: JournalEntryData = JournalEntryData(
|
|
||||||
5, [CurrencyData("USD", [self.l_p_of5d], [self.l_p_of5c])])
|
|
||||||
|
|
||||||
self.__add_journal_entry(self.j_r_of1)
|
|
||||||
self.__add_journal_entry(self.j_r_of2)
|
|
||||||
self.__add_journal_entry(self.j_r_of3)
|
|
||||||
self.__add_journal_entry(self.j_p_of1)
|
|
||||||
self.__add_journal_entry(self.j_p_of2)
|
|
||||||
self.__add_journal_entry(self.j_p_of3)
|
|
||||||
|
|
||||||
def __add_journal_entry(self, journal_entry_data: JournalEntryData) \
|
|
||||||
-> None:
|
|
||||||
"""Adds a journal entry.
|
"""Adds a journal entry.
|
||||||
|
|
||||||
:param journal_entry_data: The journal entry data.
|
:param journal_entry_data: The journal entry data.
|
||||||
@ -313,3 +224,123 @@ class TestData:
|
|||||||
for j in range(len(journal_entry.currencies[i].credit)):
|
for j in range(len(journal_entry.currencies[i].credit)):
|
||||||
journal_entry_data.currencies[i].credit[j].id \
|
journal_entry_data.currencies[i].credit[j].id \
|
||||||
= journal_entry.currencies[i].credit[j].id
|
= journal_entry.currencies[i].credit[j].id
|
||||||
|
|
||||||
|
def _set_is_need_offset(self, account_codes: set[str],
|
||||||
|
is_need_offset: bool) -> None:
|
||||||
|
"""Sets whether the line items in some accounts need offset.
|
||||||
|
|
||||||
|
:param account_codes: The account codes.
|
||||||
|
:param is_need_offset: True if the line items in the accounts need
|
||||||
|
offset, or False otherwise.
|
||||||
|
:return:
|
||||||
|
"""
|
||||||
|
from accounting.models import Account
|
||||||
|
with self.app.app_context():
|
||||||
|
for code in account_codes:
|
||||||
|
account: Account | None = Account.find_by_code(code)
|
||||||
|
assert account is not None
|
||||||
|
account.is_need_offset = is_need_offset
|
||||||
|
db.session.commit()
|
||||||
|
|
||||||
|
|
||||||
|
class TestData(BaseTestData):
|
||||||
|
"""The test data."""
|
||||||
|
|
||||||
|
def _init_data(self) -> None:
|
||||||
|
# Receivable original line items
|
||||||
|
self.l_r_or1d, self.l_r_or1c = self._couple(
|
||||||
|
"Accountant", "1200", Accounts.RECEIVABLE, Accounts.SERVICE)
|
||||||
|
self.l_r_or2d, self.l_r_or2c = self._couple(
|
||||||
|
"Toy", "600", Accounts.RECEIVABLE, Accounts.SALES)
|
||||||
|
self.l_r_or3d, self.l_r_or3c = self._couple(
|
||||||
|
"Noodles", "100", Accounts.RECEIVABLE, Accounts.SALES)
|
||||||
|
self.l_r_or4d, self.l_r_or4c = self._couple(
|
||||||
|
"Interest", "3.4", Accounts.RECEIVABLE, Accounts.INTEREST)
|
||||||
|
|
||||||
|
# Payable original line items
|
||||||
|
self.l_p_or1d, self.l_p_or1c = self._couple(
|
||||||
|
"Airplane", "2000", Accounts.TRAVEL, Accounts.PAYABLE)
|
||||||
|
self.l_p_or2d, self.l_p_or2c = self._couple(
|
||||||
|
"Phone", "900", Accounts.OFFICE, Accounts.PAYABLE)
|
||||||
|
self.l_p_or3d, self.l_p_or3c = self._couple(
|
||||||
|
"Steak", "120", Accounts.MEAL, Accounts.PAYABLE)
|
||||||
|
self.l_p_or4d, self.l_p_or4c = self._couple(
|
||||||
|
"Envelop", "0.9", Accounts.OFFICE, Accounts.PAYABLE)
|
||||||
|
|
||||||
|
# Original journal entries
|
||||||
|
self.j_r_or1: JournalEntryData = JournalEntryData(
|
||||||
|
50, [CurrencyData("USD", [self.l_r_or1d, self.l_r_or4d],
|
||||||
|
[self.l_r_or1c, self.l_r_or4c])])
|
||||||
|
self.j_r_or2: JournalEntryData = JournalEntryData(
|
||||||
|
30, [CurrencyData("USD", [self.l_r_or2d, self.l_r_or3d],
|
||||||
|
[self.l_r_or2c, self.l_r_or3c])])
|
||||||
|
self.j_p_or1: JournalEntryData = JournalEntryData(
|
||||||
|
40, [CurrencyData("USD", [self.l_p_or1d, self.l_p_or4d],
|
||||||
|
[self.l_p_or1c, self.l_p_or4c])])
|
||||||
|
self.j_p_or2: JournalEntryData = JournalEntryData(
|
||||||
|
20, [CurrencyData("USD", [self.l_p_or2d, self.l_p_or3d],
|
||||||
|
[self.l_p_or2c, self.l_p_or3c])])
|
||||||
|
|
||||||
|
self._add_journal_entry(self.j_r_or1)
|
||||||
|
self._add_journal_entry(self.j_r_or2)
|
||||||
|
self._add_journal_entry(self.j_p_or1)
|
||||||
|
self._add_journal_entry(self.j_p_or2)
|
||||||
|
|
||||||
|
# Receivable offset items
|
||||||
|
self.l_r_of1d, self.l_r_of1c = self._couple(
|
||||||
|
"Accountant", "500", Accounts.CASH, Accounts.RECEIVABLE)
|
||||||
|
self.l_r_of1c.original_line_item = self.l_r_or1d
|
||||||
|
self.l_r_of2d, self.l_r_of2c = self._couple(
|
||||||
|
"Accountant", "200", Accounts.CASH, Accounts.RECEIVABLE)
|
||||||
|
self.l_r_of2c.original_line_item = self.l_r_or1d
|
||||||
|
self.l_r_of3d, self.l_r_of3c = self._couple(
|
||||||
|
"Accountant", "100", Accounts.CASH, Accounts.RECEIVABLE)
|
||||||
|
self.l_r_of3c.original_line_item = self.l_r_or1d
|
||||||
|
self.l_r_of4d, self.l_r_of4c = self._couple(
|
||||||
|
"Toy", "240", Accounts.CASH, Accounts.RECEIVABLE)
|
||||||
|
self.l_r_of4c.original_line_item = self.l_r_or2d
|
||||||
|
self.l_r_of5d, self.l_r_of5c = self._couple(
|
||||||
|
"Interest", "3.4", Accounts.CASH, Accounts.RECEIVABLE)
|
||||||
|
self.l_r_of5c.original_line_item = self.l_r_or4d
|
||||||
|
|
||||||
|
# Payable offset items
|
||||||
|
self.l_p_of1d, self.l_p_of1c = self._couple(
|
||||||
|
"Airplane", "800", Accounts.PAYABLE, Accounts.CASH)
|
||||||
|
self.l_p_of1d.original_line_item = self.l_p_or1c
|
||||||
|
self.l_p_of2d, self.l_p_of2c = self._couple(
|
||||||
|
"Airplane", "300", Accounts.PAYABLE, Accounts.CASH)
|
||||||
|
self.l_p_of2d.original_line_item = self.l_p_or1c
|
||||||
|
self.l_p_of3d, self.l_p_of3c = self._couple(
|
||||||
|
"Airplane", "100", Accounts.PAYABLE, Accounts.CASH)
|
||||||
|
self.l_p_of3d.original_line_item = self.l_p_or1c
|
||||||
|
self.l_p_of4d, self.l_p_of4c = self._couple(
|
||||||
|
"Phone", "400", Accounts.PAYABLE, Accounts.CASH)
|
||||||
|
self.l_p_of4d.original_line_item = self.l_p_or2c
|
||||||
|
self.l_p_of5d, self.l_p_of5c = self._couple(
|
||||||
|
"Envelop", "0.9", Accounts.PAYABLE, Accounts.CASH)
|
||||||
|
self.l_p_of5d.original_line_item = self.l_p_or4c
|
||||||
|
|
||||||
|
# Offset journal entries
|
||||||
|
self.j_r_of1: JournalEntryData = JournalEntryData(
|
||||||
|
25, [CurrencyData("USD", [self.l_r_of1d], [self.l_r_of1c])])
|
||||||
|
self.j_r_of2: JournalEntryData = JournalEntryData(
|
||||||
|
20, [CurrencyData("USD",
|
||||||
|
[self.l_r_of2d, self.l_r_of3d, self.l_r_of4d],
|
||||||
|
[self.l_r_of2c, self.l_r_of3c, self.l_r_of4c])])
|
||||||
|
self.j_r_of3: JournalEntryData = JournalEntryData(
|
||||||
|
15, [CurrencyData("USD", [self.l_r_of5d], [self.l_r_of5c])])
|
||||||
|
self.j_p_of1: JournalEntryData = JournalEntryData(
|
||||||
|
15, [CurrencyData("USD", [self.l_p_of1d], [self.l_p_of1c])])
|
||||||
|
self.j_p_of2: JournalEntryData = JournalEntryData(
|
||||||
|
10, [CurrencyData("USD",
|
||||||
|
[self.l_p_of2d, self.l_p_of3d, self.l_p_of4d],
|
||||||
|
[self.l_p_of2c, self.l_p_of3c, self.l_p_of4c])])
|
||||||
|
self.j_p_of3: JournalEntryData = JournalEntryData(
|
||||||
|
5, [CurrencyData("USD", [self.l_p_of5d], [self.l_p_of5c])])
|
||||||
|
|
||||||
|
self._add_journal_entry(self.j_r_of1)
|
||||||
|
self._add_journal_entry(self.j_r_of2)
|
||||||
|
self._add_journal_entry(self.j_r_of3)
|
||||||
|
self._add_journal_entry(self.j_p_of1)
|
||||||
|
self._add_journal_entry(self.j_p_of2)
|
||||||
|
self._add_journal_entry(self.j_p_of3)
|
||||||
|
Loading…
Reference in New Issue
Block a user