Merge pull request #17299 from nabinhait/inv-disc-fixes
fix: Close loan considering latest invoice outstanding balance
This commit is contained in:
commit
06f992f850
@ -145,23 +145,25 @@ class InvoiceDiscounting(AccountsController):
|
||||
|
||||
if getdate(self.loan_end_date) > getdate(nowdate()):
|
||||
for d in self.invoices:
|
||||
je.append("accounts", {
|
||||
"account": self.accounts_receivable_discounted,
|
||||
"credit_in_account_currency": flt(d.outstanding_amount),
|
||||
"reference_type": "Invoice Discounting",
|
||||
"reference_name": self.name,
|
||||
"party_type": "Customer",
|
||||
"party": d.customer
|
||||
})
|
||||
outstanding_amount = frappe.db.get_value("Sales Invoice", d.sales_invoice, "outstanding_amount")
|
||||
if flt(outstanding_amount) > 0:
|
||||
je.append("accounts", {
|
||||
"account": self.accounts_receivable_discounted,
|
||||
"credit_in_account_currency": flt(outstanding_amount),
|
||||
"reference_type": "Invoice Discounting",
|
||||
"reference_name": self.name,
|
||||
"party_type": "Customer",
|
||||
"party": d.customer
|
||||
})
|
||||
|
||||
je.append("accounts", {
|
||||
"account": self.accounts_receivable_unpaid,
|
||||
"debit_in_account_currency": flt(d.outstanding_amount),
|
||||
"reference_type": "Invoice Discounting",
|
||||
"reference_name": self.name,
|
||||
"party_type": "Customer",
|
||||
"party": d.customer
|
||||
})
|
||||
je.append("accounts", {
|
||||
"account": self.accounts_receivable_unpaid,
|
||||
"debit_in_account_currency": flt(outstanding_amount),
|
||||
"reference_type": "Invoice Discounting",
|
||||
"reference_name": self.name,
|
||||
"party_type": "Customer",
|
||||
"party": d.customer
|
||||
})
|
||||
|
||||
return je
|
||||
|
||||
|
@ -146,6 +146,38 @@ class TestInvoiceDiscounting(unittest.TestCase):
|
||||
|
||||
self.assertEqual(inv_disc.status, "Settled")
|
||||
|
||||
def test_on_close_after_loan_period_after_inv_payment(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
|
||||
)
|
||||
|
||||
je1 = inv_disc.create_disbursement_entry()
|
||||
je1.posting_date = nowdate()
|
||||
je1.submit()
|
||||
|
||||
je_on_payment = frappe.get_doc(get_payment_entry_against_invoice("Sales Invoice", inv.name))
|
||||
je_on_payment.posting_date = nowdate()
|
||||
je_on_payment.cheque_no = "126981"
|
||||
je_on_payment.cheque_date = nowdate()
|
||||
je_on_payment.save()
|
||||
je_on_payment.submit()
|
||||
|
||||
je2 = inv_disc.close_loan()
|
||||
|
||||
self.assertEqual(je2.accounts[0].account, self.short_term_loan)
|
||||
self.assertEqual(je2.accounts[0].debit_in_account_currency, flt(inv_disc.total_amount))
|
||||
|
||||
self.assertEqual(je2.accounts[1].account, self.bank_account)
|
||||
self.assertEqual(je2.accounts[1].credit_in_account_currency, flt(inv_disc.total_amount))
|
||||
|
||||
def test_on_close_before_loan_period(self):
|
||||
inv = create_sales_invoice(rate=700)
|
||||
inv_disc = create_invoice_discounting([inv.name],
|
||||
@ -173,10 +205,6 @@ class TestInvoiceDiscounting(unittest.TestCase):
|
||||
self.assertEqual(je2.accounts[1].account, self.bank_account)
|
||||
self.assertEqual(je2.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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user