refactor(test): more modularization
This commit is contained in:
parent
1d93d66c30
commit
5c09fdf941
@ -20,20 +20,8 @@ class TestUnreconcilePayments(AccountsTestMixin, FrappeTestCase):
|
|||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
frappe.db.rollback()
|
frappe.db.rollback()
|
||||||
|
|
||||||
def test_01_unreconcile_invoice(self):
|
def create_sales_invoice(self):
|
||||||
si1 = create_sales_invoice(
|
si = 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,
|
item=self.item,
|
||||||
company=self.company,
|
company=self.company,
|
||||||
customer=self.customer,
|
customer=self.customer,
|
||||||
@ -44,7 +32,9 @@ class TestUnreconcilePayments(AccountsTestMixin, FrappeTestCase):
|
|||||||
rate=100,
|
rate=100,
|
||||||
price_list_rate=100,
|
price_list_rate=100,
|
||||||
)
|
)
|
||||||
|
return si
|
||||||
|
|
||||||
|
def create_payment_entry(self):
|
||||||
pe = create_payment_entry(
|
pe = create_payment_entry(
|
||||||
company=self.company,
|
company=self.company,
|
||||||
payment_type="Receive",
|
payment_type="Receive",
|
||||||
@ -55,7 +45,13 @@ class TestUnreconcilePayments(AccountsTestMixin, FrappeTestCase):
|
|||||||
paid_amount=200,
|
paid_amount=200,
|
||||||
save=True,
|
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(
|
pe.append(
|
||||||
"references",
|
"references",
|
||||||
{"reference_doctype": si1.doctype, "reference_name": si1.name, "allocated_amount": 100},
|
{"reference_doctype": si1.doctype, "reference_name": si1.name, "allocated_amount": 100},
|
||||||
@ -68,10 +64,10 @@ class TestUnreconcilePayments(AccountsTestMixin, FrappeTestCase):
|
|||||||
pe.save().submit()
|
pe.save().submit()
|
||||||
|
|
||||||
# Assert outstanding
|
# Assert outstanding
|
||||||
si1.reload()
|
[doc.reload() for doc in [si1, si2, pe]]
|
||||||
si2.reload()
|
|
||||||
self.assertEqual(si1.outstanding_amount, 0)
|
self.assertEqual(si1.outstanding_amount, 0)
|
||||||
self.assertEqual(si2.outstanding_amount, 0)
|
self.assertEqual(si2.outstanding_amount, 0)
|
||||||
|
self.assertEqual(pe.unallocated_amount, 0)
|
||||||
|
|
||||||
unreconcile = frappe.get_doc(
|
unreconcile = frappe.get_doc(
|
||||||
{
|
{
|
||||||
@ -92,54 +88,22 @@ class TestUnreconcilePayments(AccountsTestMixin, FrappeTestCase):
|
|||||||
unreconcile.save().submit()
|
unreconcile.save().submit()
|
||||||
|
|
||||||
# Assert outstanding
|
# Assert outstanding
|
||||||
si1.reload()
|
[doc.reload() for doc in [si1, si2, pe]]
|
||||||
si2.reload()
|
|
||||||
self.assertEqual(si1.outstanding_amount, 100)
|
self.assertEqual(si1.outstanding_amount, 100)
|
||||||
self.assertEqual(si2.outstanding_amount, 0)
|
self.assertEqual(si2.outstanding_amount, 0)
|
||||||
|
|
||||||
pe.reload()
|
|
||||||
self.assertEqual(len(pe.references), 1)
|
self.assertEqual(len(pe.references), 1)
|
||||||
self.assertEqual(pe.unallocated_amount, 100)
|
self.assertEqual(pe.unallocated_amount, 100)
|
||||||
|
|
||||||
def test_02_unreconcile_one_payment_from_multi_payments(self):
|
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
|
Unreconcile only one payment from one invoice
|
||||||
"""
|
"""
|
||||||
si1 = create_sales_invoice(
|
si1 = self.create_sales_invoice()
|
||||||
item=self.item,
|
si2 = self.create_sales_invoice()
|
||||||
company=self.company,
|
pe1 = self.create_payment_entry()
|
||||||
customer=self.customer,
|
pe1.paid_amount = 100
|
||||||
debit_to=self.debit_to,
|
# Allocate payment against both invoices
|
||||||
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,
|
|
||||||
)
|
|
||||||
pe1.append(
|
pe1.append(
|
||||||
"references",
|
"references",
|
||||||
{"reference_doctype": si1.doctype, "reference_name": si1.name, "allocated_amount": 50},
|
{"reference_doctype": si1.doctype, "reference_name": si1.name, "allocated_amount": 50},
|
||||||
@ -148,19 +112,11 @@ class TestUnreconcilePayments(AccountsTestMixin, FrappeTestCase):
|
|||||||
"references",
|
"references",
|
||||||
{"reference_doctype": si2.doctype, "reference_name": si2.name, "allocated_amount": 50},
|
{"reference_doctype": si2.doctype, "reference_name": si2.name, "allocated_amount": 50},
|
||||||
)
|
)
|
||||||
# Allocation payment against both invoices
|
|
||||||
pe1.save().submit()
|
pe1.save().submit()
|
||||||
|
|
||||||
pe2 = create_payment_entry(
|
pe2 = self.create_payment_entry()
|
||||||
company=self.company,
|
pe2.paid_amount = 100
|
||||||
payment_type="Receive",
|
# Allocate payment against both invoices
|
||||||
party_type="Customer",
|
|
||||||
party=self.customer,
|
|
||||||
paid_from=self.debit_to,
|
|
||||||
paid_to=self.cash,
|
|
||||||
paid_amount=100,
|
|
||||||
save=True,
|
|
||||||
)
|
|
||||||
pe2.append(
|
pe2.append(
|
||||||
"references",
|
"references",
|
||||||
{"reference_doctype": si1.doctype, "reference_name": si1.name, "allocated_amount": 50},
|
{"reference_doctype": si1.doctype, "reference_name": si1.name, "allocated_amount": 50},
|
||||||
@ -169,14 +125,14 @@ class TestUnreconcilePayments(AccountsTestMixin, FrappeTestCase):
|
|||||||
"references",
|
"references",
|
||||||
{"reference_doctype": si2.doctype, "reference_name": si2.name, "allocated_amount": 50},
|
{"reference_doctype": si2.doctype, "reference_name": si2.name, "allocated_amount": 50},
|
||||||
)
|
)
|
||||||
# Allocation payment against both invoices
|
|
||||||
pe2.save().submit()
|
pe2.save().submit()
|
||||||
|
|
||||||
# Assert outstanding
|
# Assert outstanding and unallocated
|
||||||
si1.reload()
|
[doc.reload() for doc in [si1, si2, pe1, pe2]]
|
||||||
si2.reload()
|
self.assertEqual(si1.outstanding_amount, 0.0)
|
||||||
self.assertEqual(si1.outstanding_amount, 0)
|
self.assertEqual(si2.outstanding_amount, 0.0)
|
||||||
self.assertEqual(si2.outstanding_amount, 0)
|
self.assertEqual(pe1.unallocated_amount, 0.0)
|
||||||
|
self.assertEqual(pe2.unallocated_amount, 0.0)
|
||||||
|
|
||||||
unreconcile = frappe.get_doc(
|
unreconcile = frappe.get_doc(
|
||||||
{
|
{
|
||||||
@ -196,14 +152,10 @@ class TestUnreconcilePayments(AccountsTestMixin, FrappeTestCase):
|
|||||||
unreconcile.remove(x)
|
unreconcile.remove(x)
|
||||||
unreconcile.save().submit()
|
unreconcile.save().submit()
|
||||||
|
|
||||||
# Assert outstanding
|
# Assert outstanding and unallocated
|
||||||
si1.reload()
|
[doc.reload() for doc in [si1, si2, pe1, pe2]]
|
||||||
si2.reload()
|
|
||||||
self.assertEqual(si1.outstanding_amount, 50)
|
self.assertEqual(si1.outstanding_amount, 50)
|
||||||
self.assertEqual(si2.outstanding_amount, 0)
|
self.assertEqual(si2.outstanding_amount, 0)
|
||||||
|
|
||||||
pe1.reload()
|
|
||||||
pe2.reload()
|
|
||||||
self.assertEqual(len(pe1.references), 2)
|
self.assertEqual(len(pe1.references), 2)
|
||||||
self.assertEqual(len(pe2.references), 1)
|
self.assertEqual(len(pe2.references), 1)
|
||||||
self.assertEqual(pe1.unallocated_amount, 0)
|
self.assertEqual(pe1.unallocated_amount, 0)
|
||||||
|
Loading…
Reference in New Issue
Block a user