Revised the property names in the TestData class in testlib_offset.py.

This commit is contained in:
依瑪貓 2023-04-08 20:30:17 +08:00
parent df240472a4
commit 285c12406b
2 changed files with 104 additions and 104 deletions

View File

@ -81,21 +81,21 @@ class OffsetTestCase(unittest.TestCase):
response: httpx.Response
journal_entry_data: JournalEntryData = JournalEntryData(
self.data.e_r_or3d.journal_entry.days, [CurrencyData(
self.data.l_r_or3d.journal_entry.days, [CurrencyData(
"USD",
[],
[JournalEntryLineItemData(
Accounts.RECEIVABLE,
self.data.e_r_or1d.description, "300",
original_line_item=self.data.e_r_or1d),
self.data.l_r_or1d.description, "300",
original_line_item=self.data.l_r_or1d),
JournalEntryLineItemData(
Accounts.RECEIVABLE,
self.data.e_r_or1d.description, "100",
original_line_item=self.data.e_r_or1d),
self.data.l_r_or1d.description, "100",
original_line_item=self.data.l_r_or1d),
JournalEntryLineItemData(
Accounts.RECEIVABLE,
self.data.e_r_or3d.description, "100",
original_line_item=self.data.e_r_or3d)])])
self.data.l_r_or3d.description, "100",
original_line_item=self.data.l_r_or3d)])])
# Non-existing original line item ID
form = journal_entry_data.new_form(self.csrf_token)
@ -107,8 +107,8 @@ class OffsetTestCase(unittest.TestCase):
# The same debit or credit
form = journal_entry_data.new_form(self.csrf_token)
form["currency-1-credit-1-original_line_item_id"] \
= self.data.e_p_or1c.id
form["currency-1-credit-1-account_code"] = self.data.e_p_or1c.account
= self.data.l_p_or1c.id
form["currency-1-credit-1-account_code"] = self.data.l_p_or1c.account
form["currency-1-credit-1-amount"] = "100"
response = self.client.post(store_uri, data=form)
self.assertEqual(response.status_code, 302)
@ -131,8 +131,8 @@ class OffsetTestCase(unittest.TestCase):
# The original line item is also an offset
form = journal_entry_data.new_form(self.csrf_token)
form["currency-1-credit-1-original_line_item_id"] \
= self.data.e_p_of1d.id
form["currency-1-credit-1-account_code"] = self.data.e_p_of1d.account
= self.data.l_p_of1d.id
form["currency-1-credit-1-account_code"] = self.data.l_p_of1d.account
response = self.client.post(store_uri, data=form)
self.assertEqual(response.status_code, 302)
self.assertEqual(response.headers["Location"], create_uri)
@ -195,13 +195,13 @@ class OffsetTestCase(unittest.TestCase):
:return: None.
"""
from accounting.models import Account
journal_entry_data: JournalEntryData = self.data.v_r_of2
journal_entry_data: JournalEntryData = self.data.j_r_of2
edit_uri: str = f"{PREFIX}/{journal_entry_data.id}/edit?next=%2F_next"
update_uri: str = f"{PREFIX}/{journal_entry_data.id}/update"
form: dict[str, str]
response: httpx.Response
journal_entry_data.days = self.data.v_r_or2.days
journal_entry_data.days = self.data.j_r_or2.days
journal_entry_data.currencies[0].debit[0].amount = Decimal("600")
journal_entry_data.currencies[0].credit[0].amount = Decimal("600")
journal_entry_data.currencies[0].debit[2].amount = Decimal("600")
@ -217,8 +217,8 @@ class OffsetTestCase(unittest.TestCase):
# The same debit or credit
form = journal_entry_data.update_form(self.csrf_token)
form["currency-1-credit-1-original_line_item_id"] \
= self.data.e_p_or1c.id
form["currency-1-credit-1-account_code"] = self.data.e_p_or1c.account
= self.data.l_p_or1c.id
form["currency-1-credit-1-account_code"] = self.data.l_p_or1c.account
form["currency-1-debit-1-amount"] = "100"
form["currency-1-credit-1-amount"] = "100"
response = self.client.post(update_uri, data=form)
@ -242,8 +242,8 @@ class OffsetTestCase(unittest.TestCase):
# The original line item is also an offset
form = journal_entry_data.update_form(self.csrf_token)
form["currency-1-credit-1-original_line_item_id"] \
= self.data.e_p_of1d.id
form["currency-1-credit-1-account_code"] = self.data.e_p_of1d.account
= self.data.l_p_of1d.id
form["currency-1-credit-1-account_code"] = self.data.l_p_of1d.account
response = self.client.post(update_uri, data=form)
self.assertEqual(response.status_code, 302)
self.assertEqual(response.headers["Location"], edit_uri)
@ -308,13 +308,13 @@ class OffsetTestCase(unittest.TestCase):
:return: None.
"""
from accounting.models import JournalEntry
journal_entry_data: JournalEntryData = self.data.v_r_or1
journal_entry_data: JournalEntryData = self.data.j_r_or1
edit_uri: str = f"{PREFIX}/{journal_entry_data.id}/edit?next=%2F_next"
update_uri: str = f"{PREFIX}/{journal_entry_data.id}/update"
form: dict[str, str]
response: httpx.Response
journal_entry_data.days = self.data.v_r_of1.days
journal_entry_data.days = self.data.j_r_of1.days
journal_entry_data.currencies[0].debit[0].amount = Decimal("800")
journal_entry_data.currencies[0].credit[0].amount = Decimal("800")
journal_entry_data.currencies[0].debit[1].amount = Decimal("3.4")
@ -388,7 +388,7 @@ class OffsetTestCase(unittest.TestCase):
JournalEntry, journal_entry_data.id)
self.assertIsNotNone(journal_entry_or)
journal_entry_of: JournalEntry | None = db.session.get(
JournalEntry, self.data.v_r_of1.id)
JournalEntry, self.data.j_r_of1.id)
self.assertIsNotNone(journal_entry_of)
self.assertEqual(journal_entry_or.date, journal_entry_of.date)
self.assertLess(journal_entry_or.no, journal_entry_of.no)
@ -405,20 +405,20 @@ class OffsetTestCase(unittest.TestCase):
response: httpx.Response
journal_entry_data: JournalEntryData = JournalEntryData(
self.data.e_p_or3c.journal_entry.days, [CurrencyData(
self.data.l_p_or3c.journal_entry.days, [CurrencyData(
"USD",
[JournalEntryLineItemData(
Accounts.PAYABLE,
self.data.e_p_or1c.description, "500",
original_line_item=self.data.e_p_or1c),
self.data.l_p_or1c.description, "500",
original_line_item=self.data.l_p_or1c),
JournalEntryLineItemData(
Accounts.PAYABLE,
self.data.e_p_or1c.description, "300",
original_line_item=self.data.e_p_or1c),
self.data.l_p_or1c.description, "300",
original_line_item=self.data.l_p_or1c),
JournalEntryLineItemData(
Accounts.PAYABLE,
self.data.e_p_or3c.description, "120",
original_line_item=self.data.e_p_or3c)],
self.data.l_p_or3c.description, "120",
original_line_item=self.data.l_p_or3c)],
[])])
# Non-existing original line item ID
@ -431,8 +431,8 @@ class OffsetTestCase(unittest.TestCase):
# The same debit or credit
form = journal_entry_data.new_form(self.csrf_token)
form["currency-1-debit-1-original_line_item_id"] \
= self.data.e_r_or1d.id
form["currency-1-debit-1-account_code"] = self.data.e_r_or1d.account
= self.data.l_r_or1d.id
form["currency-1-debit-1-account_code"] = self.data.l_r_or1d.account
form["currency-1-debit-1-amount"] = "100"
response = self.client.post(store_uri, data=form)
self.assertEqual(response.status_code, 302)
@ -455,8 +455,8 @@ class OffsetTestCase(unittest.TestCase):
# The original line item is also an offset
form = journal_entry_data.new_form(self.csrf_token)
form["currency-1-debit-1-original_line_item_id"] \
= self.data.e_r_of1c.id
form["currency-1-debit-1-account_code"] = self.data.e_r_of1c.account
= self.data.l_r_of1c.id
form["currency-1-debit-1-account_code"] = self.data.l_r_of1c.account
response = self.client.post(store_uri, data=form)
self.assertEqual(response.status_code, 302)
self.assertEqual(response.headers["Location"], create_uri)
@ -519,13 +519,13 @@ class OffsetTestCase(unittest.TestCase):
:return: None.
"""
from accounting.models import Account, JournalEntry
journal_entry_data: JournalEntryData = self.data.v_p_of2
journal_entry_data: JournalEntryData = self.data.j_p_of2
edit_uri: str = f"{PREFIX}/{journal_entry_data.id}/edit?next=%2F_next"
update_uri: str = f"{PREFIX}/{journal_entry_data.id}/update"
form: dict[str, str]
response: httpx.Response
journal_entry_data.days = self.data.v_p_or2.days
journal_entry_data.days = self.data.j_p_or2.days
journal_entry_data.currencies[0].debit[0].amount = Decimal("1100")
journal_entry_data.currencies[0].credit[0].amount = Decimal("1100")
journal_entry_data.currencies[0].debit[2].amount = Decimal("900")
@ -541,8 +541,8 @@ class OffsetTestCase(unittest.TestCase):
# The same debit or credit
form = journal_entry_data.update_form(self.csrf_token)
form["currency-1-debit-1-original_line_item_id"] \
= self.data.e_r_or1d.id
form["currency-1-debit-1-account_code"] = self.data.e_r_or1d.account
= self.data.l_r_or1d.id
form["currency-1-debit-1-account_code"] = self.data.l_r_or1d.account
form["currency-1-debit-1-amount"] = "100"
form["currency-1-credit-1-amount"] = "100"
response = self.client.post(update_uri, data=form)
@ -566,8 +566,8 @@ class OffsetTestCase(unittest.TestCase):
# The original line item is also an offset
form = journal_entry_data.update_form(self.csrf_token)
form["currency-1-debit-1-original_line_item_id"] \
= self.data.e_r_of1c.id
form["currency-1-debit-1-account_code"] = self.data.e_r_of1c.account
= self.data.l_r_of1c.id
form["currency-1-debit-1-account_code"] = self.data.l_r_of1c.account
response = self.client.post(update_uri, data=form)
self.assertEqual(response.status_code, 302)
self.assertEqual(response.headers["Location"], edit_uri)
@ -636,13 +636,13 @@ class OffsetTestCase(unittest.TestCase):
:return: None.
"""
from accounting.models import JournalEntry
journal_entry_data: JournalEntryData = self.data.v_p_or1
journal_entry_data: JournalEntryData = self.data.j_p_or1
edit_uri: str = f"{PREFIX}/{journal_entry_data.id}/edit?next=%2F_next"
update_uri: str = f"{PREFIX}/{journal_entry_data.id}/update"
form: dict[str, str]
response: httpx.Response
journal_entry_data.days = self.data.v_p_of1.days
journal_entry_data.days = self.data.j_p_of1.days
journal_entry_data.currencies[0].debit[0].amount = Decimal("1200")
journal_entry_data.currencies[0].credit[0].amount = Decimal("1200")
journal_entry_data.currencies[0].debit[1].amount = Decimal("0.9")
@ -716,7 +716,7 @@ class OffsetTestCase(unittest.TestCase):
JournalEntry, journal_entry_data.id)
self.assertIsNotNone(journal_entry_or)
journal_entry_of: JournalEntry | None = db.session.get(
JournalEntry, self.data.v_p_of1.id)
JournalEntry, self.data.j_p_of1.id)
self.assertIsNotNone(journal_entry_of)
self.assertEqual(journal_entry_or.date, journal_entry_of.date)
self.assertLess(journal_entry_or.no, journal_entry_of.no)

