mirror of
https://github.com/frappe/erpnext.git
synced 2026-06-03 04:09:11 +00:00
Merge pull request #17277 from nabinhait/invoice-discounting-fixes
Invoice discounting fixes
This commit is contained in:
@@ -190,9 +190,11 @@ def get_invoices(filters):
|
|||||||
customer,
|
customer,
|
||||||
posting_date,
|
posting_date,
|
||||||
outstanding_amount
|
outstanding_amount
|
||||||
from `tabSales Invoice`
|
from `tabSales Invoice` si
|
||||||
where
|
where
|
||||||
docstatus = 1
|
docstatus = 1
|
||||||
and outstanding_amount > 0
|
and outstanding_amount > 0
|
||||||
%s
|
%s
|
||||||
|
and not exists(select di.name from `tabDiscounted Invoice` di
|
||||||
|
where di.docstatus=1 and di.sales_invoice=si.name)
|
||||||
""" % where_condition, filters, as_dict=1)
|
""" % where_condition, filters, as_dict=1)
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
from __future__ import unicode_literals
|
||||||
|
from frappe import _
|
||||||
|
|
||||||
|
def get_data():
|
||||||
|
return {
|
||||||
|
'fieldname': 'reference_name',
|
||||||
|
'internal_links': {
|
||||||
|
'Sales Invoice': ['invoices', 'sales_invoice']
|
||||||
|
},
|
||||||
|
'transactions': [
|
||||||
|
{
|
||||||
|
'label': _('Reference'),
|
||||||
|
'items': ['Sales Invoice']
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'label': _('Payment'),
|
||||||
|
'items': ['Payment Entry', 'Journal Entry']
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -122,23 +122,26 @@ class TestInvoiceDiscounting(unittest.TestCase):
|
|||||||
period=60
|
period=60
|
||||||
)
|
)
|
||||||
|
|
||||||
inv_disc.create_disbursement_entry()
|
je1 = inv_disc.create_disbursement_entry()
|
||||||
je = inv_disc.close_loan()
|
je1.posting_date = nowdate()
|
||||||
|
je1.submit()
|
||||||
|
|
||||||
self.assertEqual(je.accounts[0].account, self.short_term_loan)
|
je2 = inv_disc.close_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(je2.accounts[0].account, self.short_term_loan)
|
||||||
self.assertEqual(je.accounts[1].credit_in_account_currency, flt(inv_disc.total_amount))
|
self.assertEqual(je2.accounts[0].debit_in_account_currency, flt(inv_disc.total_amount))
|
||||||
|
|
||||||
self.assertEqual(je.accounts[2].account, self.ar_discounted)
|
self.assertEqual(je2.accounts[1].account, self.bank_account)
|
||||||
self.assertEqual(je.accounts[2].credit_in_account_currency, flt(inv.outstanding_amount))
|
self.assertEqual(je2.accounts[1].credit_in_account_currency, flt(inv_disc.total_amount))
|
||||||
|
|
||||||
self.assertEqual(je.accounts[3].account, self.ar_unpaid)
|
self.assertEqual(je2.accounts[2].account, self.ar_discounted)
|
||||||
self.assertEqual(je.accounts[3].debit_in_account_currency, flt(inv.outstanding_amount))
|
self.assertEqual(je2.accounts[2].credit_in_account_currency, flt(inv.outstanding_amount))
|
||||||
|
|
||||||
je.posting_date = nowdate()
|
self.assertEqual(je2.accounts[3].account, self.ar_unpaid)
|
||||||
je.submit()
|
self.assertEqual(je2.accounts[3].debit_in_account_currency, flt(inv.outstanding_amount))
|
||||||
|
|
||||||
|
je2.posting_date = nowdate()
|
||||||
|
je2.submit()
|
||||||
inv_disc.reload()
|
inv_disc.reload()
|
||||||
|
|
||||||
self.assertEqual(inv_disc.status, "Settled")
|
self.assertEqual(inv_disc.status, "Settled")
|
||||||
@@ -154,19 +157,21 @@ class TestInvoiceDiscounting(unittest.TestCase):
|
|||||||
bank_account=self.bank_account,
|
bank_account=self.bank_account,
|
||||||
start=add_days(nowdate(), -80),
|
start=add_days(nowdate(), -80),
|
||||||
period=60
|
period=60
|
||||||
)
|
)
|
||||||
|
|
||||||
inv_disc.create_disbursement_entry()
|
je1 = inv_disc.create_disbursement_entry()
|
||||||
je = inv_disc.close_loan()
|
je1.posting_date = nowdate()
|
||||||
|
je1.submit()
|
||||||
|
|
||||||
je.posting_date = nowdate()
|
je2 = inv_disc.close_loan()
|
||||||
je.submit()
|
je2.posting_date = nowdate()
|
||||||
|
je2.submit()
|
||||||
|
|
||||||
self.assertEqual(je.accounts[0].account, self.short_term_loan)
|
self.assertEqual(je2.accounts[0].account, self.short_term_loan)
|
||||||
self.assertEqual(je.accounts[0].debit_in_account_currency, flt(inv_disc.total_amount))
|
self.assertEqual(je2.accounts[0].debit_in_account_currency, flt(inv_disc.total_amount))
|
||||||
|
|
||||||
self.assertEqual(je.accounts[1].account, self.bank_account)
|
self.assertEqual(je2.accounts[1].account, self.bank_account)
|
||||||
self.assertEqual(je.accounts[1].credit_in_account_currency, flt(inv_disc.total_amount))
|
self.assertEqual(je2.accounts[1].credit_in_account_currency, flt(inv_disc.total_amount))
|
||||||
|
|
||||||
inv_disc.reload()
|
inv_disc.reload()
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
import frappe, erpnext, json
|
import frappe, erpnext, json
|
||||||
from frappe.utils import cstr, flt, fmt_money, formatdate, getdate, nowdate, cint
|
from frappe.utils import cstr, flt, fmt_money, formatdate, getdate, nowdate, cint, get_link_to_form
|
||||||
from frappe import msgprint, _, scrub
|
from frappe import msgprint, _, scrub
|
||||||
from erpnext.controllers.accounts_controller import AccountsController
|
from erpnext.controllers.accounts_controller import AccountsController
|
||||||
from erpnext.accounts.utils import get_balance_on, get_account_currency
|
from erpnext.accounts.utils import get_balance_on, get_account_currency
|
||||||
@@ -53,6 +53,20 @@ class JournalEntry(AccountsController):
|
|||||||
self.update_inter_company_jv()
|
self.update_inter_company_jv()
|
||||||
self.update_invoice_discounting()
|
self.update_invoice_discounting()
|
||||||
|
|
||||||
|
def on_cancel(self):
|
||||||
|
from erpnext.accounts.utils import unlink_ref_doc_from_payment_entries
|
||||||
|
from erpnext.hr.doctype.salary_slip.salary_slip import unlink_ref_doc_from_salary_slip
|
||||||
|
unlink_ref_doc_from_payment_entries(self)
|
||||||
|
unlink_ref_doc_from_salary_slip(self.name)
|
||||||
|
self.make_gl_entries(1)
|
||||||
|
self.update_advance_paid()
|
||||||
|
self.update_expense_claim()
|
||||||
|
self.update_loan()
|
||||||
|
self.unlink_advance_entry_reference()
|
||||||
|
self.unlink_asset_reference()
|
||||||
|
self.unlink_inter_company_jv()
|
||||||
|
self.unlink_asset_adjustment_entry()
|
||||||
|
self.update_invoice_discounting()
|
||||||
|
|
||||||
def get_title(self):
|
def get_title(self):
|
||||||
return self.pay_to_recd_from or self.accounts[0].account
|
return self.pay_to_recd_from or self.accounts[0].account
|
||||||
@@ -83,31 +97,32 @@ class JournalEntry(AccountsController):
|
|||||||
"inter_company_journal_entry_reference", self.name)
|
"inter_company_journal_entry_reference", self.name)
|
||||||
|
|
||||||
def update_invoice_discounting(self):
|
def update_invoice_discounting(self):
|
||||||
invoice_discounting_list = [d.reference_name for d in self.accounts if d.reference_type=="Invoice Discounting"]
|
def _validate_invoice_discounting_status(inv_disc, id_status, expected_status, row_id):
|
||||||
|
id_link = get_link_to_form("Invoice Discounting", inv_disc)
|
||||||
|
if id_status != expected_status:
|
||||||
|
frappe.throw(_("Row #{0}: Status must be {1} for Invoice Discounting {2}").format(d.idx, expected_status, id_link))
|
||||||
|
|
||||||
|
invoice_discounting_list = list(set([d.reference_name for d in self.accounts if d.reference_type=="Invoice Discounting"]))
|
||||||
for inv_disc in invoice_discounting_list:
|
for inv_disc in invoice_discounting_list:
|
||||||
short_term_loan_account = frappe.db.get_value("Invoice Discounting", inv_disc, "short_term_loan")
|
short_term_loan_account, id_status = frappe.db.get_value("Invoice Discounting", inv_disc, ["short_term_loan", "status"])
|
||||||
for d in self.accounts:
|
for d in self.accounts:
|
||||||
if d.account == short_term_loan_account and d.reference_name == inv_disc:
|
if d.account == short_term_loan_account and d.reference_name == inv_disc:
|
||||||
if d.credit > 0:
|
if self.docstatus == 1:
|
||||||
status = "Disbursed"
|
if d.credit > 0:
|
||||||
elif d.debit > 0:
|
_validate_invoice_discounting_status(inv_disc, id_status, "Sanctioned", d.idx)
|
||||||
status = "Settled"
|
status = "Disbursed"
|
||||||
|
elif d.debit > 0:
|
||||||
|
_validate_invoice_discounting_status(inv_disc, id_status, "Disbursed", d.idx)
|
||||||
|
status = "Settled"
|
||||||
|
else:
|
||||||
|
if d.credit > 0:
|
||||||
|
_validate_invoice_discounting_status(inv_disc, id_status, "Disbursed", d.idx)
|
||||||
|
status = "Sanctioned"
|
||||||
|
elif d.debit > 0:
|
||||||
|
_validate_invoice_discounting_status(inv_disc, id_status, "Settled", d.idx)
|
||||||
|
status = "Disbursed"
|
||||||
frappe.db.set_value("Invoice Discounting", inv_disc, "status", status)
|
frappe.db.set_value("Invoice Discounting", inv_disc, "status", status)
|
||||||
|
|
||||||
def on_cancel(self):
|
|
||||||
from erpnext.accounts.utils import unlink_ref_doc_from_payment_entries
|
|
||||||
from erpnext.hr.doctype.salary_slip.salary_slip import unlink_ref_doc_from_salary_slip
|
|
||||||
unlink_ref_doc_from_payment_entries(self)
|
|
||||||
unlink_ref_doc_from_salary_slip(self.name)
|
|
||||||
self.make_gl_entries(1)
|
|
||||||
self.update_advance_paid()
|
|
||||||
self.update_expense_claim()
|
|
||||||
self.update_loan()
|
|
||||||
self.unlink_advance_entry_reference()
|
|
||||||
self.unlink_asset_reference()
|
|
||||||
self.unlink_inter_company_jv()
|
|
||||||
self.unlink_asset_adjustment_entry()
|
|
||||||
|
|
||||||
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 == "Yes" and d.reference_type in ("Sales Invoice", "Purchase Invoice"):
|
if d.is_advance == "Yes" and d.reference_type in ("Sales Invoice", "Purchase Invoice"):
|
||||||
|
|||||||
@@ -232,6 +232,11 @@ def get_data():
|
|||||||
"label": _("Bank Account"),
|
"label": _("Bank Account"),
|
||||||
"name": "Bank Account",
|
"name": "Bank Account",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"type": "doctype",
|
||||||
|
"label": _("Invoice Discounting"),
|
||||||
|
"name": "Invoice Discounting",
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"type": "doctype",
|
"type": "doctype",
|
||||||
"label": _("Bank Statement Transaction Entry List"),
|
"label": _("Bank Statement Transaction Entry List"),
|
||||||
|
|||||||
Reference in New Issue
Block a user