diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.js b/erpnext/accounts/doctype/sales_invoice/sales_invoice.js index 7b69f018d00..b95bb00dd15 100644 --- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.js +++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.js @@ -203,32 +203,57 @@ erpnext.accounts.SalesInvoiceController = class SalesInvoiceController extends e } unreconcile_prompt() { - // get linked payments - let query_args = { - query:"erpnext.accounts.doctype.unreconcile_payments.unreconcile_payments.get_linked_payments_for_doc", - filters: { - doctype: this.frm.doc.doctype, - docname: this.frm.doc.name - } - } - - new frappe.ui.form.MultiSelectDialog({ - doctype: "Payment Ledger Entry", - target: this.cur_frm, - setters: { }, - add_filters_group: 0, - date_field: "posting_date", - columns: ["voucher_type", "voucher_no", "allocated_amount"], - primary_action_label: "Un-Reconcile", - title: "Un-Reconcile Payments", - get_query() { - return query_args; + let child_table_fields = [ + { label: __("Voucher Type"), fieldname: "voucher_type", fieldtype: "Dynamic Link", options: "DocType", in_list_view: 1, read_only: 1}, + { label: __("Voucher No"), fieldname: "voucher_no", fieldtype: "Link", options: "voucher_type", in_list_view: 1, read_only: 1 }, + { label: __("Allocated Amount"), fieldname: "allocated_amount", fieldtype: "Float", in_list_view: 1, read_only: 1 }, + ] + let unreconcile_dialog_fields = [ + { + label: __('Allocations'), + fieldname: 'allocations', + fieldtype: 'Table', + read_only: 1, + fields: child_table_fields, }, - action(selections) { - console.log(selections); + ]; + + // get linked payments + frappe.call({ + "method": "erpnext.accounts.doctype.unreconcile_payments.unreconcile_payments.get_linked_payments_for_doc", + "args": { + "company": this.frm.doc.company, + "doctype": this.frm.doc.doctype, + "docname": this.frm.doc.name + }, + callback: function(r) { + if (r.message) { + // populate child table with allocations + unreconcile_dialog_fields[0].data = r.message; + unreconcile_dialog_fields[0].get_data = function(){ return r.message}; + + let d = new frappe.ui.Dialog({ + title: 'Un-Reconcile Allocations', + fields: unreconcile_dialog_fields, + size: 'large', + cannot_add_rows: 1, + primary_action_label: 'Un-Reconcile', + primary_action(values) { + + let selected_allocations = values.allocations.filter(x=>x.__checked); + if (selected_allocations.length > 0) { + // assuming each row is an individual voucher + // pass this to server side method that created unreconcile doc for row + } else { + frappe.msgprint("No Selection"); + } + } + }); + + d.show(); + } } }); - } make_maintenance_schedule() { diff --git a/erpnext/accounts/doctype/unreconcile_payments/unreconcile_payments.py b/erpnext/accounts/doctype/unreconcile_payments/unreconcile_payments.py index dfd2d29e0f4..cced2b3de49 100644 --- a/erpnext/accounts/doctype/unreconcile_payments/unreconcile_payments.py +++ b/erpnext/accounts/doctype/unreconcile_payments/unreconcile_payments.py @@ -73,20 +73,25 @@ def doc_has_payments(doctype, docname): @frappe.whitelist() -def get_linked_payments_for_doc(doctype, txt, searchfield, start, page_len, filters): - if filters.get("doctype") and filters.get("docname"): - _dt = filters.get("doctype") - _dn = filters.get("docname") +def get_linked_payments_for_doc( + company: str = None, doctype: str = None, docname: str = None +) -> list: + if company and doctype and docname: + _dt = doctype + _dn = docname ple = qb.DocType("Payment Ledger Entry") if _dt in ["Sales Invoice", "Purchase Invoice"]: - criteria = [(ple.delinked == 0), (ple.against_voucher_no == _dn), (ple.amount < 0)] - - if txt: - criteria.append(ple.voucher_no.like(f"%{txt}%")) + criteria = [ + (ple.delinked == 0), + (ple.against_voucher_no == _dn), + (ple.amount < 0), + (ple.company == company), + ] res = ( qb.from_(ple) .select( + ple.company, ple.voucher_type, ple.voucher_no, Abs(Sum(ple.amount_in_account_currency)).as_("allocated_amount"), @@ -108,3 +113,19 @@ def get_linked_payments_for_doc(doctype, txt, searchfield, start, page_len, filt group_by="against_voucher_no", fields=["against_voucher_type", "against_voucher_no", "Sum(amount_in_account_currency)"], ) + return [] + + +@frappe.whitelist() +def create_unreconcile_doc_for_selection( + company: str = None, dt: str = None, dn: str = None, selections: list = None +): + if selections: + # assuming each row is a unique voucher + for row in selections: + unrecon = frappe.new_doc("Unreconcile Payments") + unrecon.company = company + unrecon.voucher_type = dt + unrecon.voucher_type = dn + unrecon.add_references() + # remove unselected references