* don"t summarise due_dates query * reference_due_date to fetch outstanding based on due date * use if else so that no need to do useless checks * clear debit and credit fields before fetching outstanding * grid keeps forgetting drop down so add to options * clear debit and credit fields before fetching outstanding properly
This commit is contained in:
parent
d377018695
commit
1d459c4327
@ -221,6 +221,7 @@ erpnext.accounts.JournalEntry = frappe.ui.form.Controller.extend({
|
|||||||
input.empty();
|
input.empty();
|
||||||
input.add_options(options);
|
input.add_options(options);
|
||||||
frappe.model.set_value(cdt, cdn, "reference_due_date", options[0]);
|
frappe.model.set_value(cdt, cdn, "reference_due_date", options[0]);
|
||||||
|
me.frm.cur_grid.get_field("reference_due_date").df.options = options.join('\n');
|
||||||
me.due_date_options_cache[d.reference_name] = options;
|
me.due_date_options_cache[d.reference_name] = options;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -230,20 +231,42 @@ erpnext.accounts.JournalEntry = frappe.ui.form.Controller.extend({
|
|||||||
if(d.reference_name) {
|
if(d.reference_name) {
|
||||||
if (d.reference_type==="Purchase Invoice" && !flt(d.debit)) {
|
if (d.reference_type==="Purchase Invoice" && !flt(d.debit)) {
|
||||||
this.get_outstanding('Purchase Invoice', d.reference_name, doc.company, d);
|
this.get_outstanding('Purchase Invoice', d.reference_name, doc.company, d);
|
||||||
}
|
} else if (d.reference_type==="Sales Invoice" && !flt(d.credit)) {
|
||||||
if (d.reference_type==="Sales Invoice" && !flt(d.credit)) {
|
|
||||||
this.get_outstanding('Sales Invoice', d.reference_name, doc.company, d);
|
this.get_outstanding('Sales Invoice', d.reference_name, doc.company, d);
|
||||||
}
|
} else if (d.reference_type==="Journal Entry" && !flt(d.credit) && !flt(d.debit)) {
|
||||||
if (d.reference_type==="Journal Entry" && !flt(d.credit) && !flt(d.debit)) {
|
|
||||||
this.get_outstanding('Journal Entry', d.reference_name, doc.company, d);
|
this.get_outstanding('Journal Entry', d.reference_name, doc.company, d);
|
||||||
}
|
}
|
||||||
|
|
||||||
if( in_list(["Sales Invoice", "Purchase Invoice"]), d.reference_type) {
|
if( in_list(["Sales Invoice", "Purchase Invoice"]), d.reference_type) {
|
||||||
get_invoice_due_dates(d.reference_name);
|
get_invoice_due_dates(d.reference_name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
get_outstanding: function(doctype, docname, company, child) {
|
reference_due_date: function(doc, cdt, cdn) {
|
||||||
|
const d = frappe.get_doc(cdt, cdn);
|
||||||
|
|
||||||
|
if (d.reference_type && d.reference_name && d.reference_due_date) {
|
||||||
|
if (in_list(["Sales Invoice", "Purchase Invoice"], d.reference_type)) {
|
||||||
|
console.log('cdt:', cdt, cdn);
|
||||||
|
frappe.model.set_value(cdt, cdn, 'debit_in_account_currency', '');
|
||||||
|
frappe.model.set_value(cdt, cdn, 'credit_in_account_currency', '');
|
||||||
|
}
|
||||||
|
if (d.reference_type==="Purchase Invoice") {
|
||||||
|
this.get_outstanding(
|
||||||
|
'Purchase Invoice', d.reference_name, doc.company, d, d.reference_due_date
|
||||||
|
);
|
||||||
|
} else if (d.reference_type==="Sales Invoice") {
|
||||||
|
this.get_outstanding(
|
||||||
|
'Sales Invoice', d.reference_name, doc.company, d, d.reference_due_date
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
frappe.model.set_value(cdt, cdn, 'reference_due_date', d.reference_due_date);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
get_outstanding: function(doctype, docname, company, child, due_date) {
|
||||||
var me = this;
|
var me = this;
|
||||||
var args = {
|
var args = {
|
||||||
"doctype": doctype,
|
"doctype": doctype,
|
||||||
@ -254,6 +277,8 @@ erpnext.accounts.JournalEntry = frappe.ui.form.Controller.extend({
|
|||||||
"company": company
|
"company": company
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (due_date) args.due_date = due_date;
|
||||||
|
|
||||||
return frappe.call({
|
return frappe.call({
|
||||||
method: "erpnext.accounts.doctype.journal_entry.journal_entry.get_outstanding",
|
method: "erpnext.accounts.doctype.journal_entry.journal_entry.get_outstanding",
|
||||||
args: { args: args},
|
args: { args: args},
|
||||||
|
@ -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
|
from frappe.utils import cstr, flt, fmt_money, formatdate, getdate
|
||||||
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
|
||||||
@ -782,8 +782,7 @@ def get_outstanding(args):
|
|||||||
}
|
}
|
||||||
elif args.get("doctype") in ("Sales Invoice", "Purchase Invoice"):
|
elif args.get("doctype") in ("Sales Invoice", "Purchase Invoice"):
|
||||||
party_type = "Customer" if args.get("doctype") == "Sales Invoice" else "Supplier"
|
party_type = "Customer" if args.get("doctype") == "Sales Invoice" else "Supplier"
|
||||||
invoice = frappe.db.get_value(args["doctype"], args["docname"],
|
invoice = frappe.get_doc(args['doctype'], args['docname']).as_dict()
|
||||||
["outstanding_amount", "conversion_rate", scrub(party_type)], as_dict=1)
|
|
||||||
|
|
||||||
exchange_rate = invoice.conversion_rate if (args.get("account_currency") != company_currency) else 1
|
exchange_rate = invoice.conversion_rate if (args.get("account_currency") != company_currency) else 1
|
||||||
|
|
||||||
@ -794,8 +793,17 @@ def get_outstanding(args):
|
|||||||
amount_field = "debit_in_account_currency" \
|
amount_field = "debit_in_account_currency" \
|
||||||
if flt(invoice.outstanding_amount) > 0 else "credit_in_account_currency"
|
if flt(invoice.outstanding_amount) > 0 else "credit_in_account_currency"
|
||||||
|
|
||||||
|
if args.get('due_date'):
|
||||||
|
outstanding = ''
|
||||||
|
for d in invoice.payment_schedule:
|
||||||
|
if d.due_date == getdate(args['due_date']):
|
||||||
|
outstanding = abs(flt(d.payment_amount))
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
outstanding = abs(flt(invoice.outstanding_amount))
|
||||||
|
|
||||||
return {
|
return {
|
||||||
amount_field: abs(flt(invoice.outstanding_amount)),
|
amount_field: outstanding,
|
||||||
"exchange_rate": exchange_rate,
|
"exchange_rate": exchange_rate,
|
||||||
"party_type": party_type,
|
"party_type": party_type,
|
||||||
"party": invoice.get(scrub(party_type))
|
"party": invoice.get(scrub(party_type))
|
||||||
@ -902,7 +910,7 @@ def get_average_exchange_rate(account):
|
|||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
def get_invoice_due_dates(name):
|
def get_invoice_due_dates(name):
|
||||||
result = frappe.get_list(
|
result = frappe.get_list(
|
||||||
doctype='GL Entry', group_by='name, due_date',
|
doctype='GL Entry',
|
||||||
filters={'voucher_no': name, "ifnull(due_date, '')": ('!=', '')},
|
filters={'voucher_no': name, "ifnull(due_date, '')": ('!=', '')},
|
||||||
fields=['due_date'], distinct=True
|
fields=['due_date'], distinct=True
|
||||||
)
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user