diff --git a/erpnext/accounts/doctype/invoice_discounting/invoice_discounting.py b/erpnext/accounts/doctype/invoice_discounting/invoice_discounting.py index 590929bade8..c8756af7d75 100644 --- a/erpnext/accounts/doctype/invoice_discounting/invoice_discounting.py +++ b/erpnext/accounts/doctype/invoice_discounting/invoice_discounting.py @@ -199,4 +199,21 @@ def get_invoices(filters): %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) \ No newline at end of file + """ % where_condition, filters, as_dict=1) + +def get_party_account_based_on_invoice_discounting(sales_invoice): + party_account = None + invoice_discounting = frappe.db.sql(""" + select par.accounts_receivable_discounted, par.accounts_receivable_unpaid, par.status + from `tabInvoice Discounting` par, `tabDiscounted Invoice` ch + where par.name=ch.parent + and par.docstatus=1 + and ch.sales_invoice = %s + """, (sales_invoice), as_dict=1) + if invoice_discounting: + if invoice_discounting[0].status == "Disbursed": + party_account = invoice_discounting[0].accounts_receivable_discounted + elif invoice_discounting[0].status == "Settled": + party_account = invoice_discounting[0].accounts_receivable_unpaid + + return party_account diff --git a/erpnext/accounts/doctype/journal_entry/journal_entry.py b/erpnext/accounts/doctype/journal_entry/journal_entry.py index 08d707385cb..63f180dccea 100644 --- a/erpnext/accounts/doctype/journal_entry/journal_entry.py +++ b/erpnext/accounts/doctype/journal_entry/journal_entry.py @@ -10,6 +10,7 @@ from erpnext.accounts.utils import get_balance_on, get_account_currency from erpnext.accounts.party import get_party_account from erpnext.hr.doctype.expense_claim.expense_claim import update_reimbursed_amount from erpnext.hr.doctype.loan.loan import update_disbursement_status, update_total_amount_paid +from erpnext.accounts.doctype.invoice_discounting.invoice_discounting import get_party_account_based_on_invoice_discounting from six import string_types, iteritems @@ -747,23 +748,6 @@ def get_payment_entry_against_invoice(dt, dn, amount=None, debit_in_account_cur "journal_entry": journal_entry }) -def get_party_account_based_on_invoice_discounting(sales_invoice): - party_account = None - invoice_discounting = frappe.db.sql(""" - select par.accounts_receivable_discounted, par.accounts_receivable_unpaid, par.status - from `tabInvoice Discounting` par, `tabDiscounted Invoice` ch - where par.name=ch.parent - and par.docstatus=1 - and ch.sales_invoice = %s - """, (sales_invoice), as_dict=1) - if invoice_discounting: - if invoice_discounting[0].status == "Disbursed": - party_account = invoice_discounting[0].accounts_receivable_discounted - elif invoice_discounting[0].status == "Settled": - party_account = invoice_discounting[0].accounts_receivable_unpaid - - return party_account - def get_payment_entry(ref_doc, args): cost_center = ref_doc.get("cost_center") or frappe.get_cached_value('Company', ref_doc.company, "cost_center") exchange_rate = 1 diff --git a/erpnext/accounts/doctype/payment_entry/payment_entry.py b/erpnext/accounts/doctype/payment_entry/payment_entry.py index eb672e023be..ec35f030d35 100644 --- a/erpnext/accounts/doctype/payment_entry/payment_entry.py +++ b/erpnext/accounts/doctype/payment_entry/payment_entry.py @@ -14,6 +14,7 @@ from erpnext.accounts.general_ledger import make_gl_entries from erpnext.hr.doctype.expense_claim.expense_claim import update_reimbursed_amount from erpnext.accounts.doctype.bank_account.bank_account import get_party_bank_account, get_bank_account_details from erpnext.controllers.accounts_controller import AccountsController, get_supplier_block_status +from erpnext.accounts.doctype.invoice_discounting.invoice_discounting import get_party_account_based_on_invoice_discounting from six import string_types, iteritems @@ -237,7 +238,7 @@ class PaymentEntry(AccountsController): if d.reference_doctype in ("Sales Invoice", "Purchase Invoice", "Expense Claim", "Fees"): if self.party_type == "Customer": - ref_party_account = ref_doc.debit_to + ref_party_account = get_party_account_based_on_invoice_discounting(d.reference_name) or ref_doc.debit_to elif self.party_type == "Student": ref_party_account = ref_doc.receivable_account elif self.party_type=="Supplier": @@ -826,7 +827,7 @@ def get_payment_entry(dt, dn, party_amount=None, bank_account=None, bank_amount= # party account if dt == "Sales Invoice": - party_account = doc.debit_to + party_account = get_party_account_based_on_invoice_discounting(dn) or ref_doc.debit_to elif dt == "Purchase Invoice": party_account = doc.credit_to elif dt == "Fees":