refactor(test): exc gain/loss journal for advance in purchase invoice
This commit is contained in:
parent
78bc712756
commit
5b06bd1af4
@ -1273,10 +1273,11 @@ class TestPurchaseInvoice(unittest.TestCase, StockTestMixin):
|
|||||||
pi.save()
|
pi.save()
|
||||||
pi.submit()
|
pi.submit()
|
||||||
|
|
||||||
|
creditors_account = pi.credit_to
|
||||||
|
|
||||||
expected_gle = [
|
expected_gle = [
|
||||||
["_Test Account Cost for Goods Sold - _TC", 37500.0],
|
["_Test Account Cost for Goods Sold - _TC", 37500.0],
|
||||||
["_Test Payable USD - _TC", -35000.0],
|
["_Test Payable USD - _TC", -37500.0],
|
||||||
["Exchange Gain/Loss - _TC", -2500.0],
|
|
||||||
]
|
]
|
||||||
|
|
||||||
gl_entries = frappe.db.sql(
|
gl_entries = frappe.db.sql(
|
||||||
@ -1293,6 +1294,31 @@ class TestPurchaseInvoice(unittest.TestCase, StockTestMixin):
|
|||||||
self.assertEqual(expected_gle[i][0], gle.account)
|
self.assertEqual(expected_gle[i][0], gle.account)
|
||||||
self.assertEqual(expected_gle[i][1], gle.balance)
|
self.assertEqual(expected_gle[i][1], gle.balance)
|
||||||
|
|
||||||
|
pi.reload()
|
||||||
|
self.assertEqual(pi.outstanding_amount, 0)
|
||||||
|
|
||||||
|
total_debit_amount = frappe.db.get_all(
|
||||||
|
"Journal Entry Account",
|
||||||
|
{"account": creditors_account, "docstatus": 1, "reference_name": pi.name},
|
||||||
|
"sum(debit) as amount",
|
||||||
|
group_by="reference_name",
|
||||||
|
)[0].amount
|
||||||
|
self.assertEqual(flt(total_debit_amount, 2), 2500)
|
||||||
|
jea_parent = frappe.db.get_all(
|
||||||
|
"Journal Entry Account",
|
||||||
|
filters={
|
||||||
|
"account": creditors_account,
|
||||||
|
"docstatus": 1,
|
||||||
|
"reference_name": pi.name,
|
||||||
|
"debit": 2500,
|
||||||
|
"debit_in_account_currency": 0,
|
||||||
|
},
|
||||||
|
fields=["parent"],
|
||||||
|
)[0]
|
||||||
|
self.assertEqual(
|
||||||
|
frappe.db.get_value("Journal Entry", jea_parent.parent, "voucher_type"), "Exchange Gain Or Loss"
|
||||||
|
)
|
||||||
|
|
||||||
pi_2 = make_purchase_invoice(
|
pi_2 = make_purchase_invoice(
|
||||||
supplier="_Test Supplier USD",
|
supplier="_Test Supplier USD",
|
||||||
currency="USD",
|
currency="USD",
|
||||||
@ -1317,10 +1343,12 @@ class TestPurchaseInvoice(unittest.TestCase, StockTestMixin):
|
|||||||
pi_2.save()
|
pi_2.save()
|
||||||
pi_2.submit()
|
pi_2.submit()
|
||||||
|
|
||||||
|
pi_2.reload()
|
||||||
|
self.assertEqual(pi_2.outstanding_amount, 0)
|
||||||
|
|
||||||
expected_gle = [
|
expected_gle = [
|
||||||
["_Test Account Cost for Goods Sold - _TC", 36500.0],
|
["_Test Account Cost for Goods Sold - _TC", 36500.0],
|
||||||
["_Test Payable USD - _TC", -35000.0],
|
["_Test Payable USD - _TC", -36500.0],
|
||||||
["Exchange Gain/Loss - _TC", -1500.0],
|
|
||||||
]
|
]
|
||||||
|
|
||||||
gl_entries = frappe.db.sql(
|
gl_entries = frappe.db.sql(
|
||||||
@ -1351,12 +1379,39 @@ class TestPurchaseInvoice(unittest.TestCase, StockTestMixin):
|
|||||||
self.assertEqual(expected_gle[i][0], gle.account)
|
self.assertEqual(expected_gle[i][0], gle.account)
|
||||||
self.assertEqual(expected_gle[i][1], gle.balance)
|
self.assertEqual(expected_gle[i][1], gle.balance)
|
||||||
|
|
||||||
|
total_debit_amount = frappe.db.get_all(
|
||||||
|
"Journal Entry Account",
|
||||||
|
{"account": creditors_account, "docstatus": 1, "reference_name": pi_2.name},
|
||||||
|
"sum(debit) as amount",
|
||||||
|
group_by="reference_name",
|
||||||
|
)[0].amount
|
||||||
|
self.assertEqual(flt(total_debit_amount, 2), 1500)
|
||||||
|
jea_parent_2 = frappe.db.get_all(
|
||||||
|
"Journal Entry Account",
|
||||||
|
filters={
|
||||||
|
"account": creditors_account,
|
||||||
|
"docstatus": 1,
|
||||||
|
"reference_name": pi_2.name,
|
||||||
|
"debit": 1500,
|
||||||
|
"debit_in_account_currency": 0,
|
||||||
|
},
|
||||||
|
fields=["parent"],
|
||||||
|
)[0]
|
||||||
|
self.assertEqual(
|
||||||
|
frappe.db.get_value("Journal Entry", jea_parent_2.parent, "voucher_type"),
|
||||||
|
"Exchange Gain Or Loss",
|
||||||
|
)
|
||||||
|
|
||||||
pi.reload()
|
pi.reload()
|
||||||
pi.cancel()
|
pi.cancel()
|
||||||
|
|
||||||
|
self.assertEqual(frappe.db.get_value("Journal Entry", jea_parent.parent, "docstatus"), 2)
|
||||||
|
|
||||||
pi_2.reload()
|
pi_2.reload()
|
||||||
pi_2.cancel()
|
pi_2.cancel()
|
||||||
|
|
||||||
|
self.assertEqual(frappe.db.get_value("Journal Entry", jea_parent_2.parent, "docstatus"), 2)
|
||||||
|
|
||||||
pay.reload()
|
pay.reload()
|
||||||
pay.cancel()
|
pay.cancel()
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user