refactor(test): make use of test fixtures in Payment Order
(cherry picked from commit 322cdbaccf0b8697000aae4e56efa659a34fa8e5)
This commit is contained in:
parent
949f4c3790
commit
4235e08668
@ -4,9 +4,13 @@
|
|||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
import frappe
|
import frappe
|
||||||
|
from frappe.tests.utils import FrappeTestCase
|
||||||
from frappe.utils import getdate
|
from frappe.utils import getdate
|
||||||
|
|
||||||
from erpnext.accounts.doctype.bank_transaction.test_bank_transaction import create_bank_account
|
from erpnext.accounts.doctype.bank_transaction.test_bank_transaction import (
|
||||||
|
create_bank_account,
|
||||||
|
create_gl_account,
|
||||||
|
)
|
||||||
from erpnext.accounts.doctype.payment_entry.payment_entry import (
|
from erpnext.accounts.doctype.payment_entry.payment_entry import (
|
||||||
get_payment_entry,
|
get_payment_entry,
|
||||||
make_payment_order,
|
make_payment_order,
|
||||||
@ -14,28 +18,32 @@ from erpnext.accounts.doctype.payment_entry.payment_entry import (
|
|||||||
from erpnext.accounts.doctype.purchase_invoice.test_purchase_invoice import make_purchase_invoice
|
from erpnext.accounts.doctype.purchase_invoice.test_purchase_invoice import make_purchase_invoice
|
||||||
|
|
||||||
|
|
||||||
class TestPaymentOrder(unittest.TestCase):
|
class TestPaymentOrder(FrappeTestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
create_bank_account()
|
# generate and use a uniq hash identifier for 'Bank Account' and it's linked GL 'Account' to avoid validation error
|
||||||
|
uniq_identifier = frappe.generate_hash(length=10)
|
||||||
|
self.gl_account = create_gl_account("_Test Bank " + uniq_identifier)
|
||||||
|
self.bank_account = create_bank_account(
|
||||||
|
gl_account=self.gl_account, bank_account_name="Checking Account " + uniq_identifier
|
||||||
|
)
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
for bt in frappe.get_all("Payment Order"):
|
frappe.db.rollback()
|
||||||
doc = frappe.get_doc("Payment Order", bt.name)
|
|
||||||
doc.cancel()
|
|
||||||
doc.delete()
|
|
||||||
|
|
||||||
def test_payment_order_creation_against_payment_entry(self):
|
def test_payment_order_creation_against_payment_entry(self):
|
||||||
purchase_invoice = make_purchase_invoice()
|
purchase_invoice = make_purchase_invoice()
|
||||||
payment_entry = get_payment_entry(
|
payment_entry = get_payment_entry(
|
||||||
"Purchase Invoice", purchase_invoice.name, bank_account="_Test Bank - _TC"
|
"Purchase Invoice", purchase_invoice.name, bank_account=self.gl_account
|
||||||
)
|
)
|
||||||
payment_entry.reference_no = "_Test_Payment_Order"
|
payment_entry.reference_no = "_Test_Payment_Order"
|
||||||
payment_entry.reference_date = getdate()
|
payment_entry.reference_date = getdate()
|
||||||
payment_entry.party_bank_account = "Checking Account - Citi Bank"
|
payment_entry.party_bank_account = self.bank_account
|
||||||
payment_entry.insert()
|
payment_entry.insert()
|
||||||
payment_entry.submit()
|
payment_entry.submit()
|
||||||
|
|
||||||
doc = create_payment_order_against_payment_entry(payment_entry, "Payment Entry")
|
doc = create_payment_order_against_payment_entry(
|
||||||
|
payment_entry, "Payment Entry", self.bank_account
|
||||||
|
)
|
||||||
reference_doc = doc.get("references")[0]
|
reference_doc = doc.get("references")[0]
|
||||||
self.assertEqual(reference_doc.reference_name, payment_entry.name)
|
self.assertEqual(reference_doc.reference_name, payment_entry.name)
|
||||||
self.assertEqual(reference_doc.reference_doctype, "Payment Entry")
|
self.assertEqual(reference_doc.reference_doctype, "Payment Entry")
|
||||||
@ -43,13 +51,13 @@ class TestPaymentOrder(unittest.TestCase):
|
|||||||
self.assertEqual(reference_doc.amount, 250)
|
self.assertEqual(reference_doc.amount, 250)
|
||||||
|
|
||||||
|
|
||||||
def create_payment_order_against_payment_entry(ref_doc, order_type):
|
def create_payment_order_against_payment_entry(ref_doc, order_type, bank_account):
|
||||||
payment_order = frappe.get_doc(
|
payment_order = frappe.get_doc(
|
||||||
dict(
|
dict(
|
||||||
doctype="Payment Order",
|
doctype="Payment Order",
|
||||||
company="_Test Company",
|
company="_Test Company",
|
||||||
payment_order_type=order_type,
|
payment_order_type=order_type,
|
||||||
company_bank_account="Checking Account - Citi Bank",
|
company_bank_account=bank_account,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
doc = make_payment_order(ref_doc.name, payment_order)
|
doc = make_payment_order(ref_doc.name, payment_order)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user