[test-case] test cases for delinking advance payments
This commit is contained in:
parent
866c295989
commit
8adbfa8a09
@ -69,7 +69,7 @@ class JournalEntry(AccountsController):
|
|||||||
self.update_advance_paid()
|
self.update_advance_paid()
|
||||||
self.update_expense_claim()
|
self.update_expense_claim()
|
||||||
self.unlink_advance_entry_reference()
|
self.unlink_advance_entry_reference()
|
||||||
|
|
||||||
def unlink_advance_entry_reference(self):
|
def unlink_advance_entry_reference(self):
|
||||||
for d in self.get("accounts"):
|
for d in self.get("accounts"):
|
||||||
if d.is_advance and d.reference_type in ("Sales Invoice", "Purchase Invoice"):
|
if d.is_advance and d.reference_type in ("Sales Invoice", "Purchase Invoice"):
|
||||||
|
@ -437,6 +437,38 @@ class TestPurchaseInvoice(unittest.TestCase):
|
|||||||
|
|
||||||
self.assertEquals(frappe.db.get_value("Serial No", pi.get("items")[0].rejected_serial_no,
|
self.assertEquals(frappe.db.get_value("Serial No", pi.get("items")[0].rejected_serial_no,
|
||||||
"warehouse"), pi.get("items")[0].rejected_warehouse)
|
"warehouse"), pi.get("items")[0].rejected_warehouse)
|
||||||
|
|
||||||
|
def test_outstanding_amount_after_advance_jv_cancelation(self):
|
||||||
|
from erpnext.accounts.doctype.journal_entry.test_journal_entry \
|
||||||
|
import test_records as jv_test_records
|
||||||
|
|
||||||
|
jv = frappe.copy_doc(jv_test_records[1])
|
||||||
|
jv.insert()
|
||||||
|
jv.submit()
|
||||||
|
|
||||||
|
pi = frappe.copy_doc(test_records[0])
|
||||||
|
pi.append("advances", {
|
||||||
|
"reference_type": "Journal Entry",
|
||||||
|
"reference_name": jv.name,
|
||||||
|
"reference_row": jv.get("accounts")[0].name,
|
||||||
|
"advance_amount": 400,
|
||||||
|
"allocated_amount": 300,
|
||||||
|
"remarks": jv.remark
|
||||||
|
})
|
||||||
|
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, pi.precision("outstanding_amount")))
|
||||||
|
|
||||||
|
#added to avoid Document has been modified exception
|
||||||
|
jv = frappe.get_doc("Journal Entry", jv.name)
|
||||||
|
jv.cancel()
|
||||||
|
|
||||||
|
pi.load_from_db()
|
||||||
|
#check outstanding after advance cancellation
|
||||||
|
self.assertEqual(flt(pi.outstanding_amount), flt(pi.grand_total + pi.total_advance, pi.precision("outstanding_amount")))
|
||||||
|
|
||||||
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")
|
||||||
|
@ -980,6 +980,39 @@ class TestSalesInvoice(unittest.TestCase):
|
|||||||
pe.submit()
|
pe.submit()
|
||||||
|
|
||||||
self.assertEquals(frappe.db.get_value('Customer', customer.name, 'status'), 'Active')
|
self.assertEquals(frappe.db.get_value('Customer', customer.name, 'status'), 'Active')
|
||||||
|
|
||||||
|
def test_outstanding_amount_after_advance_jv_cancelation(self):
|
||||||
|
from erpnext.accounts.doctype.journal_entry.test_journal_entry \
|
||||||
|
import test_records as jv_test_records
|
||||||
|
|
||||||
|
jv = frappe.copy_doc(jv_test_records[0])
|
||||||
|
jv.insert()
|
||||||
|
jv.submit()
|
||||||
|
|
||||||
|
si = frappe.copy_doc(test_records[0])
|
||||||
|
si.append("advances", {
|
||||||
|
"doctype": "Sales Invoice Advance",
|
||||||
|
"reference_type": "Journal Entry",
|
||||||
|
"reference_name": jv.name,
|
||||||
|
"reference_row": jv.get("accounts")[0].name,
|
||||||
|
"advance_amount": 400,
|
||||||
|
"allocated_amount": 300,
|
||||||
|
"remarks": jv.remark
|
||||||
|
})
|
||||||
|
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
|
||||||
|
jv = frappe.get_doc("Journal Entry", jv.name)
|
||||||
|
jv.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")
|
||||||
|
@ -129,11 +129,16 @@ class TransactionBase(StatusUpdater):
|
|||||||
def delink_advance_entries(self, jv):
|
def delink_advance_entries(self, jv):
|
||||||
total_allocated_amount = 0
|
total_allocated_amount = 0
|
||||||
for adv in self.advances:
|
for adv in self.advances:
|
||||||
|
consider_for_total_advance = True
|
||||||
if adv.reference_name == jv:
|
if adv.reference_name == jv:
|
||||||
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)
|
||||||
total_allocated_amount += flt(adv.allocated_amount, adv.precision("allocated_amount"))
|
consider_for_total_advance = False
|
||||||
self.db_set("total_advance", total_allocated_amount)
|
|
||||||
|
if consider_for_total_advance:
|
||||||
|
total_allocated_amount += flt(adv.allocated_amount, adv.precision("allocated_amount"))
|
||||||
|
|
||||||
|
frappe.db.set_value(self.doctype, self.name, "total_advance", total_allocated_amount, update_modified=False)
|
||||||
|
|
||||||
def delete_events(ref_type, ref_name):
|
def delete_events(ref_type, ref_name):
|
||||||
frappe.delete_doc("Event", frappe.db.sql_list("""select name from `tabEvent`
|
frappe.delete_doc("Event", frappe.db.sql_list("""select name from `tabEvent`
|
||||||
|
Loading…
x
Reference in New Issue
Block a user