From 08d8ca0184f19dab13ca77d930baf0dc2db5087e Mon Sep 17 00:00:00 2001 From: tunde Date: Wed, 30 Aug 2017 13:41:07 +0100 Subject: [PATCH] enhance reference_due_date behaviour: - creates new api - get_invoice_due_dates - when reference_name is changed, populate reference_due_date --- .../doctype/journal_entry/journal_entry.js | 21 +++++++++++++++++++ .../doctype/journal_entry/journal_entry.py | 11 ++++++++++ 2 files changed, 32 insertions(+) diff --git a/erpnext/accounts/doctype/journal_entry/journal_entry.js b/erpnext/accounts/doctype/journal_entry/journal_entry.js index 9047a4edcc..934dbeb03a 100644 --- a/erpnext/accounts/doctype/journal_entry/journal_entry.js +++ b/erpnext/accounts/doctype/journal_entry/journal_entry.js @@ -187,6 +187,24 @@ erpnext.accounts.JournalEntry = frappe.ui.form.Controller.extend({ reference_name: function(doc, cdt, cdn) { var d = frappe.get_doc(cdt, cdn); + + const get_invoice_due_dates = (invoice_name) => { + frappe.call({ + method: "erpnext.accounts.doctype.journal_entry.journal_entry.get_invoice_due_dates", + args: {name: invoice_name}, + callback: function(r){ + const wrapper = cur_frm.fields_dict["accounts"].wrapper; + const input = $(wrapper).find("select[data-fieldname=reference_due_date]"); + + input.children('option').remove(); + + $.each(r.message, function(key, value) { + input.append(new Option(value.due_date, "", false, false)); + }); + } + }); + } + if(d.reference_name) { if (d.reference_type==="Purchase Invoice" && !flt(d.debit)) { this.get_outstanding('Purchase Invoice', d.reference_name, doc.company, d); @@ -197,6 +215,9 @@ erpnext.accounts.JournalEntry = frappe.ui.form.Controller.extend({ if (d.reference_type==="Journal Entry" && !flt(d.credit) && !flt(d.debit)) { this.get_outstanding('Journal Entry', d.reference_name, doc.company, d); } + if( in_list(d.reference_type), ["Sales Invoice", "Purchase Invoice"]) { + get_invoice_due_dates(d.reference_name); + } } }, diff --git a/erpnext/accounts/doctype/journal_entry/journal_entry.py b/erpnext/accounts/doctype/journal_entry/journal_entry.py index 375d85d1b7..68f4cc53be 100644 --- a/erpnext/accounts/doctype/journal_entry/journal_entry.py +++ b/erpnext/accounts/doctype/journal_entry/journal_entry.py @@ -889,3 +889,14 @@ def get_average_exchange_rate(account): exchange_rate = bank_balance_in_company_currency / bank_balance_in_account_currency return exchange_rate + + +@frappe.whitelist() +def get_invoice_due_dates(name): + result = frappe.get_list( + doctype='GL Entry', group_by='name, due_date', + filters={'voucher_no': name, "ifnull(due_date, '')": ('!=', '')}, + fields=['due_date'], distinct=True + ) + + return result