refactor(test): more modularization

This commit is contained in:
ruthra kumar 2023-09-08 21:43:23 +05:30
parent 1d93d66c30
commit 5c09fdf941

View File

@ -20,20 +20,8 @@ class TestUnreconcilePayments(AccountsTestMixin, FrappeTestCase):
def tearDown(self):
frappe.db.rollback()
def test_01_unreconcile_invoice(self):
si1 = create_sales_invoice(
item=self.item,
company=self.company,
customer=self.customer,
debit_to=self.debit_to,
posting_date=today(),
parent_cost_center=self.cost_center,
cost_center=self.cost_center,
rate=100,
price_list_rate=100,
)
si2 = create_sales_invoice(
def create_sales_invoice(self):
si = create_sales_invoice(
item=self.item,
company=self.company,
customer=self.customer,
@ -44,7 +32,9 @@ class TestUnreconcilePayments(AccountsTestMixin, FrappeTestCase):
rate=100,
price_list_rate=100,
)
return si
def create_payment_entry(self):
pe = create_payment_entry(
company=self.company,
payment_type="Receive",
@ -55,7 +45,13 @@ class TestUnreconcilePayments(AccountsTestMixin, FrappeTestCase):
paid_amount=200,
save=True,
)
return pe
def test_01_unreconcile_invoice(self):
si1 = self.create_sales_invoice()
si2 = self.create_sales_invoice()
pe = self.create_payment_entry()
pe.append(
"references",
{"reference_doctype": si1.doctype, "reference_name": si1.name, "allocated_amount": 100},
@ -68,10 +64,10 @@ class TestUnreconcilePayments(AccountsTestMixin, FrappeTestCase):
pe.save().submit()
# Assert outstanding
si1.reload()
si2.reload()
[doc.reload() for doc in [si1, si2, pe]]
self.assertEqual(si1.outstanding_amount, 0)
self.assertEqual(si2.outstanding_amount, 0)
self.assertEqual(pe.unallocated_amount, 0)
unreconcile = frappe.get_doc(
{
@ -92,54 +88,22 @@ class TestUnreconcilePayments(AccountsTestMixin, FrappeTestCase):
unreconcile.save().submit()
# Assert outstanding
si1.reload()
si2.reload()
[doc.reload() for doc in [si1, si2, pe]]
self.assertEqual(si1.outstanding_amount, 100)
self.assertEqual(si2.outstanding_amount, 0)
pe.reload()
self.assertEqual(len(pe.references), 1)
self.assertEqual(pe.unallocated_amount, 100)
def test_02_unreconcile_one_payment_from_multi_payments(self):
"""
Scenario: 2 payments, both split against 2 invoices
Scenario: 2 payments, both split against 2 different invoices
Unreconcile only one payment from one invoice
"""
si1 = create_sales_invoice(
item=self.item,
company=self.company,
customer=self.customer,
debit_to=self.debit_to,
posting_date=today(),
parent_cost_center=self.cost_center,
cost_center=self.cost_center,
rate=100,
price_list_rate=100,
)
si2 = create_sales_invoice(
item=self.item,
company=self.company,
customer=self.customer,
debit_to=self.debit_to,
posting_date=today(),
parent_cost_center=self.cost_center,
cost_center=self.cost_center,
rate=100,
price_list_rate=100,
)
pe1 = create_payment_entry(
company=self.company,
payment_type="Receive",
party_type="Customer",
party=self.customer,
paid_from=self.debit_to,
paid_to=self.cash,
paid_amount=100,
save=True,
)
si1 = self.create_sales_invoice()
si2 = self.create_sales_invoice()
pe1 = self.create_payment_entry()
pe1.paid_amount = 100
# Allocate payment against both invoices
pe1.append(
"references",
{"reference_doctype": si1.doctype, "reference_name": si1.name, "allocated_amount": 50},
@ -148,19 +112,11 @@ class TestUnreconcilePayments(AccountsTestMixin, FrappeTestCase):
"references",
{"reference_doctype": si2.doctype, "reference_name": si2.name, "allocated_amount": 50},
)
# Allocation payment against both invoices
pe1.save().submit()
pe2 = create_payment_entry(
company=self.company,
payment_type="Receive",
party_type="Customer",
party=self.customer,
paid_from=self.debit_to,
paid_to=self.cash,
paid_amount=100,
save=True,
)
pe2 = self.create_payment_entry()
pe2.paid_amount = 100
# Allocate payment against both invoices
pe2.append(
"references",
{"reference_doctype": si1.doctype, "reference_name": si1.name, "allocated_amount": 50},
@ -169,14 +125,14 @@ class TestUnreconcilePayments(AccountsTestMixin, FrappeTestCase):
"references",
{"reference_doctype": si2.doctype, "reference_name": si2.name, "allocated_amount": 50},
)
# Allocation payment against both invoices
pe2.save().submit()
# Assert outstanding
si1.reload()
si2.reload()
self.assertEqual(si1.outstanding_amount, 0)
self.assertEqual(si2.outstanding_amount, 0)
# Assert outstanding and unallocated
[doc.reload() for doc in [si1, si2, pe1, pe2]]
self.assertEqual(si1.outstanding_amount, 0.0)
self.assertEqual(si2.outstanding_amount, 0.0)
self.assertEqual(pe1.unallocated_amount, 0.0)
self.assertEqual(pe2.unallocated_amount, 0.0)
unreconcile = frappe.get_doc(
{
@ -196,14 +152,10 @@ class TestUnreconcilePayments(AccountsTestMixin, FrappeTestCase):
unreconcile.remove(x)
unreconcile.save().submit()
# Assert outstanding
si1.reload()
si2.reload()
# Assert outstanding and unallocated
[doc.reload() for doc in [si1, si2, pe1, pe2]]
self.assertEqual(si1.outstanding_amount, 50)
self.assertEqual(si2.outstanding_amount, 0)
pe1.reload()
pe2.reload()
self.assertEqual(len(pe1.references), 2)
self.assertEqual(len(pe2.references), 1)
self.assertEqual(pe1.unallocated_amount, 0)