Renamed the CurrencyData class to JournalEntryCurrencyData in testlib_offset.py, to be clear.

This commit is contained in:
依瑪貓 2023-04-09 10:04:12 +08:00
parent bb5383febe
commit f47e9b3150
3 changed files with 109 additions and 68 deletions

View File

@ -28,8 +28,8 @@ from flask.testing import FlaskCliRunner
from test_site import db from test_site import db
from testlib import Accounts, create_test_app, get_client from testlib import Accounts, create_test_app, get_client
from testlib_journal_entry import match_journal_entry_detail from testlib_journal_entry import match_journal_entry_detail
from testlib_offset import TestData, JournalEntryLineItemData, \ from testlib_offset import JournalEntryData, JournalEntryCurrencyData, \
JournalEntryData, CurrencyData JournalEntryLineItemData, TestData
PREFIX: str = "/accounting/journal-entries" PREFIX: str = "/accounting/journal-entries"
"""The URL prefix for the journal entry management.""" """The URL prefix for the journal entry management."""
@ -81,7 +81,7 @@ class OffsetTestCase(unittest.TestCase):
response: httpx.Response response: httpx.Response
journal_entry_data: JournalEntryData = JournalEntryData( journal_entry_data: JournalEntryData = JournalEntryData(
self.data.l_r_or3d.journal_entry.days, [CurrencyData( self.data.l_r_or3d.journal_entry.days, [JournalEntryCurrencyData(
"USD", "USD",
[], [],
[JournalEntryLineItemData( [JournalEntryLineItemData(
@ -405,7 +405,7 @@ class OffsetTestCase(unittest.TestCase):
response: httpx.Response response: httpx.Response
journal_entry_data: JournalEntryData = JournalEntryData( journal_entry_data: JournalEntryData = JournalEntryData(
self.data.l_p_or3c.journal_entry.days, [CurrencyData( self.data.l_p_or3c.journal_entry.days, [JournalEntryCurrencyData(
"USD", "USD",
[JournalEntryLineItemData( [JournalEntryLineItemData(
Accounts.PAYABLE, Accounts.PAYABLE,

View File

@ -26,7 +26,8 @@ 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_offset import BaseTestData, JournalEntryData, CurrencyData from testlib_offset import JournalEntryData, JournalEntryCurrencyData, \
BaseTestData
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."""
@ -432,17 +433,21 @@ class DifferentTestData(BaseTestData):
# Original journal entries # Original journal entries
self.j_r_or1: JournalEntryData = JournalEntryData( self.j_r_or1: JournalEntryData = JournalEntryData(
50, [CurrencyData("USD", [self.l_r_or1d, self.l_r_or4d], 50, [JournalEntryCurrencyData(
[self.l_r_or1c, self.l_r_or4c])]) "USD", [self.l_r_or1d, self.l_r_or4d],
[self.l_r_or1c, self.l_r_or4c])])
self.j_r_or2: JournalEntryData = JournalEntryData( self.j_r_or2: JournalEntryData = JournalEntryData(
30, [CurrencyData("USD", [self.l_r_or2d, self.l_r_or3d], 30, [JournalEntryCurrencyData(
[self.l_r_or2c, self.l_r_or3c])]) "USD", [self.l_r_or2d, self.l_r_or3d],
[self.l_r_or2c, self.l_r_or3c])])
self.j_p_or1: JournalEntryData = JournalEntryData( self.j_p_or1: JournalEntryData = JournalEntryData(
40, [CurrencyData("USD", [self.l_p_or1d, self.l_p_or4d], 40, [JournalEntryCurrencyData(
[self.l_p_or1c, self.l_p_or4c])]) "USD", [self.l_p_or1d, self.l_p_or4d],
[self.l_p_or1c, self.l_p_or4c])])
self.j_p_or2: JournalEntryData = JournalEntryData( self.j_p_or2: JournalEntryData = JournalEntryData(
20, [CurrencyData("USD", [self.l_p_or2d, self.l_p_or3d], 20, [JournalEntryCurrencyData(
[self.l_p_or2c, self.l_p_or3c])]) "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_or1)
self._add_journal_entry(self.j_r_or2) self._add_journal_entry(self.j_r_or2)
@ -475,21 +480,25 @@ class DifferentTestData(BaseTestData):
# Offset journal entries # Offset journal entries
self.j_r_of1: JournalEntryData = JournalEntryData( self.j_r_of1: JournalEntryData = JournalEntryData(
25, [CurrencyData("USD", [self.l_r_of1d], [self.l_r_of1c])]) 25, [JournalEntryCurrencyData(
"USD", [self.l_r_of1d], [self.l_r_of1c])])
self.j_r_of2: JournalEntryData = JournalEntryData( self.j_r_of2: JournalEntryData = JournalEntryData(
20, [CurrencyData("USD", 20, [JournalEntryCurrencyData(
[self.l_r_of2d, self.l_r_of3d, self.l_r_of4d], "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.l_r_of2c, self.l_r_of3c, self.l_r_of4c])])
self.j_r_of3: JournalEntryData = JournalEntryData( self.j_r_of3: JournalEntryData = JournalEntryData(
15, [CurrencyData("USD", [self.l_r_of5d], [self.l_r_of5c])]) 15, [JournalEntryCurrencyData(
"USD", [self.l_r_of5d], [self.l_r_of5c])])
self.j_p_of1: JournalEntryData = JournalEntryData( self.j_p_of1: JournalEntryData = JournalEntryData(
15, [CurrencyData("USD", [self.l_p_of1d], [self.l_p_of1c])]) 15, [JournalEntryCurrencyData(
"USD", [self.l_p_of1d], [self.l_p_of1c])])
self.j_p_of2: JournalEntryData = JournalEntryData( self.j_p_of2: JournalEntryData = JournalEntryData(
10, [CurrencyData("USD", 10, [JournalEntryCurrencyData(
[self.l_p_of2d, self.l_p_of3d, self.l_p_of4d], "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.l_p_of2c, self.l_p_of3c, self.l_p_of4c])])
self.j_p_of3: JournalEntryData = JournalEntryData( self.j_p_of3: JournalEntryData = JournalEntryData(
5, [CurrencyData("USD", [self.l_p_of5d], [self.l_p_of5c])]) 5, [JournalEntryCurrencyData(
"USD", [self.l_p_of5d], [self.l_p_of5c])])
self._set_is_need_offset({Accounts.RECEIVABLE, Accounts.PAYABLE}, self._set_is_need_offset({Accounts.RECEIVABLE, Accounts.PAYABLE},
False) False)
@ -537,29 +546,41 @@ class SameTestData(BaseTestData):
# Original journal entries # Original journal entries
self.j_r_or1: JournalEntryData = JournalEntryData( self.j_r_or1: JournalEntryData = JournalEntryData(
60, [CurrencyData("USD", [self.l_r_or1d], [self.l_r_or1c])]) 60, [JournalEntryCurrencyData(
"USD", [self.l_r_or1d], [self.l_r_or1c])])
self.j_r_or2: JournalEntryData = JournalEntryData( self.j_r_or2: JournalEntryData = JournalEntryData(
50, [CurrencyData("USD", [self.l_r_or2d], [self.l_r_or2c])]) 50, [JournalEntryCurrencyData(
"USD", [self.l_r_or2d], [self.l_r_or2c])])
self.j_r_or3: JournalEntryData = JournalEntryData( self.j_r_or3: JournalEntryData = JournalEntryData(
40, [CurrencyData("USD", [self.l_r_or3d], [self.l_r_or3c])]) 40, [JournalEntryCurrencyData(
"USD", [self.l_r_or3d], [self.l_r_or3c])])
self.j_r_or4: JournalEntryData = JournalEntryData( self.j_r_or4: JournalEntryData = JournalEntryData(
30, [CurrencyData("USD", [self.l_r_or4d], [self.l_r_or4c])]) 30, [JournalEntryCurrencyData(
"USD", [self.l_r_or4d], [self.l_r_or4c])])
self.j_r_or5: JournalEntryData = JournalEntryData( self.j_r_or5: JournalEntryData = JournalEntryData(
20, [CurrencyData("USD", [self.l_r_or5d], [self.l_r_or5c])]) 20, [JournalEntryCurrencyData(
"USD", [self.l_r_or5d], [self.l_r_or5c])])
self.j_r_or6: JournalEntryData = JournalEntryData( self.j_r_or6: JournalEntryData = JournalEntryData(
10, [CurrencyData("USD", [self.l_r_or6d], [self.l_r_or6c])]) 10, [JournalEntryCurrencyData(
"USD", [self.l_r_or6d], [self.l_r_or6c])])
self.j_p_or1: JournalEntryData = JournalEntryData( self.j_p_or1: JournalEntryData = JournalEntryData(
60, [CurrencyData("USD", [self.l_p_or1d], [self.l_p_or1c])]) 60, [JournalEntryCurrencyData(
"USD", [self.l_p_or1d], [self.l_p_or1c])])
self.j_p_or2: JournalEntryData = JournalEntryData( self.j_p_or2: JournalEntryData = JournalEntryData(
50, [CurrencyData("USD", [self.l_p_or2d], [self.l_p_or2c])]) 50, [JournalEntryCurrencyData(
"USD", [self.l_p_or2d], [self.l_p_or2c])])
self.j_p_or3: JournalEntryData = JournalEntryData( self.j_p_or3: JournalEntryData = JournalEntryData(
40, [CurrencyData("USD", [self.l_p_or3d], [self.l_p_or3c])]) 40, [JournalEntryCurrencyData(
"USD", [self.l_p_or3d], [self.l_p_or3c])])
self.j_p_or4: JournalEntryData = JournalEntryData( self.j_p_or4: JournalEntryData = JournalEntryData(
30, [CurrencyData("USD", [self.l_p_or4d], [self.l_p_or4c])]) 30, [JournalEntryCurrencyData(
"USD", [self.l_p_or4d], [self.l_p_or4c])])
self.j_p_or5: JournalEntryData = JournalEntryData( self.j_p_or5: JournalEntryData = JournalEntryData(
20, [CurrencyData("USD", [self.l_p_or5d], [self.l_p_or5c])]) 20, [JournalEntryCurrencyData(
"USD", [self.l_p_or5d], [self.l_p_or5c])])
self.j_p_or6: JournalEntryData = JournalEntryData( self.j_p_or6: JournalEntryData = JournalEntryData(
10, [CurrencyData("USD", [self.l_p_or6d], [self.l_p_or6c])]) 10, [JournalEntryCurrencyData(
"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)
@ -606,29 +627,41 @@ class SameTestData(BaseTestData):
# Offset journal entries # Offset journal entries
self.j_r_of1: JournalEntryData = JournalEntryData( self.j_r_of1: JournalEntryData = JournalEntryData(
65, [CurrencyData("USD", [self.l_r_of1d], [self.l_r_of1c])]) 65, [JournalEntryCurrencyData(
"USD", [self.l_r_of1d], [self.l_r_of1c])])
self.j_r_of2: JournalEntryData = JournalEntryData( self.j_r_of2: JournalEntryData = JournalEntryData(
35, [CurrencyData("USD", [self.l_r_of2d], [self.l_r_of2c])]) 35, [JournalEntryCurrencyData(
"USD", [self.l_r_of2d], [self.l_r_of2c])])
self.j_r_of3: JournalEntryData = JournalEntryData( self.j_r_of3: JournalEntryData = JournalEntryData(
35, [CurrencyData("USD", [self.l_r_of3d], [self.l_r_of3c])]) 35, [JournalEntryCurrencyData(
"USD", [self.l_r_of3d], [self.l_r_of3c])])
self.j_r_of4: JournalEntryData = JournalEntryData( self.j_r_of4: JournalEntryData = JournalEntryData(
35, [CurrencyData("USD", [self.l_r_of4d], [self.l_r_of4c])]) 35, [JournalEntryCurrencyData(
"USD", [self.l_r_of4d], [self.l_r_of4c])])
self.j_r_of5: JournalEntryData = JournalEntryData( self.j_r_of5: JournalEntryData = JournalEntryData(
35, [CurrencyData("USD", [self.l_r_of5d], [self.l_r_of5c])]) 35, [JournalEntryCurrencyData(
"USD", [self.l_r_of5d], [self.l_r_of5c])])
self.j_r_of6: JournalEntryData = JournalEntryData( self.j_r_of6: JournalEntryData = JournalEntryData(
15, [CurrencyData("USD", [self.l_r_of6d], [self.l_r_of6c])]) 15, [JournalEntryCurrencyData(
"USD", [self.l_r_of6d], [self.l_r_of6c])])
self.j_p_of1: JournalEntryData = JournalEntryData( self.j_p_of1: JournalEntryData = JournalEntryData(
65, [CurrencyData("USD", [self.l_p_of1d], [self.l_p_of1c])]) 65, [JournalEntryCurrencyData(
"USD", [self.l_p_of1d], [self.l_p_of1c])])
self.j_p_of2: JournalEntryData = JournalEntryData( self.j_p_of2: JournalEntryData = JournalEntryData(
35, [CurrencyData("USD", [self.l_p_of2d], [self.l_p_of2c])]) 35, [JournalEntryCurrencyData(
"USD", [self.l_p_of2d], [self.l_p_of2c])])
self.j_p_of3: JournalEntryData = JournalEntryData( self.j_p_of3: JournalEntryData = JournalEntryData(
35, [CurrencyData("USD", [self.l_p_of3d], [self.l_p_of3c])]) 35, [JournalEntryCurrencyData(
"USD", [self.l_p_of3d], [self.l_p_of3c])])
self.j_p_of4: JournalEntryData = JournalEntryData( self.j_p_of4: JournalEntryData = JournalEntryData(
35, [CurrencyData("USD", [self.l_p_of4d], [self.l_p_of4c])]) 35, [JournalEntryCurrencyData(
"USD", [self.l_p_of4d], [self.l_p_of4c])])
self.j_p_of5: JournalEntryData = JournalEntryData( self.j_p_of5: JournalEntryData = JournalEntryData(
35, [CurrencyData("USD", [self.l_p_of5d], [self.l_p_of5c])]) 35, [JournalEntryCurrencyData(
"USD", [self.l_p_of5d], [self.l_p_of5c])])
self.j_p_of6: JournalEntryData = JournalEntryData( self.j_p_of6: JournalEntryData = JournalEntryData(
15, [CurrencyData("USD", [self.l_p_of6d], [self.l_p_of6c])]) 15, [JournalEntryCurrencyData(
"USD", [self.l_p_of6d], [self.l_p_of6c])])
self._set_is_need_offset({Accounts.RECEIVABLE, Accounts.PAYABLE}, self._set_is_need_offset({Accounts.RECEIVABLE, Accounts.PAYABLE},
False) False)

View File

@ -76,7 +76,7 @@ class JournalEntryLineItemData:
return form return form
class CurrencyData: class JournalEntryCurrencyData:
"""The journal entry currency data.""" """The journal entry currency data."""
def __init__(self, currency: str, debit: list[JournalEntryLineItemData], def __init__(self, currency: str, debit: list[JournalEntryLineItemData],
@ -111,7 +111,7 @@ class CurrencyData:
class JournalEntryData: class JournalEntryData:
"""The journal entry data.""" """The journal entry data."""
def __init__(self, days: int, currencies: list[CurrencyData]): def __init__(self, days: int, currencies: list[JournalEntryCurrencyData]):
"""Constructs a journal entry. """Constructs a journal entry.
:param days: The number of days before today. :param days: The number of days before today.
@ -119,7 +119,7 @@ class JournalEntryData:
""" """
self.id: int = -1 self.id: int = -1
self.days: int = days self.days: int = days
self.currencies: list[CurrencyData] = currencies self.currencies: list[JournalEntryCurrencyData] = currencies
self.note: str | None = None self.note: str | None = None
for currency in self.currencies: for currency in self.currencies:
for line_item in currency.debit: for line_item in currency.debit:
@ -269,17 +269,21 @@ class TestData(BaseTestData):
# Original journal entries # Original journal entries
self.j_r_or1: JournalEntryData = JournalEntryData( self.j_r_or1: JournalEntryData = JournalEntryData(
50, [CurrencyData("USD", [self.l_r_or1d, self.l_r_or4d], 50, [JournalEntryCurrencyData(
[self.l_r_or1c, self.l_r_or4c])]) "USD", [self.l_r_or1d, self.l_r_or4d],
[self.l_r_or1c, self.l_r_or4c])])
self.j_r_or2: JournalEntryData = JournalEntryData( self.j_r_or2: JournalEntryData = JournalEntryData(
30, [CurrencyData("USD", [self.l_r_or2d, self.l_r_or3d], 30, [JournalEntryCurrencyData(
[self.l_r_or2c, self.l_r_or3c])]) "USD", [self.l_r_or2d, self.l_r_or3d],
[self.l_r_or2c, self.l_r_or3c])])
self.j_p_or1: JournalEntryData = JournalEntryData( self.j_p_or1: JournalEntryData = JournalEntryData(
40, [CurrencyData("USD", [self.l_p_or1d, self.l_p_or4d], 40, [JournalEntryCurrencyData(
[self.l_p_or1c, self.l_p_or4c])]) "USD", [self.l_p_or1d, self.l_p_or4d],
[self.l_p_or1c, self.l_p_or4c])])
self.j_p_or2: JournalEntryData = JournalEntryData( self.j_p_or2: JournalEntryData = JournalEntryData(
20, [CurrencyData("USD", [self.l_p_or2d, self.l_p_or3d], 20, [JournalEntryCurrencyData(
[self.l_p_or2c, self.l_p_or3c])]) "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_or1)
self._add_journal_entry(self.j_r_or2) self._add_journal_entry(self.j_r_or2)
@ -322,21 +326,25 @@ class TestData(BaseTestData):
# Offset journal entries # Offset journal entries
self.j_r_of1: JournalEntryData = JournalEntryData( self.j_r_of1: JournalEntryData = JournalEntryData(
25, [CurrencyData("USD", [self.l_r_of1d], [self.l_r_of1c])]) 25, [JournalEntryCurrencyData(
"USD", [self.l_r_of1d], [self.l_r_of1c])])
self.j_r_of2: JournalEntryData = JournalEntryData( self.j_r_of2: JournalEntryData = JournalEntryData(
20, [CurrencyData("USD", 20, [JournalEntryCurrencyData(
[self.l_r_of2d, self.l_r_of3d, self.l_r_of4d], "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.l_r_of2c, self.l_r_of3c, self.l_r_of4c])])
self.j_r_of3: JournalEntryData = JournalEntryData( self.j_r_of3: JournalEntryData = JournalEntryData(
15, [CurrencyData("USD", [self.l_r_of5d], [self.l_r_of5c])]) 15, [JournalEntryCurrencyData(
"USD", [self.l_r_of5d], [self.l_r_of5c])])
self.j_p_of1: JournalEntryData = JournalEntryData( self.j_p_of1: JournalEntryData = JournalEntryData(
15, [CurrencyData("USD", [self.l_p_of1d], [self.l_p_of1c])]) 15, [JournalEntryCurrencyData(
"USD", [self.l_p_of1d], [self.l_p_of1c])])
self.j_p_of2: JournalEntryData = JournalEntryData( self.j_p_of2: JournalEntryData = JournalEntryData(
10, [CurrencyData("USD", 10, [JournalEntryCurrencyData(
[self.l_p_of2d, self.l_p_of3d, self.l_p_of4d], "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.l_p_of2c, self.l_p_of3c, self.l_p_of4c])])
self.j_p_of3: JournalEntryData = JournalEntryData( self.j_p_of3: JournalEntryData = JournalEntryData(
5, [CurrencyData("USD", [self.l_p_of5d], [self.l_p_of5c])]) 5, [JournalEntryCurrencyData(
"USD", [self.l_p_of5d], [self.l_p_of5c])])
self._add_journal_entry(self.j_r_of1) self._add_journal_entry(self.j_r_of1)
self._add_journal_entry(self.j_r_of2) self._add_journal_entry(self.j_r_of2)