Skip to content

Commit

Permalink
test: Impact on SO of advance PE submit and unlinking/replacement by SI
Browse files Browse the repository at this point in the history
  • Loading branch information
marination committed Sep 13, 2023
1 parent 426350e commit 8a4954d
Showing 1 changed file with 28 additions and 4 deletions.
32 changes: 28 additions & 4 deletions erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py
Original file line number Diff line number Diff line change
Expand Up @@ -1801,6 +1801,10 @@ def test_outstanding_amount_after_advance_jv_cancellation(self):
)

def test_outstanding_amount_after_advance_payment_entry_cancellation(self):
"""Test impact of advance PE submission/cancellation on SI and SO."""
from erpnext.selling.doctype.sales_order.test_sales_order import make_sales_order

sales_order = make_sales_order(item_code="138-CMS Shoe", qty=1, price_list_rate=500)
pe = frappe.get_doc(
{
"doctype": "Payment Entry",
Expand All @@ -1820,17 +1824,33 @@ def test_outstanding_amount_after_advance_payment_entry_cancellation(self):
"paid_to": "_Test Cash - _TC",
}
)
pe.append(
"references",
{
"reference_doctype": "Sales Order",
"reference_name": sales_order.name,
"total_amount": sales_order.grand_total,
"outstanding_amount": sales_order.grand_total,
"allocated_amount": 300,
},
)
pe.insert()
pe.submit()

sales_order.reload()
self.assertEqual(sales_order.advance_paid, 300)

si = frappe.copy_doc(test_records[0])
si.items[0].sales_order = sales_order.name
si.items[0].so_detail = sales_order.get("items")[0].name
si.is_pos = 0
si.append(
"advances",
{
"doctype": "Sales Invoice Advance",
"reference_type": "Payment Entry",
"reference_name": pe.name,
"reference_row": pe.references[0].name,
"advance_amount": 300,
"allocated_amount": 300,
"remarks": pe.remarks,
Expand All @@ -1839,19 +1859,23 @@ def test_outstanding_amount_after_advance_payment_entry_cancellation(self):
si.insert()
si.submit()

si.load_from_db()
si.reload()
pe.reload()
sales_order.reload()

# Check if SO is unlinked/replaced by SI in PE & if SO advance paid is 0
self.assertEqual(pe.references[0].reference_name, si.name)
self.assertEqual(sales_order.advance_paid, 0.0)

# check outstanding after advance allocation
self.assertEqual(
flt(si.outstanding_amount),
flt(si.rounded_total - si.total_advance, si.precision("outstanding_amount")),
)

# added to avoid Document has been modified exception
pe = frappe.get_doc("Payment Entry", pe.name)
pe.cancel()
si.reload()

si.load_from_db()
# check outstanding after advance cancellation
self.assertEqual(
flt(si.outstanding_amount),
Expand Down

0 comments on commit 8a4954d

Please sign in to comment.