View File

@ -189,102 +189,102 @@ class TestData:
JournalEntryLineItemData(credit, description, amount)
# Receivable original line items
self.e_r_or1d, self.e_r_or1c = couple(
self.l_r_or1d, self.l_r_or1c = couple(
"Accountant", "1200", Accounts.RECEIVABLE, Accounts.SERVICE)
self.e_r_or2d, self.e_r_or2c = couple(
self.l_r_or2d, self.l_r_or2c = couple(
"Toy", "600", Accounts.RECEIVABLE, Accounts.SALES)
self.e_r_or3d, self.e_r_or3c = couple(
self.l_r_or3d, self.l_r_or3c = couple(
"Noodles", "100", Accounts.RECEIVABLE, Accounts.SALES)
self.e_r_or4d, self.e_r_or4c = couple(
self.l_r_or4d, self.l_r_or4c = couple(
"Interest", "3.4", Accounts.RECEIVABLE, Accounts.INTEREST)
# Payable original line items
self.e_p_or1d, self.e_p_or1c = couple(
self.l_p_or1d, self.l_p_or1c = couple(
"Airplane", "2000", Accounts.TRAVEL, Accounts.PAYABLE)
self.e_p_or2d, self.e_p_or2c = couple(
self.l_p_or2d, self.l_p_or2c = couple(
"Phone", "900", Accounts.OFFICE, Accounts.PAYABLE)
self.e_p_or3d, self.e_p_or3c = couple(
self.l_p_or3d, self.l_p_or3c = couple(
"Steak", "120", Accounts.MEAL, Accounts.PAYABLE)
self.e_p_or4d, self.e_p_or4c = couple(
self.l_p_or4d, self.l_p_or4c = couple(
"Envelop", "0.9", Accounts.OFFICE, Accounts.PAYABLE)
# Original journal entries
self.v_r_or1: JournalEntryData = JournalEntryData(
50, [CurrencyData("USD", [self.e_r_or1d, self.e_r_or4d],
[self.e_r_or1c, self.e_r_or4c])])
self.v_r_or2: JournalEntryData = JournalEntryData(
30, [CurrencyData("USD", [self.e_r_or2d, self.e_r_or3d],
[self.e_r_or2c, self.e_r_or3c])])
self.v_p_or1: JournalEntryData = JournalEntryData(
40, [CurrencyData("USD", [self.e_p_or1d, self.e_p_or4d],
[self.e_p_or1c, self.e_p_or4c])])
self.v_p_or2: JournalEntryData = JournalEntryData(
20, [CurrencyData("USD", [self.e_p_or2d, self.e_p_or3d],
[self.e_p_or2c, self.e_p_or3c])])
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.v_r_or1)
self.__add_journal_entry(self.v_r_or2)
self.__add_journal_entry(self.v_p_or1)
self.__add_journal_entry(self.v_p_or2)
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.e_r_of1d, self.e_r_of1c = couple(
self.l_r_of1d, self.l_r_of1c = couple(
"Accountant", "500", Accounts.CASH, Accounts.RECEIVABLE)
self.e_r_of1c.original_line_item = self.e_r_or1d
self.e_r_of2d, self.e_r_of2c = couple(
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.e_r_of2c.original_line_item = self.e_r_or1d
self.e_r_of3d, self.e_r_of3c = couple(
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.e_r_of3c.original_line_item = self.e_r_or1d
self.e_r_of4d, self.e_r_of4c = couple(
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.e_r_of4c.original_line_item = self.e_r_or2d
self.e_r_of5d, self.e_r_of5c = couple(
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.e_r_of5c.original_line_item = self.e_r_or4d
self.l_r_of5c.original_line_item = self.l_r_or4d
# Payable offset items
self.e_p_of1d, self.e_p_of1c = couple(
self.l_p_of1d, self.l_p_of1c = couple(
"Airplane", "800", Accounts.PAYABLE, Accounts.CASH)
self.e_p_of1d.original_line_item = self.e_p_or1c
self.e_p_of2d, self.e_p_of2c = couple(
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.e_p_of2d.original_line_item = self.e_p_or1c
self.e_p_of3d, self.e_p_of3c = couple(
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.e_p_of3d.original_line_item = self.e_p_or1c
self.e_p_of4d, self.e_p_of4c = couple(
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.e_p_of4d.original_line_item = self.e_p_or2c
self.e_p_of5d, self.e_p_of5c = couple(
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.e_p_of5d.original_line_item = self.e_p_or4c
self.l_p_of5d.original_line_item = self.l_p_or4c
# Offset journal entries
self.v_r_of1: JournalEntryData = JournalEntryData(
25, [CurrencyData("USD", [self.e_r_of1d], [self.e_r_of1c])])
self.v_r_of2: JournalEntryData = JournalEntryData(
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.e_r_of2d, self.e_r_of3d, self.e_r_of4d],
[self.e_r_of2c, self.e_r_of3c, self.e_r_of4c])])
self.v_r_of3: JournalEntryData = JournalEntryData(
15, [CurrencyData("USD", [self.e_r_of5d], [self.e_r_of5c])])
self.v_p_of1: JournalEntryData = JournalEntryData(
15, [CurrencyData("USD", [self.e_p_of1d], [self.e_p_of1c])])
self.v_p_of2: JournalEntryData = JournalEntryData(
[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.e_p_of2d, self.e_p_of3d, self.e_p_of4d],
[self.e_p_of2c, self.e_p_of3c, self.e_p_of4c])])
self.v_p_of3: JournalEntryData = JournalEntryData(
5, [CurrencyData("USD", [self.e_p_of5d], [self.e_p_of5c])])
[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.v_r_of1)
self.__add_journal_entry(self.v_r_of2)
self.__add_journal_entry(self.v_r_of3)
self.__add_journal_entry(self.v_p_of1)
self.__add_journal_entry(self.v_p_of2)
self.__add_journal_entry(self.v_p_of3)
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: