mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-20 13:39:18 +00:00
refactor: use qb for JV tests
This commit is contained in:
@@ -166,43 +166,37 @@ class TestJournalEntry(unittest.TestCase):
|
|||||||
jv.get("accounts")[1].credit_in_account_currency = 5000
|
jv.get("accounts")[1].credit_in_account_currency = 5000
|
||||||
jv.submit()
|
jv.submit()
|
||||||
|
|
||||||
gl_entries = frappe.db.sql(
|
self.voucher_no = jv.name
|
||||||
"""select account, account_currency, debit, credit,
|
|
||||||
debit_in_account_currency, credit_in_account_currency
|
|
||||||
from `tabGL Entry` where voucher_type='Journal Entry' and voucher_no=%s
|
|
||||||
order by account asc""",
|
|
||||||
jv.name,
|
|
||||||
as_dict=1,
|
|
||||||
)
|
|
||||||
|
|
||||||
self.assertTrue(gl_entries)
|
self.fields = [
|
||||||
|
"account",
|
||||||
|
"account_currency",
|
||||||
|
"debit",
|
||||||
|
"debit_in_account_currency",
|
||||||
|
"credit",
|
||||||
|
"credit_in_account_currency",
|
||||||
|
]
|
||||||
|
|
||||||
expected_values = {
|
self.expected_gle = [
|
||||||
"_Test Bank USD - _TC": {
|
{
|
||||||
"account_currency": "USD",
|
"account": "_Test Bank - _TC",
|
||||||
"debit": 5000,
|
|
||||||
"debit_in_account_currency": 100,
|
|
||||||
"credit": 0,
|
|
||||||
"credit_in_account_currency": 0,
|
|
||||||
},
|
|
||||||
"_Test Bank - _TC": {
|
|
||||||
"account_currency": "INR",
|
"account_currency": "INR",
|
||||||
"debit": 0,
|
"debit": 0,
|
||||||
"debit_in_account_currency": 0,
|
"debit_in_account_currency": 0,
|
||||||
"credit": 5000,
|
"credit": 5000,
|
||||||
"credit_in_account_currency": 5000,
|
"credit_in_account_currency": 5000,
|
||||||
},
|
},
|
||||||
}
|
{
|
||||||
|
"account": "_Test Bank USD - _TC",
|
||||||
|
"account_currency": "USD",
|
||||||
|
"debit": 5000,
|
||||||
|
"debit_in_account_currency": 100,
|
||||||
|
"credit": 0,
|
||||||
|
"credit_in_account_currency": 0,
|
||||||
|
},
|
||||||
|
]
|
||||||
|
|
||||||
for field in (
|
self.check_gl_entries()
|
||||||
"account_currency",
|
|
||||||
"debit",
|
|
||||||
"debit_in_account_currency",
|
|
||||||
"credit",
|
|
||||||
"credit_in_account_currency",
|
|
||||||
):
|
|
||||||
for i, gle in enumerate(gl_entries):
|
|
||||||
self.assertEqual(expected_values[gle.account][field], gle[field])
|
|
||||||
|
|
||||||
# cancel
|
# cancel
|
||||||
jv.cancel()
|
jv.cancel()
|
||||||
@@ -228,43 +222,37 @@ class TestJournalEntry(unittest.TestCase):
|
|||||||
rjv.posting_date = nowdate()
|
rjv.posting_date = nowdate()
|
||||||
rjv.submit()
|
rjv.submit()
|
||||||
|
|
||||||
gl_entries = frappe.db.sql(
|
self.voucher_no = rjv.name
|
||||||
"""select account, account_currency, debit, credit,
|
|
||||||
debit_in_account_currency, credit_in_account_currency
|
|
||||||
from `tabGL Entry` where voucher_type='Journal Entry' and voucher_no=%s
|
|
||||||
order by account asc""",
|
|
||||||
rjv.name,
|
|
||||||
as_dict=1,
|
|
||||||
)
|
|
||||||
|
|
||||||
self.assertTrue(gl_entries)
|
self.fields = [
|
||||||
|
"account",
|
||||||
|
"account_currency",
|
||||||
|
"debit",
|
||||||
|
"credit",
|
||||||
|
"debit_in_account_currency",
|
||||||
|
"credit_in_account_currency",
|
||||||
|
]
|
||||||
|
|
||||||
expected_values = {
|
self.expected_gle = [
|
||||||
"_Test Bank USD - _TC": {
|
{
|
||||||
|
"account": "_Test Bank USD - _TC",
|
||||||
"account_currency": "USD",
|
"account_currency": "USD",
|
||||||
"debit": 0,
|
"debit": 0,
|
||||||
"debit_in_account_currency": 0,
|
"debit_in_account_currency": 0,
|
||||||
"credit": 5000,
|
"credit": 5000,
|
||||||
"credit_in_account_currency": 100,
|
"credit_in_account_currency": 100,
|
||||||
},
|
},
|
||||||
"Sales - _TC": {
|
{
|
||||||
|
"account": "Sales - _TC",
|
||||||
"account_currency": "INR",
|
"account_currency": "INR",
|
||||||
"debit": 5000,
|
"debit": 5000,
|
||||||
"debit_in_account_currency": 5000,
|
"debit_in_account_currency": 5000,
|
||||||
"credit": 0,
|
"credit": 0,
|
||||||
"credit_in_account_currency": 0,
|
"credit_in_account_currency": 0,
|
||||||
},
|
},
|
||||||
}
|
]
|
||||||
|
|
||||||
for field in (
|
self.check_gl_entries()
|
||||||
"account_currency",
|
|
||||||
"debit",
|
|
||||||
"debit_in_account_currency",
|
|
||||||
"credit",
|
|
||||||
"credit_in_account_currency",
|
|
||||||
):
|
|
||||||
for i, gle in enumerate(gl_entries):
|
|
||||||
self.assertEqual(expected_values[gle.account][field], gle[field])
|
|
||||||
|
|
||||||
def test_disallow_change_in_account_currency_for_a_party(self):
|
def test_disallow_change_in_account_currency_for_a_party(self):
|
||||||
# create jv in USD
|
# create jv in USD
|
||||||
@@ -344,23 +332,25 @@ class TestJournalEntry(unittest.TestCase):
|
|||||||
jv.insert()
|
jv.insert()
|
||||||
jv.submit()
|
jv.submit()
|
||||||
|
|
||||||
expected_values = {
|
self.voucher_no = jv.name
|
||||||
"_Test Cash - _TC": {"cost_center": cost_center},
|
|
||||||
"_Test Bank - _TC": {"cost_center": cost_center},
|
|
||||||
}
|
|
||||||
|
|
||||||
gl_entries = frappe.db.sql(
|
self.fields = [
|
||||||
"""select account, cost_center, debit, credit
|
"account",
|
||||||
from `tabGL Entry` where voucher_type='Journal Entry' and voucher_no=%s
|
"cost_center",
|
||||||
order by account asc""",
|
]
|
||||||
jv.name,
|
|
||||||
as_dict=1,
|
|
||||||
)
|
|
||||||
|
|
||||||
self.assertTrue(gl_entries)
|
self.expected_gle = [
|
||||||
|
{
|
||||||
|
"account": "_Test Bank - _TC",
|
||||||
|
"cost_center": cost_center,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"account": "_Test Cash - _TC",
|
||||||
|
"cost_center": cost_center,
|
||||||
|
},
|
||||||
|
]
|
||||||
|
|
||||||
for gle in gl_entries:
|
self.check_gl_entries()
|
||||||
self.assertEqual(expected_values[gle.account]["cost_center"], gle.cost_center)
|
|
||||||
|
|
||||||
def test_jv_with_project(self):
|
def test_jv_with_project(self):
|
||||||
from erpnext.projects.doctype.project.test_project import make_project
|
from erpnext.projects.doctype.project.test_project import make_project
|
||||||
@@ -387,23 +377,22 @@ class TestJournalEntry(unittest.TestCase):
|
|||||||
jv.insert()
|
jv.insert()
|
||||||
jv.submit()
|
jv.submit()
|
||||||
|
|
||||||
expected_values = {
|
self.voucher_no = jv.name
|
||||||
"_Test Cash - _TC": {"project": project_name},
|
|
||||||
"_Test Bank - _TC": {"project": project_name},
|
|
||||||
}
|
|
||||||
|
|
||||||
gl_entries = frappe.db.sql(
|
self.fields = ["account", "project"]
|
||||||
"""select account, project, debit, credit
|
|
||||||
from `tabGL Entry` where voucher_type='Journal Entry' and voucher_no=%s
|
|
||||||
order by account asc""",
|
|
||||||
jv.name,
|
|
||||||
as_dict=1,
|
|
||||||
)
|
|
||||||
|
|
||||||
self.assertTrue(gl_entries)
|
self.expected_gle = [
|
||||||
|
{
|
||||||
|
"account": "_Test Bank - _TC",
|
||||||
|
"project": project_name,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"account": "_Test Cash - _TC",
|
||||||
|
"project": project_name,
|
||||||
|
},
|
||||||
|
]
|
||||||
|
|
||||||
for gle in gl_entries:
|
self.check_gl_entries()
|
||||||
self.assertEqual(expected_values[gle.account]["project"], gle.project)
|
|
||||||
|
|
||||||
def test_jv_account_and_party_balance_with_cost_centre(self):
|
def test_jv_account_and_party_balance_with_cost_centre(self):
|
||||||
from erpnext.accounts.doctype.cost_center.test_cost_center import create_cost_center
|
from erpnext.accounts.doctype.cost_center.test_cost_center import create_cost_center
|
||||||
@@ -426,6 +415,24 @@ class TestJournalEntry(unittest.TestCase):
|
|||||||
account_balance = get_balance_on(account="_Test Bank - _TC", cost_center=cost_center)
|
account_balance = get_balance_on(account="_Test Bank - _TC", cost_center=cost_center)
|
||||||
self.assertEqual(expected_account_balance, account_balance)
|
self.assertEqual(expected_account_balance, account_balance)
|
||||||
|
|
||||||
|
def check_gl_entries(self):
|
||||||
|
gl = frappe.qb.DocType("GL Entry")
|
||||||
|
query = frappe.qb.from_(gl)
|
||||||
|
for field in self.fields:
|
||||||
|
query = query.select(gl[field])
|
||||||
|
|
||||||
|
query = query.where(
|
||||||
|
(gl.voucher_type == "Journal Entry")
|
||||||
|
& (gl.voucher_no == self.voucher_no)
|
||||||
|
& (gl.is_cancelled == 0)
|
||||||
|
).orderby(gl.account)
|
||||||
|
|
||||||
|
gl_entries = query.run(as_dict=True)
|
||||||
|
|
||||||
|
for i in range(len(self.expected_gle)):
|
||||||
|
for field in self.fields:
|
||||||
|
self.assertEqual(self.expected_gle[i][field], gl_entries[i][field])
|
||||||
|
|
||||||
|
|
||||||
def make_journal_entry(
|
def make_journal_entry(
|
||||||
account1,
|
account1,
|
||||||
|
|||||||
Reference in New Issue
Block a user