* fix: fix get outstanding invoices btn and add get outstanding orders btn (#35776)
* fix: fix get outstanding invoices btn and add get outstanding orders btn
* chore: remove unnecessary arg
(cherry picked from commit c1da3ddbbf)
# Conflicts:
# erpnext/accounts/doctype/payment_entry/payment_entry.json
# erpnext/accounts/doctype/payment_entry/payment_entry.py
* chore: resolving conflicts
* chore: resolving conflicts properly
---------
Co-authored-by: Anand Baburajan <anandbaburajan@gmail.com>
This commit is contained in:
@@ -623,7 +623,7 @@ frappe.ui.form.on('Payment Entry', {
|
|||||||
frm.events.set_unallocated_amount(frm);
|
frm.events.set_unallocated_amount(frm);
|
||||||
},
|
},
|
||||||
|
|
||||||
get_outstanding_invoice: function(frm) {
|
get_outstanding_invoices_or_orders: function(frm, get_outstanding_invoices, get_orders_to_be_billed) {
|
||||||
const today = frappe.datetime.get_today();
|
const today = frappe.datetime.get_today();
|
||||||
const fields = [
|
const fields = [
|
||||||
{fieldtype:"Section Break", label: __("Posting Date")},
|
{fieldtype:"Section Break", label: __("Posting Date")},
|
||||||
@@ -653,12 +653,29 @@ frappe.ui.form.on('Payment Entry', {
|
|||||||
{fieldtype:"Check", label: __("Allocate Payment Amount"), fieldname:"allocate_payment_amount", default:1},
|
{fieldtype:"Check", label: __("Allocate Payment Amount"), fieldname:"allocate_payment_amount", default:1},
|
||||||
];
|
];
|
||||||
|
|
||||||
|
let btn_text = "";
|
||||||
|
|
||||||
|
if (get_outstanding_invoices) {
|
||||||
|
btn_text = "Get Outstanding Invoices";
|
||||||
|
}
|
||||||
|
else if (get_orders_to_be_billed) {
|
||||||
|
btn_text = "Get Outstanding Orders";
|
||||||
|
}
|
||||||
|
|
||||||
frappe.prompt(fields, function(filters){
|
frappe.prompt(fields, function(filters){
|
||||||
frappe.flags.allocate_payment_amount = true;
|
frappe.flags.allocate_payment_amount = true;
|
||||||
frm.events.validate_filters_data(frm, filters);
|
frm.events.validate_filters_data(frm, filters);
|
||||||
frm.doc.cost_center = filters.cost_center;
|
frm.doc.cost_center = filters.cost_center;
|
||||||
frm.events.get_outstanding_documents(frm, filters);
|
frm.events.get_outstanding_documents(frm, filters, get_outstanding_invoices, get_orders_to_be_billed);
|
||||||
}, __("Filters"), __("Get Outstanding Documents"));
|
}, __("Filters"), __(btn_text));
|
||||||
|
},
|
||||||
|
|
||||||
|
get_outstanding_invoices: function(frm) {
|
||||||
|
frm.events.get_outstanding_invoices_or_orders(frm, true, false);
|
||||||
|
},
|
||||||
|
|
||||||
|
get_outstanding_orders: function(frm) {
|
||||||
|
frm.events.get_outstanding_invoices_or_orders(frm, false, true);
|
||||||
},
|
},
|
||||||
|
|
||||||
validate_filters_data: function(frm, filters) {
|
validate_filters_data: function(frm, filters) {
|
||||||
@@ -684,7 +701,7 @@ frappe.ui.form.on('Payment Entry', {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
get_outstanding_documents: function(frm, filters) {
|
get_outstanding_documents: function(frm, filters, get_outstanding_invoices, get_orders_to_be_billed) {
|
||||||
frm.clear_table("references");
|
frm.clear_table("references");
|
||||||
|
|
||||||
if(!frm.doc.party) {
|
if(!frm.doc.party) {
|
||||||
@@ -708,6 +725,13 @@ frappe.ui.form.on('Payment Entry', {
|
|||||||
args[key] = filters[key];
|
args[key] = filters[key];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (get_outstanding_invoices) {
|
||||||
|
args["get_outstanding_invoices"] = true;
|
||||||
|
}
|
||||||
|
else if (get_orders_to_be_billed) {
|
||||||
|
args["get_orders_to_be_billed"] = true;
|
||||||
|
}
|
||||||
|
|
||||||
frappe.flags.allocate_payment_amount = filters['allocate_payment_amount'];
|
frappe.flags.allocate_payment_amount = filters['allocate_payment_amount'];
|
||||||
|
|
||||||
return frappe.call({
|
return frappe.call({
|
||||||
|
|||||||
@@ -48,7 +48,8 @@
|
|||||||
"base_received_amount",
|
"base_received_amount",
|
||||||
"base_received_amount_after_tax",
|
"base_received_amount_after_tax",
|
||||||
"section_break_14",
|
"section_break_14",
|
||||||
"get_outstanding_invoice",
|
"get_outstanding_invoices",
|
||||||
|
"get_outstanding_orders",
|
||||||
"references",
|
"references",
|
||||||
"section_break_34",
|
"section_break_34",
|
||||||
"total_allocated_amount",
|
"total_allocated_amount",
|
||||||
@@ -353,12 +354,6 @@
|
|||||||
"fieldtype": "Section Break",
|
"fieldtype": "Section Break",
|
||||||
"label": "Reference"
|
"label": "Reference"
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"depends_on": "eval:doc.docstatus==0",
|
|
||||||
"fieldname": "get_outstanding_invoice",
|
|
||||||
"fieldtype": "Button",
|
|
||||||
"label": "Get Outstanding Invoice"
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"fieldname": "references",
|
"fieldname": "references",
|
||||||
"fieldtype": "Table",
|
"fieldtype": "Table",
|
||||||
@@ -726,12 +721,24 @@
|
|||||||
"fieldname": "section_break_60",
|
"fieldname": "section_break_60",
|
||||||
"fieldtype": "Section Break",
|
"fieldtype": "Section Break",
|
||||||
"hide_border": 1
|
"hide_border": 1
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"depends_on": "eval:doc.docstatus==0",
|
||||||
|
"fieldname": "get_outstanding_invoices",
|
||||||
|
"fieldtype": "Button",
|
||||||
|
"label": "Get Outstanding Invoices"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"depends_on": "eval:doc.docstatus==0",
|
||||||
|
"fieldname": "get_outstanding_orders",
|
||||||
|
"fieldtype": "Button",
|
||||||
|
"label": "Get Outstanding Orders"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"index_web_pages_for_search": 1,
|
"index_web_pages_for_search": 1,
|
||||||
"is_submittable": 1,
|
"is_submittable": 1,
|
||||||
"links": [],
|
"links": [],
|
||||||
"modified": "2022-02-23 20:08:39.559814",
|
"modified": "2023-06-19 11:38:04.387219",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "Accounts",
|
"module": "Accounts",
|
||||||
"name": "Payment Entry",
|
"name": "Payment Entry",
|
||||||
|
|||||||
@@ -174,6 +174,8 @@ class PaymentEntry(AccountsController):
|
|||||||
"payment_type": self.payment_type,
|
"payment_type": self.payment_type,
|
||||||
"party": self.party,
|
"party": self.party,
|
||||||
"party_account": self.paid_from if self.payment_type == "Receive" else self.paid_to,
|
"party_account": self.paid_from if self.payment_type == "Receive" else self.paid_to,
|
||||||
|
"get_outstanding_invoices": True,
|
||||||
|
"get_orders_to_be_billed": True,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -198,7 +200,7 @@ class PaymentEntry(AccountsController):
|
|||||||
):
|
):
|
||||||
frappe.throw(
|
frappe.throw(
|
||||||
_(
|
_(
|
||||||
"{0} {1} has already been partly paid. Please use the 'Get Outstanding Invoice' button to get the latest outstanding amount."
|
"{0} {1} has already been partly paid. Please use the 'Get Outstanding Invoice' or the 'Get Outstanding Orders' button to get the latest outstanding amounts."
|
||||||
).format(d.reference_doctype, d.reference_name)
|
).format(d.reference_doctype, d.reference_name)
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -1365,6 +1367,10 @@ def get_outstanding_reference_documents(args):
|
|||||||
if args.get("company"):
|
if args.get("company"):
|
||||||
condition += " and company = {0}".format(frappe.db.escape(args.get("company")))
|
condition += " and company = {0}".format(frappe.db.escape(args.get("company")))
|
||||||
|
|
||||||
|
outstanding_invoices = []
|
||||||
|
negative_outstanding_invoices = []
|
||||||
|
|
||||||
|
if args.get("get_outstanding_invoices"):
|
||||||
outstanding_invoices = get_outstanding_invoices(
|
outstanding_invoices = get_outstanding_invoices(
|
||||||
args.get("party_type"),
|
args.get("party_type"),
|
||||||
args.get("party"),
|
args.get("party"),
|
||||||
@@ -1388,19 +1394,6 @@ def get_outstanding_reference_documents(args):
|
|||||||
if d.voucher_type in ("Purchase Invoice"):
|
if d.voucher_type in ("Purchase Invoice"):
|
||||||
d["bill_no"] = frappe.db.get_value(d.voucher_type, d.voucher_no, "bill_no")
|
d["bill_no"] = frappe.db.get_value(d.voucher_type, d.voucher_no, "bill_no")
|
||||||
|
|
||||||
# Get all SO / PO which are not fully billed or against which full advance not paid
|
|
||||||
orders_to_be_billed = []
|
|
||||||
if args.get("party_type") != "Student":
|
|
||||||
orders_to_be_billed = get_orders_to_be_billed(
|
|
||||||
args.get("posting_date"),
|
|
||||||
args.get("party_type"),
|
|
||||||
args.get("party"),
|
|
||||||
args.get("company"),
|
|
||||||
party_account_currency,
|
|
||||||
company_currency,
|
|
||||||
filters=args,
|
|
||||||
)
|
|
||||||
|
|
||||||
# Get negative outstanding sales /purchase invoices
|
# Get negative outstanding sales /purchase invoices
|
||||||
negative_outstanding_invoices = []
|
negative_outstanding_invoices = []
|
||||||
if args.get("party_type") not in ["Student", "Employee"] and not args.get("voucher_no"):
|
if args.get("party_type") not in ["Student", "Employee"] and not args.get("voucher_no"):
|
||||||
@@ -1413,13 +1406,35 @@ def get_outstanding_reference_documents(args):
|
|||||||
condition=condition,
|
condition=condition,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Get all SO / PO which are not fully billed or against which full advance not paid
|
||||||
|
orders_to_be_billed = []
|
||||||
|
if args.get("get_orders_to_be_billed") and args.get("party_type") != "Student":
|
||||||
|
orders_to_be_billed = get_orders_to_be_billed(
|
||||||
|
args.get("posting_date"),
|
||||||
|
args.get("party_type"),
|
||||||
|
args.get("party"),
|
||||||
|
args.get("company"),
|
||||||
|
party_account_currency,
|
||||||
|
company_currency,
|
||||||
|
filters=args,
|
||||||
|
)
|
||||||
|
|
||||||
data = negative_outstanding_invoices + outstanding_invoices + orders_to_be_billed
|
data = negative_outstanding_invoices + outstanding_invoices + orders_to_be_billed
|
||||||
|
|
||||||
if not data:
|
if not data:
|
||||||
|
if args.get("get_outstanding_invoices") and args.get("get_orders_to_be_billed"):
|
||||||
|
ref_document_type = "invoices or orders"
|
||||||
|
elif args.get("get_outstanding_invoices"):
|
||||||
|
ref_document_type = "invoices"
|
||||||
|
elif args.get("get_orders_to_be_billed"):
|
||||||
|
ref_document_type = "orders"
|
||||||
|
|
||||||
frappe.msgprint(
|
frappe.msgprint(
|
||||||
_(
|
_(
|
||||||
"No outstanding invoices found for the {0} {1} which qualify the filters you have specified."
|
"No outstanding {0} found for the {1} {2} which qualify the filters you have specified."
|
||||||
).format(_(args.get("party_type")).lower(), frappe.bold(args.get("party")))
|
).format(
|
||||||
|
ref_document_type, _(args.get("party_type")).lower(), frappe.bold(args.get("party"))
|
||||||
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
return data
|
return data
|
||||||
|
|||||||
Reference in New Issue
Block a user