[fix] on advance payment entry cancellation delink invoice and pyament entry references
This commit is contained in:
parent
7fc05d6432
commit
1d210968de
@ -60,7 +60,14 @@ class PaymentEntry(AccountsController):
|
|||||||
self.setup_party_account_field()
|
self.setup_party_account_field()
|
||||||
self.make_gl_entries(cancel=1)
|
self.make_gl_entries(cancel=1)
|
||||||
self.update_advance_paid()
|
self.update_advance_paid()
|
||||||
|
self.delink_advance_entry_references()
|
||||||
|
|
||||||
|
def delink_advance_entry_references(self):
|
||||||
|
for reference in self.references:
|
||||||
|
if reference.reference_doctype in ("Sales Invoice", "Purchase Invoice"):
|
||||||
|
doc = frappe.get_doc(reference.reference_doctype, reference.reference_name)
|
||||||
|
doc.delink_advance_entries(self.name)
|
||||||
|
|
||||||
def set_missing_values(self):
|
def set_missing_values(self):
|
||||||
if self.payment_type == "Internal Transfer":
|
if self.payment_type == "Internal Transfer":
|
||||||
for field in ("party", "party_balance", "total_allocated_amount",
|
for field in ("party", "party_balance", "total_allocated_amount",
|
||||||
|
@ -460,7 +460,7 @@ class TestPurchaseInvoice(unittest.TestCase):
|
|||||||
pi.load_from_db()
|
pi.load_from_db()
|
||||||
|
|
||||||
#check outstanding after advance allocation
|
#check outstanding after advance allocation
|
||||||
self.assertEqual(flt(pi.outstanding_amount), flt(pi.grand_total - pi.total_advance, pi.precision("outstanding_amount")))
|
self.assertEqual(flt(pi.outstanding_amount), flt(pi.grand_total - pi.total_advance))
|
||||||
|
|
||||||
#added to avoid Document has been modified exception
|
#added to avoid Document has been modified exception
|
||||||
jv = frappe.get_doc("Journal Entry", jv.name)
|
jv = frappe.get_doc("Journal Entry", jv.name)
|
||||||
@ -468,7 +468,54 @@ class TestPurchaseInvoice(unittest.TestCase):
|
|||||||
|
|
||||||
pi.load_from_db()
|
pi.load_from_db()
|
||||||
#check outstanding after advance cancellation
|
#check outstanding after advance cancellation
|
||||||
self.assertEqual(flt(pi.outstanding_amount), flt(pi.grand_total + pi.total_advance, pi.precision("outstanding_amount")))
|
self.assertEqual(flt(pi.outstanding_amount), flt(pi.grand_total + pi.total_advance))
|
||||||
|
|
||||||
|
def test_outstanding_amount_after_advance_payment_entry_cancelation(self):
|
||||||
|
pe = frappe.get_doc({
|
||||||
|
"doctype": "Payment Entry",
|
||||||
|
"payment_type": "Pay",
|
||||||
|
"party_type": "Supplier",
|
||||||
|
"party": "_Test Supplier",
|
||||||
|
"company": "_Test Company",
|
||||||
|
"paid_from_account_currency": "INR",
|
||||||
|
"paid_to_account_currency": "INR",
|
||||||
|
"source_exchange_rate": 1,
|
||||||
|
"target_exchange_rate": 1,
|
||||||
|
"reference_no": "1",
|
||||||
|
"reference_date": nowdate(),
|
||||||
|
"received_amount": 300,
|
||||||
|
"paid_amount": 300,
|
||||||
|
"paid_from": "_Test Cash - _TC",
|
||||||
|
"paid_to": "_Test Payable - _TC"
|
||||||
|
})
|
||||||
|
pe.insert()
|
||||||
|
pe.submit()
|
||||||
|
|
||||||
|
pi = frappe.copy_doc(test_records[0])
|
||||||
|
pi.is_pos = 0
|
||||||
|
pi.append("advances", {
|
||||||
|
"doctype": "Purchase Invoice Advance",
|
||||||
|
"reference_type": "Payment Entry",
|
||||||
|
"reference_name": pe.name,
|
||||||
|
"advance_amount": 300,
|
||||||
|
"allocated_amount": 300,
|
||||||
|
"remarks": pe.remarks
|
||||||
|
})
|
||||||
|
pi.insert()
|
||||||
|
pi.submit()
|
||||||
|
|
||||||
|
pi.load_from_db()
|
||||||
|
|
||||||
|
#check outstanding after advance allocation
|
||||||
|
self.assertEqual(flt(pi.outstanding_amount), flt(pi.grand_total - pi.total_advance))
|
||||||
|
|
||||||
|
#added to avoid Document has been modified exception
|
||||||
|
pe = frappe.get_doc("Payment Entry", pe.name)
|
||||||
|
pe.cancel()
|
||||||
|
|
||||||
|
pi.load_from_db()
|
||||||
|
#check outstanding after advance cancellation
|
||||||
|
self.assertEqual(flt(pi.outstanding_amount), flt(pi.grand_total + pi.total_advance))
|
||||||
|
|
||||||
def unlink_payment_on_cancel_of_invoice(enable=1):
|
def unlink_payment_on_cancel_of_invoice(enable=1):
|
||||||
accounts_settings = frappe.get_doc("Accounts Settings")
|
accounts_settings = frappe.get_doc("Accounts Settings")
|
||||||
|
@ -1013,6 +1013,53 @@ class TestSalesInvoice(unittest.TestCase):
|
|||||||
si.load_from_db()
|
si.load_from_db()
|
||||||
#check outstanding after advance cancellation
|
#check outstanding after advance cancellation
|
||||||
self.assertEqual(flt(si.outstanding_amount), flt(si.grand_total + si.total_advance, si.precision("outstanding_amount")))
|
self.assertEqual(flt(si.outstanding_amount), flt(si.grand_total + si.total_advance, si.precision("outstanding_amount")))
|
||||||
|
|
||||||
|
def test_outstanding_amount_after_advance_payment_entry_cancelation(self):
|
||||||
|
pe = frappe.get_doc({
|
||||||
|
"doctype": "Payment Entry",
|
||||||
|
"payment_type": "Receive",
|
||||||
|
"party_type": "Customer",
|
||||||
|
"party": "_Test Customer",
|
||||||
|
"company": "_Test Company",
|
||||||
|
"paid_from_account_currency": "INR",
|
||||||
|
"paid_to_account_currency": "INR",
|
||||||
|
"source_exchange_rate": 1,
|
||||||
|
"target_exchange_rate": 1,
|
||||||
|
"reference_no": "1",
|
||||||
|
"reference_date": nowdate(),
|
||||||
|
"received_amount": 300,
|
||||||
|
"paid_amount": 300,
|
||||||
|
"paid_from": "_Test Receivable - _TC",
|
||||||
|
"paid_to": "_Test Cash - _TC"
|
||||||
|
})
|
||||||
|
pe.insert()
|
||||||
|
pe.submit()
|
||||||
|
|
||||||
|
si = frappe.copy_doc(test_records[0])
|
||||||
|
si.is_pos = 0
|
||||||
|
si.append("advances", {
|
||||||
|
"doctype": "Sales Invoice Advance",
|
||||||
|
"reference_type": "Payment Entry",
|
||||||
|
"reference_name": pe.name,
|
||||||
|
"advance_amount": 300,
|
||||||
|
"allocated_amount": 300,
|
||||||
|
"remarks": pe.remarks
|
||||||
|
})
|
||||||
|
si.insert()
|
||||||
|
si.submit()
|
||||||
|
|
||||||
|
si.load_from_db()
|
||||||
|
|
||||||
|
#check outstanding after advance allocation
|
||||||
|
self.assertEqual(flt(si.outstanding_amount), flt(si.grand_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.load_from_db()
|
||||||
|
#check outstanding after advance cancellation
|
||||||
|
self.assertEqual(flt(si.outstanding_amount), flt(si.grand_total + si.total_advance, si.precision("outstanding_amount")))
|
||||||
|
|
||||||
def create_sales_invoice(**args):
|
def create_sales_invoice(**args):
|
||||||
si = frappe.new_doc("Sales Invoice")
|
si = frappe.new_doc("Sales Invoice")
|
||||||
|
@ -126,11 +126,11 @@ class TransactionBase(StatusUpdater):
|
|||||||
|
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
def delink_advance_entries(self, jv):
|
def delink_advance_entries(self, linked_doc_name):
|
||||||
total_allocated_amount = 0
|
total_allocated_amount = 0
|
||||||
for adv in self.advances:
|
for adv in self.advances:
|
||||||
consider_for_total_advance = True
|
consider_for_total_advance = True
|
||||||
if adv.reference_name == jv:
|
if adv.reference_name == linked_doc_name:
|
||||||
frappe.db.sql("""delete from `tab{0} Advance`
|
frappe.db.sql("""delete from `tab{0} Advance`
|
||||||
where name = %s""".format(self.doctype), adv.name)
|
where name = %s""".format(self.doctype), adv.name)
|
||||||
consider_for_total_advance = False
|
consider_for_total_advance = False
|
||||||
|
Loading…
x
Reference in New Issue
Block a user