mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-22 14:39:19 +00:00
chore: move tests to advance payment ledger doctype
(cherry picked from commit 14cef3d4c4)
This commit is contained in:
@@ -1,8 +1,13 @@
|
|||||||
# Copyright (c) 2024, Frappe Technologies Pvt. Ltd. and Contributors
|
# Copyright (c) 2024, Frappe Technologies Pvt. Ltd. and Contributors
|
||||||
# See license.txt
|
# See license.txt
|
||||||
|
|
||||||
# import frappe
|
import frappe
|
||||||
from frappe.tests import IntegrationTestCase, UnitTestCase
|
from frappe.tests import IntegrationTestCase, UnitTestCase
|
||||||
|
from frappe.utils import nowdate, today
|
||||||
|
|
||||||
|
from erpnext.accounts.doctype.payment_entry.test_payment_entry import get_payment_entry
|
||||||
|
from erpnext.accounts.test.accounts_mixin import AccountsTestMixin
|
||||||
|
from erpnext.selling.doctype.sales_order.test_sales_order import make_sales_order
|
||||||
|
|
||||||
# On IntegrationTestCase, the doctype test records and all
|
# On IntegrationTestCase, the doctype test records and all
|
||||||
# link-field test record depdendencies are recursively loaded
|
# link-field test record depdendencies are recursively loaded
|
||||||
@@ -11,10 +16,115 @@ EXTRA_TEST_RECORD_DEPENDENCIES = [] # eg. ["User"]
|
|||||||
IGNORE_TEST_RECORD_DEPENDENCIES = [] # eg. ["User"]
|
IGNORE_TEST_RECORD_DEPENDENCIES = [] # eg. ["User"]
|
||||||
|
|
||||||
|
|
||||||
class TestAdvancePaymentLedgerEntry(IntegrationTestCase):
|
class TestAdvancePaymentLedgerEntry(AccountsTestMixin, IntegrationTestCase):
|
||||||
"""
|
"""
|
||||||
Integration tests for AdvancePaymentLedgerEntry.
|
Integration tests for AdvancePaymentLedgerEntry.
|
||||||
Use this class for testing interactions between multiple components.
|
Use this class for testing interactions between multiple components.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
pass
|
def setUp(self):
|
||||||
|
self.create_company()
|
||||||
|
self.create_usd_receivable_account()
|
||||||
|
self.create_usd_payable_account()
|
||||||
|
self.create_item()
|
||||||
|
self.clear_old_entries()
|
||||||
|
|
||||||
|
def tearDown(self):
|
||||||
|
frappe.db.rollback()
|
||||||
|
|
||||||
|
def create_sales_order(self, qty=1, rate=100, currency="INR", do_not_submit=False):
|
||||||
|
"""
|
||||||
|
Helper method
|
||||||
|
"""
|
||||||
|
so = make_sales_order(
|
||||||
|
company=self.company,
|
||||||
|
customer=self.customer,
|
||||||
|
currency=currency,
|
||||||
|
item=self.item,
|
||||||
|
qty=qty,
|
||||||
|
rate=rate,
|
||||||
|
transaction_date=today(),
|
||||||
|
do_not_submit=do_not_submit,
|
||||||
|
)
|
||||||
|
return so
|
||||||
|
|
||||||
|
def test_so_advance_paid_and_currency_with_payment(self):
|
||||||
|
self.create_customer("_Test USD Customer", "USD")
|
||||||
|
|
||||||
|
so = self.create_sales_order(currency="USD", do_not_submit=True)
|
||||||
|
so.conversion_rate = 80
|
||||||
|
so.submit()
|
||||||
|
|
||||||
|
pe_exchange_rate = 85
|
||||||
|
pe = get_payment_entry(so.doctype, so.name, bank_account=self.cash)
|
||||||
|
pe.reference_no = "1"
|
||||||
|
pe.reference_date = nowdate()
|
||||||
|
pe.paid_from = self.debtors_usd
|
||||||
|
pe.paid_from_account_currency = "USD"
|
||||||
|
pe.source_exchange_rate = pe_exchange_rate
|
||||||
|
pe.paid_amount = so.grand_total
|
||||||
|
pe.received_amount = pe_exchange_rate * pe.paid_amount
|
||||||
|
pe.references[0].outstanding_amount = 100
|
||||||
|
pe.references[0].total_amount = 100
|
||||||
|
pe.references[0].allocated_amount = 100
|
||||||
|
pe.save().submit()
|
||||||
|
|
||||||
|
so.reload()
|
||||||
|
self.assertEqual(so.advance_paid, 100)
|
||||||
|
self.assertEqual(so.party_account_currency, "USD")
|
||||||
|
|
||||||
|
# cancel advance payment
|
||||||
|
pe.reload()
|
||||||
|
pe.cancel()
|
||||||
|
|
||||||
|
so.reload()
|
||||||
|
self.assertEqual(so.advance_paid, 0)
|
||||||
|
self.assertEqual(so.party_account_currency, "USD")
|
||||||
|
|
||||||
|
def test_so_advance_paid_and_currency_with_journal(self):
|
||||||
|
self.create_customer("_Test USD Customer", "USD")
|
||||||
|
|
||||||
|
so = self.create_sales_order(currency="USD", do_not_submit=True)
|
||||||
|
so.conversion_rate = 80
|
||||||
|
so.submit()
|
||||||
|
|
||||||
|
je_exchange_rate = 85
|
||||||
|
je = frappe.get_doc(
|
||||||
|
{
|
||||||
|
"doctype": "Journal Entry",
|
||||||
|
"company": self.company,
|
||||||
|
"voucher_type": "Journal Entry",
|
||||||
|
"posting_date": so.transaction_date,
|
||||||
|
"multi_currency": True,
|
||||||
|
"accounts": [
|
||||||
|
{
|
||||||
|
"account": self.debtors_usd,
|
||||||
|
"party_type": "Customer",
|
||||||
|
"party": so.customer,
|
||||||
|
"credit": 8500,
|
||||||
|
"credit_in_account_currency": 100,
|
||||||
|
"is_advance": "Yes",
|
||||||
|
"reference_type": so.doctype,
|
||||||
|
"reference_name": so.name,
|
||||||
|
"exchange_rate": je_exchange_rate,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"account": self.cash,
|
||||||
|
"debit": 8500,
|
||||||
|
"debit_in_account_currency": 8500,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
}
|
||||||
|
)
|
||||||
|
je.save().submit()
|
||||||
|
so.reload()
|
||||||
|
self.assertEqual(so.advance_paid, 100)
|
||||||
|
self.assertEqual(so.party_account_currency, "USD")
|
||||||
|
|
||||||
|
# cancel advance payment
|
||||||
|
je.reload()
|
||||||
|
je.cancel()
|
||||||
|
|
||||||
|
so.reload()
|
||||||
|
self.assertEqual(so.advance_paid, 0)
|
||||||
|
self.assertEqual(so.party_account_currency, "USD")
|
||||||
|
|||||||
@@ -1327,115 +1327,6 @@ class TestSalesOrder(AccountsTestMixin, FrappeTestCase):
|
|||||||
so.reload()
|
so.reload()
|
||||||
self.assertEqual(so.advance_paid, 0)
|
self.assertEqual(so.advance_paid, 0)
|
||||||
|
|
||||||
def create_foreign_currency_usd_account(self):
|
|
||||||
account_name = "Debtors USD"
|
|
||||||
if not frappe.db.get_value(
|
|
||||||
"Account", filters={"account_name": account_name, "company": "_Test Company"}
|
|
||||||
):
|
|
||||||
acc = frappe.new_doc("Account")
|
|
||||||
acc.account_name = account_name
|
|
||||||
acc.parent_account = "Accounts Receivable - _TC"
|
|
||||||
acc.company = "_Test Company"
|
|
||||||
acc.account_currency = "USD"
|
|
||||||
acc.account_type = "Receivable"
|
|
||||||
acc.insert()
|
|
||||||
else:
|
|
||||||
name = frappe.db.get_value(
|
|
||||||
"Account",
|
|
||||||
filters={"account_name": account_name, "company": "_Test Company"},
|
|
||||||
fieldname="name",
|
|
||||||
pluck=True,
|
|
||||||
)
|
|
||||||
acc = frappe.get_doc("Account", name)
|
|
||||||
self.debtors_usd = acc.name
|
|
||||||
|
|
||||||
def test_advance_paid_and_currency_with_payment(self):
|
|
||||||
from erpnext.accounts.doctype.payment_entry.test_payment_entry import get_payment_entry
|
|
||||||
|
|
||||||
self.create_customer("_Test USD Customer", "USD")
|
|
||||||
self.create_foreign_currency_usd_account()
|
|
||||||
|
|
||||||
so = make_sales_order(customer=self.customer, currency="USD", qty=1, rate=100, do_not_submit=True)
|
|
||||||
so.conversion_rate = 80
|
|
||||||
so.submit()
|
|
||||||
|
|
||||||
pe_exchange_rate = 85
|
|
||||||
pe = get_payment_entry("Sales Order", so.name, bank_account="_Test Bank - _TC")
|
|
||||||
pe.reference_no = "1"
|
|
||||||
pe.reference_date = nowdate()
|
|
||||||
pe.paid_from = self.debtors_usd
|
|
||||||
pe.paid_from_account_currency = "USD"
|
|
||||||
pe.source_exchange_rate = pe_exchange_rate
|
|
||||||
pe.paid_amount = so.grand_total
|
|
||||||
pe.received_amount = pe_exchange_rate * pe.paid_amount
|
|
||||||
pe.references[0].outstanding_amount = 100
|
|
||||||
pe.references[0].total_amount = 100
|
|
||||||
pe.references[0].allocated_amount = 100
|
|
||||||
pe.save().submit()
|
|
||||||
|
|
||||||
so.reload()
|
|
||||||
self.assertEqual(so.advance_paid, 100)
|
|
||||||
self.assertEqual(so.party_account_currency, "USD")
|
|
||||||
|
|
||||||
# cancel advance payment
|
|
||||||
pe.reload()
|
|
||||||
pe.cancel()
|
|
||||||
|
|
||||||
so.reload()
|
|
||||||
self.assertEqual(so.advance_paid, 0)
|
|
||||||
self.assertEqual(so.party_account_currency, "USD")
|
|
||||||
|
|
||||||
def test_advance_paid_and_currency_with_journal(self):
|
|
||||||
from erpnext.accounts.doctype.payment_entry.test_payment_entry import get_payment_entry
|
|
||||||
|
|
||||||
self.create_customer("_Test USD Customer", "USD")
|
|
||||||
self.create_foreign_currency_usd_account()
|
|
||||||
|
|
||||||
so = make_sales_order(customer=self.customer, currency="USD", qty=1, rate=100, do_not_submit=True)
|
|
||||||
so.conversion_rate = 80
|
|
||||||
so.submit()
|
|
||||||
|
|
||||||
je_exchange_rate = 85
|
|
||||||
je = frappe.get_doc(
|
|
||||||
{
|
|
||||||
"doctype": "Journal Entry",
|
|
||||||
"company": "_Test Company",
|
|
||||||
"voucher_type": "Journal Entry",
|
|
||||||
"posting_date": so.transaction_date,
|
|
||||||
"multi_currency": True,
|
|
||||||
"accounts": [
|
|
||||||
{
|
|
||||||
"account": self.debtors_usd,
|
|
||||||
"party_type": "Customer",
|
|
||||||
"party": so.customer,
|
|
||||||
"credit": 8500,
|
|
||||||
"credit_in_account_currency": 100,
|
|
||||||
"is_advance": "Yes",
|
|
||||||
"reference_type": so.doctype,
|
|
||||||
"reference_name": so.name,
|
|
||||||
"exchange_rate": je_exchange_rate,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"account": "_Test Bank - _TC",
|
|
||||||
"debit": 8500,
|
|
||||||
"debit_in_account_currency": 8500,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
}
|
|
||||||
)
|
|
||||||
je.save().submit()
|
|
||||||
so.reload()
|
|
||||||
self.assertEqual(so.advance_paid, 100)
|
|
||||||
self.assertEqual(so.party_account_currency, "USD")
|
|
||||||
|
|
||||||
# cancel advance payment
|
|
||||||
je.reload()
|
|
||||||
je.cancel()
|
|
||||||
|
|
||||||
so.reload()
|
|
||||||
self.assertEqual(so.advance_paid, 0)
|
|
||||||
self.assertEqual(so.party_account_currency, "USD")
|
|
||||||
|
|
||||||
def test_cancel_sales_order_after_cancel_payment_entry(self):
|
def test_cancel_sales_order_after_cancel_payment_entry(self):
|
||||||
from erpnext.accounts.doctype.payment_entry.test_payment_entry import get_payment_entry
|
from erpnext.accounts.doctype.payment_entry.test_payment_entry import get_payment_entry
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user