enhance reference_due_date behaviour:
- creates new api - get_invoice_due_dates
- when reference_name is changed, populate reference_due_date
diff --git a/erpnext/accounts/doctype/journal_entry/journal_entry.js b/erpnext/accounts/doctype/journal_entry/journal_entry.js
index 9047a4e..934dbeb 100644
--- a/erpnext/accounts/doctype/journal_entry/journal_entry.js
+++ b/erpnext/accounts/doctype/journal_entry/journal_entry.js
@@ -187,6 +187,24 @@
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 @@
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 375d85d..68f4cc5 100644
--- a/erpnext/accounts/doctype/journal_entry/journal_entry.py
+++ b/erpnext/accounts/doctype/journal_entry/journal_entry.py
@@ -889,3 +889,14 @@
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