Renamed "journal entry" to "voucher line item", and "entry type" to "side".

This commit is contained in:
2023-03-19 21:00:11 +08:00
parent 25c45b16ae
commit c1235608d8
58 changed files with 1961 additions and 1926 deletions

View File

@ -27,7 +27,7 @@ from flask.testing import FlaskCliRunner
from test_site import db
from testlib import create_test_app, get_client
from testlib_offset import TestData, JournalEntryData, VoucherData, \
from testlib_offset import TestData, VoucherLineItemData, VoucherData, \
CurrencyData
from testlib_voucher import Accounts, match_voucher_detail
@ -49,7 +49,7 @@ class OffsetTestCase(unittest.TestCase):
runner: FlaskCliRunner = self.app.test_cli_runner()
with self.app.app_context():
from accounting.models import BaseAccount, Voucher, \
JournalEntry
VoucherLineItem
result: Result
result = runner.invoke(args="init-db")
self.assertEqual(result.exit_code, 0)
@ -63,7 +63,7 @@ class OffsetTestCase(unittest.TestCase):
"-u", "editor"])
self.assertEqual(result.exit_code, 0)
Voucher.query.delete()
JournalEntry.query.delete()
VoucherLineItem.query.delete()
self.client, self.csrf_token = get_client(self.app, "editor")
self.data: TestData = TestData(self.app, self.client, self.csrf_token)
@ -84,33 +84,34 @@ class OffsetTestCase(unittest.TestCase):
self.data.e_r_or3d.voucher.days, [CurrencyData(
"USD",
[],
[JournalEntryData(Accounts.RECEIVABLE,
self.data.e_r_or1d.summary, "300",
original_entry=self.data.e_r_or1d),
JournalEntryData(Accounts.RECEIVABLE,
self.data.e_r_or1d.summary, "100",
original_entry=self.data.e_r_or1d),
JournalEntryData(Accounts.RECEIVABLE,
self.data.e_r_or3d.summary, "100",
original_entry=self.data.e_r_or3d)])])
[VoucherLineItemData(Accounts.RECEIVABLE,
self.data.e_r_or1d.summary, "300",
original_line_item=self.data.e_r_or1d),
VoucherLineItemData(Accounts.RECEIVABLE,
self.data.e_r_or1d.summary, "100",
original_line_item=self.data.e_r_or1d),
VoucherLineItemData(Accounts.RECEIVABLE,
self.data.e_r_or3d.summary, "100",
original_line_item=self.data.e_r_or3d)])])
# Non-existing original entry ID
# Non-existing original line item ID
form = voucher_data.new_form(self.csrf_token)
form["currency-1-credit-1-original_entry_id"] = "9999"
form["currency-1-credit-1-original_line_item_id"] = "9999"
response = self.client.post(store_uri, data=form)
self.assertEqual(response.status_code, 302)
self.assertEqual(response.headers["Location"], create_uri)
# The same side
form = voucher_data.new_form(self.csrf_token)
form["currency-1-credit-1-original_entry_id"] = self.data.e_p_or1c.id
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
form["currency-1-credit-1-amount"] = "100"
response = self.client.post(store_uri, data=form)
self.assertEqual(response.status_code, 302)
self.assertEqual(response.headers["Location"], create_uri)
# The original entry does not need offset
# The original line item does not need offset
with self.app.app_context():
account = Account.find_by_code(Accounts.RECEIVABLE)
account.is_need_offset = False
@ -124,9 +125,10 @@ class OffsetTestCase(unittest.TestCase):
account.is_need_offset = True
db.session.commit()
# The original entry is also an offset
# The original line item is also an offset
form = voucher_data.new_form(self.csrf_token)
form["currency-1-credit-1-original_entry_id"] = self.data.e_p_of1d.id
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
response = self.client.post(store_uri, data=form)
self.assertEqual(response.status_code, 302)
@ -164,7 +166,7 @@ class OffsetTestCase(unittest.TestCase):
self.assertEqual(response.status_code, 302)
self.assertEqual(response.headers["Location"], create_uri)
# Not before the original entries
# Not before the original line items
old_days = voucher_data.days
voucher_data.days = old_days + 1
form = voucher_data.new_form(self.csrf_token)
@ -181,7 +183,7 @@ class OffsetTestCase(unittest.TestCase):
with self.app.app_context():
voucher = db.session.get(Voucher, voucher_id)
for offset in voucher.currencies[0].credit:
self.assertIsNotNone(offset.original_entry_id)
self.assertIsNotNone(offset.original_line_item_id)
def test_edit_receivable_offset(self) -> None:
"""Tests to edit the receivable offset.
@ -201,16 +203,17 @@ class OffsetTestCase(unittest.TestCase):
voucher_data.currencies[0].debit[2].amount = Decimal("600")
voucher_data.currencies[0].credit[2].amount = Decimal("600")
# Non-existing original entry ID
# Non-existing original line item ID
form = voucher_data.update_form(self.csrf_token)
form["currency-1-credit-1-original_entry_id"] = "9999"
form["currency-1-credit-1-original_line_item_id"] = "9999"
response = self.client.post(update_uri, data=form)
self.assertEqual(response.status_code, 302)
self.assertEqual(response.headers["Location"], edit_uri)
# The same side
form = voucher_data.update_form(self.csrf_token)
form["currency-1-credit-1-original_entry_id"] = self.data.e_p_or1c.id
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
form["currency-1-debit-1-amount"] = "100"
form["currency-1-credit-1-amount"] = "100"
@ -218,7 +221,7 @@ class OffsetTestCase(unittest.TestCase):
self.assertEqual(response.status_code, 302)
self.assertEqual(response.headers["Location"], edit_uri)
# The original entry does not need offset
# The original line item does not need offset
with self.app.app_context():
account = Account.find_by_code(Accounts.RECEIVABLE)
account.is_need_offset = False
@ -232,9 +235,10 @@ class OffsetTestCase(unittest.TestCase):
account.is_need_offset = True
db.session.commit()
# The original entry is also an offset
# The original line item is also an offset
form = voucher_data.update_form(self.csrf_token)
form["currency-1-credit-1-original_entry_id"] = self.data.e_p_of1d.id
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
response = self.client.post(update_uri, data=form)
self.assertEqual(response.status_code, 302)
@ -276,7 +280,7 @@ class OffsetTestCase(unittest.TestCase):
self.assertEqual(response.status_code, 302)
self.assertEqual(response.headers["Location"], edit_uri)
# Not before the original entries
# Not before the original line items
old_days: int = voucher_data.days
voucher_data.days = old_days + 1
form = voucher_data.update_form(self.csrf_token)
@ -292,8 +296,8 @@ class OffsetTestCase(unittest.TestCase):
self.assertEqual(response.headers["Location"],
f"{PREFIX}/{voucher_data.id}?next=%2F_next")
def test_edit_receivable_original_entry(self) -> None:
"""Tests to edit the receivable original entry.
def test_edit_receivable_original_line_item(self) -> None:
"""Tests to edit the receivable original line item.
:return: None.
"""
@ -346,7 +350,7 @@ class OffsetTestCase(unittest.TestCase):
self.assertEqual(response.status_code, 302)
self.assertEqual(response.headers["Location"], edit_uri)
# Not after the offset entries
# Not after the offset items
old_days: int = voucher_data.days
voucher_data.days = old_days - 1
form = voucher_data.update_form(self.csrf_token)
@ -355,7 +359,7 @@ class OffsetTestCase(unittest.TestCase):
self.assertEqual(response.headers["Location"], edit_uri)
voucher_data.days = old_days
# Not deleting matched original entries
# Not deleting matched original line items
form = voucher_data.update_form(self.csrf_token)
del form["currency-1-debit-1-eid"]
response = self.client.post(update_uri, data=form)
@ -369,8 +373,8 @@ class OffsetTestCase(unittest.TestCase):
self.assertEqual(response.headers["Location"],
f"{PREFIX}/{voucher_data.id}?next=%2F_next")
# The original entry is always before the offset entry, even when they
# happen in the same day.
# The original line item is always before the offset item, even when
# they happen in the same day.
with self.app.app_context():
voucher_or: Voucher | None = db.session.get(
Voucher, voucher_data.id)
@ -395,34 +399,35 @@ class OffsetTestCase(unittest.TestCase):
voucher_data: VoucherData = VoucherData(
self.data.e_p_or3c.voucher.days, [CurrencyData(
"USD",
[JournalEntryData(Accounts.PAYABLE,
self.data.e_p_or1c.summary, "500",
original_entry=self.data.e_p_or1c),
JournalEntryData(Accounts.PAYABLE,
self.data.e_p_or1c.summary, "300",
original_entry=self.data.e_p_or1c),
JournalEntryData(Accounts.PAYABLE,
self.data.e_p_or3c.summary, "120",
original_entry=self.data.e_p_or3c)],
[VoucherLineItemData(Accounts.PAYABLE,
self.data.e_p_or1c.summary, "500",
original_line_item=self.data.e_p_or1c),
VoucherLineItemData(Accounts.PAYABLE,
self.data.e_p_or1c.summary, "300",
original_line_item=self.data.e_p_or1c),
VoucherLineItemData(Accounts.PAYABLE,
self.data.e_p_or3c.summary, "120",
original_line_item=self.data.e_p_or3c)],
[])])
# Non-existing original entry ID
# Non-existing original line item ID
form = voucher_data.new_form(self.csrf_token)
form["currency-1-debit-1-original_entry_id"] = "9999"
form["currency-1-debit-1-original_line_item_id"] = "9999"
response = self.client.post(store_uri, data=form)
self.assertEqual(response.status_code, 302)
self.assertEqual(response.headers["Location"], create_uri)
# The same side
form = voucher_data.new_form(self.csrf_token)
form["currency-1-debit-1-original_entry_id"] = self.data.e_r_or1d.id
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
form["currency-1-debit-1-amount"] = "100"
response = self.client.post(store_uri, data=form)
self.assertEqual(response.status_code, 302)
self.assertEqual(response.headers["Location"], create_uri)
# The original entry does not need offset
# The original line item does not need offset
with self.app.app_context():
account = Account.find_by_code(Accounts.PAYABLE)
account.is_need_offset = False
@ -436,9 +441,10 @@ class OffsetTestCase(unittest.TestCase):
account.is_need_offset = True
db.session.commit()
# The original entry is also an offset
# The original line item is also an offset
form = voucher_data.new_form(self.csrf_token)
form["currency-1-debit-1-original_entry_id"] = self.data.e_r_of1c.id
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
response = self.client.post(store_uri, data=form)
self.assertEqual(response.status_code, 302)
@ -474,7 +480,7 @@ class OffsetTestCase(unittest.TestCase):
self.assertEqual(response.status_code, 302)
self.assertEqual(response.headers["Location"], create_uri)
# Not before the original entries
# Not before the original line items
old_days: int = voucher_data.days
voucher_data.days = old_days + 1
form = voucher_data.new_form(self.csrf_token)
@ -491,7 +497,7 @@ class OffsetTestCase(unittest.TestCase):
with self.app.app_context():
voucher = db.session.get(Voucher, voucher_id)
for offset in voucher.currencies[0].debit:
self.assertIsNotNone(offset.original_entry_id)
self.assertIsNotNone(offset.original_line_item_id)
def test_edit_payable_offset(self) -> None:
"""Tests to edit the payable offset.
@ -511,16 +517,17 @@ class OffsetTestCase(unittest.TestCase):
voucher_data.currencies[0].debit[2].amount = Decimal("900")
voucher_data.currencies[0].credit[2].amount = Decimal("900")
# Non-existing original entry ID
# Non-existing original line item ID
form = voucher_data.update_form(self.csrf_token)
form["currency-1-debit-1-original_entry_id"] = "9999"
form["currency-1-debit-1-original_line_item_id"] = "9999"
response = self.client.post(update_uri, data=form)
self.assertEqual(response.status_code, 302)
self.assertEqual(response.headers["Location"], edit_uri)
# The same side
form = voucher_data.update_form(self.csrf_token)
form["currency-1-debit-1-original_entry_id"] = self.data.e_r_or1d.id
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
form["currency-1-debit-1-amount"] = "100"
form["currency-1-credit-1-amount"] = "100"
@ -528,7 +535,7 @@ class OffsetTestCase(unittest.TestCase):
self.assertEqual(response.status_code, 302)
self.assertEqual(response.headers["Location"], edit_uri)
# The original entry does not need offset
# The original line item does not need offset
with self.app.app_context():
account = Account.find_by_code(Accounts.PAYABLE)
account.is_need_offset = False
@ -542,9 +549,10 @@ class OffsetTestCase(unittest.TestCase):
account.is_need_offset = True
db.session.commit()
# The original entry is also an offset
# The original line item is also an offset
form = voucher_data.update_form(self.csrf_token)
form["currency-1-debit-1-original_entry_id"] = self.data.e_r_of1c.id
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
response = self.client.post(update_uri, data=form)
self.assertEqual(response.status_code, 302)
@ -586,7 +594,7 @@ class OffsetTestCase(unittest.TestCase):
self.assertEqual(response.status_code, 302)
self.assertEqual(response.headers["Location"], edit_uri)
# Not before the original entries
# Not before the original line items
old_days: int = voucher_data.days
voucher_data.days = old_days + 1
form = voucher_data.update_form(self.csrf_token)
@ -603,10 +611,10 @@ class OffsetTestCase(unittest.TestCase):
with self.app.app_context():
voucher = db.session.get(Voucher, voucher_id)
for offset in voucher.currencies[0].debit:
self.assertIsNotNone(offset.original_entry_id)
self.assertIsNotNone(offset.original_line_item_id)
def test_edit_payable_original_entry(self) -> None:
"""Tests to edit the payable original entry.
def test_edit_payable_original_line_item(self) -> None:
"""Tests to edit the payable original line item.
:return: None.
"""
@ -659,7 +667,7 @@ class OffsetTestCase(unittest.TestCase):
self.assertEqual(response.status_code, 302)
self.assertEqual(response.headers["Location"], edit_uri)
# Not after the offset entries
# Not after the offset items
old_days: int = voucher_data.days
voucher_data.days = old_days - 1
form = voucher_data.update_form(self.csrf_token)
@ -668,7 +676,7 @@ class OffsetTestCase(unittest.TestCase):
self.assertEqual(response.headers["Location"], edit_uri)
voucher_data.days = old_days
# Not deleting matched original entries
# Not deleting matched original line items
form = voucher_data.update_form(self.csrf_token)
del form["currency-1-credit-1-eid"]
response = self.client.post(update_uri, data=form)
@ -682,8 +690,8 @@ class OffsetTestCase(unittest.TestCase):
self.assertEqual(response.headers["Location"],
f"{PREFIX}/{voucher_data.id}?next=%2F_next")
# The original entry is always before the offset entry, even when they
# happen in the same day
# The original line item is always before the offset item, even when
# they happen in the same day
with self.app.app_context():
voucher_or: Voucher | None = db.session.get(
Voucher, voucher_data.id)