test: tests for loan status Disbursed, Settled and on payment Entry for attached invoices

This commit is contained in:
Anurag Mishra 2019-03-14 16:02:49 +05:30
parent 6deffbd6e8
commit 1c7baaeba5
2 changed files with 147 additions and 16 deletions

View File

@ -103,7 +103,6 @@ class InvoiceDiscounting(AccountsController):
"reference_type": "Invoice Discounting",
"reference_name": self.name
})
for d in self.invoices:
je.append("accounts", {
"account": self.accounts_receivable_discounted,
@ -123,7 +122,7 @@ class InvoiceDiscounting(AccountsController):
"party": d.customer
})
return je.as_dict()
return je
def close_loan(self):
je = frappe.new_doc("Journal Entry")
@ -163,7 +162,7 @@ class InvoiceDiscounting(AccountsController):
"party": d.customer
})
return je.as_dict()
return je
@frappe.whitelist()
def get_invoices(filters):

View File

@ -4,12 +4,12 @@
from __future__ import unicode_literals
import frappe
from frappe.utils import nowdate, add_days
from frappe.utils import nowdate, add_days, flt
import unittest
from erpnext.accounts.doctype.sales_invoice.test_sales_invoice import create_sales_invoice
from erpnext.stock.doctype.purchase_receipt.test_purchase_receipt import get_gl_entries
from erpnext.accounts.doctype.account.test_account import create_account
from erpnext.accounts.doctype.journal_entry.journal_entry import get_payment_entry_against_invoice
class TestInvoiceDiscounting(unittest.TestCase):
def setUp(self):
self.ar_credit = create_account(account_name="_Test Accounts Receivable Credit", parent_account = "Accounts Receivable - _TC")
@ -19,7 +19,6 @@ class TestInvoiceDiscounting(unittest.TestCase):
self.bank_account = create_account(account_name="_Test Bank 2", parent_account = "Bank Accounts - _TC" )
self.bank_charges_account = create_account(account_name="_Test Bank Charges Account", parent_account = "Expenses - _TC")
def test_total_amount(self):
inv1 = create_sales_invoice(rate=200)
inv2 = create_sales_invoice(rate=500)
@ -70,8 +69,9 @@ class TestInvoiceDiscounting(unittest.TestCase):
self.assertEqual(inv_disc.status, "Sanctioned")
self.assertEqual(inv_disc.loan_end_date, add_days(inv_disc.loan_start_date, inv_disc.loan_period))
'''def test_on_disbursed(self):
inv = create_sales_invoice(rate=300)
def test_on_disbursed(self):
inv = create_sales_invoice(rate=500)
inv_disc = create_invoice_discounting([inv.name],
accounts_receivable_credit=self.ar_credit,
accounts_receivable_discounted=self.ar_discounted,
@ -79,14 +79,149 @@ class TestInvoiceDiscounting(unittest.TestCase):
short_term_loan=self.short_term_loan,
bank_charges_account=self.bank_charges_account,
bank_account=self.bank_account,
set_status='Disbursed'
)
gle = get_gl_entries("Invoice Discounting", inv_disc.name)
from pprint import pprint
pprint(gle)'''
je = inv_disc.create_disbursement_entry()
self.assertEqual(je.accounts[0].account, self.bank_account)
self.assertEqual(je.accounts[0].debit_in_account_currency, flt(inv_disc.total_amount) - flt(inv_disc.bank_charges))
self.assertEqual(je.accounts[1].account, self.bank_charges_account)
self.assertEqual(je.accounts[1].debit_in_account_currency, flt(inv_disc.bank_charges))
self.assertEqual(je.accounts[2].account, self.short_term_loan)
self.assertEqual(je.accounts[2].credit_in_account_currency, flt(inv_disc.total_amount))
self.assertEqual(je.accounts[3].account, self.ar_discounted)
self.assertEqual(je.accounts[3].debit_in_account_currency, flt(inv.outstanding_amount))
self.assertEqual(je.accounts[4].account, self.ar_credit)
self.assertEqual(je.accounts[4].credit_in_account_currency, flt(inv.outstanding_amount))
je.posting_date = nowdate()
je.submit()
inv_disc.reload()
self.assertEqual(inv_disc.status, "Disbursed")
def test_on_close_after_loan_period(self):
inv = create_sales_invoice(rate=600)
inv_disc = create_invoice_discounting([inv.name],
accounts_receivable_credit=self.ar_credit,
accounts_receivable_discounted=self.ar_discounted,
accounts_receivable_unpaid=self.ar_unpaid,
short_term_loan=self.short_term_loan,
bank_charges_account=self.bank_charges_account,
bank_account=self.bank_account,
start=nowdate(),
period=60
)
inv_disc.create_disbursement_entry()
je = inv_disc.close_loan()
self.assertEqual(je.accounts[0].account, self.short_term_loan)
self.assertEqual(je.accounts[0].debit_in_account_currency, flt(inv_disc.total_amount))
self.assertEqual(je.accounts[1].account, self.bank_account)
self.assertEqual(je.accounts[1].credit_in_account_currency, flt(inv_disc.total_amount))
self.assertEqual(je.accounts[2].account, self.ar_discounted)
self.assertEqual(je.accounts[2].credit_in_account_currency, flt(inv.outstanding_amount))
self.assertEqual(je.accounts[3].account, self.ar_unpaid)
self.assertEqual(je.accounts[3].debit_in_account_currency, flt(inv.outstanding_amount))
je.posting_date = nowdate()
je.submit()
inv_disc.reload()
self.assertEqual(inv_disc.status, "Settled")
def test_on_close_before_loan_period(self):
inv = create_sales_invoice(rate=700)
inv_disc = create_invoice_discounting([inv.name],
accounts_receivable_credit=self.ar_credit,
accounts_receivable_discounted=self.ar_discounted,
accounts_receivable_unpaid=self.ar_unpaid,
short_term_loan=self.short_term_loan,
bank_charges_account=self.bank_charges_account,
bank_account=self.bank_account,
start=add_days(nowdate(), -80),
period=60
)
inv_disc.create_disbursement_entry()
je = inv_disc.close_loan()
je.posting_date = nowdate()
je.submit()
self.assertEqual(je.accounts[0].account, self.short_term_loan)
self.assertEqual(je.accounts[0].debit_in_account_currency, flt(inv_disc.total_amount))
self.assertEqual(je.accounts[1].account, self.bank_account)
self.assertEqual(je.accounts[1].credit_in_account_currency, flt(inv_disc.total_amount))
inv_disc.reload()
self.assertEqual(inv_disc.status, "Settled")
def test_make_payment_before_loan_period(self):
#it has problem
inv = create_sales_invoice(rate=700)
inv_disc = create_invoice_discounting([inv.name],
accounts_receivable_credit=self.ar_credit,
accounts_receivable_discounted=self.ar_discounted,
accounts_receivable_unpaid=self.ar_unpaid,
short_term_loan=self.short_term_loan,
bank_charges_account=self.bank_charges_account,
bank_account=self.bank_account
)
je = inv_disc.create_disbursement_entry()
inv_disc.reload()
je.posting_date = nowdate()
je.submit()
je_on_payment = get_payment_entry_against_invoice("Sales Invoice", inv.name)
self.assertEqual(je_on_payment.accounts[0].account, self.ar_discounted)
self.assertEqual(je_on_payment.accounts[0].credit_in_account_currency, flt(inv.outstanding_amount))
#self.assertEqual(je_on_payment.accounts[0].account, self.bank_account)
self.assertEqual(je_on_payment.accounts[1].debit_in_account_currency, flt(inv.outstanding_amount))
def test_make_payment_before_after_period(self):
#it has problem
inv = create_sales_invoice(rate=700)
inv_disc = create_invoice_discounting([inv.name],
accounts_receivable_credit=self.ar_credit,
accounts_receivable_discounted=self.ar_discounted,
accounts_receivable_unpaid=self.ar_unpaid,
short_term_loan=self.short_term_loan,
bank_charges_account=self.bank_charges_account,
bank_account=self.bank_account,
loan_start_date=add_days(nowdate(), -10),
period=5
)
je = inv_disc.create_disbursement_entry()
inv_disc.reload()
je.posting_date = nowdate()
je.submit()
je = inv_disc.close_loan()
inv_disc.reload()
je.posting_date = nowdate()
je.submit()
je_on_payment = get_payment_entry_against_invoice("Sales Invoice", inv.name)
self.assertEqual(je_on_payment.accounts[0].account, self.ar_unpaid)
self.assertEqual(je_on_payment.accounts[0].credit_in_account_currency, flt(inv.outstanding_amount))
#self.assertEqual(je_on_payment.accounts[0].account, self.bank_account)
self.assertEqual(je_on_payment.accounts[1].debit_in_account_currency, flt(inv.outstanding_amount))
def test_on_invoice_payment
def create_invoice_discounting(invoices, **args):
args = frappe._dict(args)
@ -113,7 +248,4 @@ def create_invoice_discounting(invoices, **args):
if not args.do_not_submit:
inv_disc.submit()
if args.set_status:
inv_disc.status = args.set_status
return inv_disc