refactor: add UI elements

This commit is contained in:
ruthra kumar 2023-08-29 11:27:16 +05:30
parent 6bbe47c671
commit 58dc0e52e1
2 changed files with 77 additions and 31 deletions

View File

@ -203,32 +203,57 @@ erpnext.accounts.SalesInvoiceController = class SalesInvoiceController extends e
} }
unreconcile_prompt() { unreconcile_prompt() {
// get linked payments let child_table_fields = [
let query_args = { { label: __("Voucher Type"), fieldname: "voucher_type", fieldtype: "Dynamic Link", options: "DocType", in_list_view: 1, read_only: 1},
query:"erpnext.accounts.doctype.unreconcile_payments.unreconcile_payments.get_linked_payments_for_doc", { label: __("Voucher No"), fieldname: "voucher_no", fieldtype: "Link", options: "voucher_type", in_list_view: 1, read_only: 1 },
filters: { { label: __("Allocated Amount"), fieldname: "allocated_amount", fieldtype: "Float", in_list_view: 1, read_only: 1 },
doctype: this.frm.doc.doctype, ]
docname: this.frm.doc.name let unreconcile_dialog_fields = [
} {
} label: __('Allocations'),
fieldname: 'allocations',
new frappe.ui.form.MultiSelectDialog({ fieldtype: 'Table',
doctype: "Payment Ledger Entry", read_only: 1,
target: this.cur_frm, fields: child_table_fields,
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;
}, },
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() { make_maintenance_schedule() {

View File

@ -73,20 +73,25 @@ def doc_has_payments(doctype, docname):
@frappe.whitelist() @frappe.whitelist()
def get_linked_payments_for_doc(doctype, txt, searchfield, start, page_len, filters): def get_linked_payments_for_doc(
if filters.get("doctype") and filters.get("docname"): company: str = None, doctype: str = None, docname: str = None
_dt = filters.get("doctype") ) -> list:
_dn = filters.get("docname") if company and doctype and docname:
_dt = doctype
_dn = docname
ple = qb.DocType("Payment Ledger Entry") ple = qb.DocType("Payment Ledger Entry")
if _dt in ["Sales Invoice", "Purchase Invoice"]: if _dt in ["Sales Invoice", "Purchase Invoice"]:
criteria = [(ple.delinked == 0), (ple.against_voucher_no == _dn), (ple.amount < 0)] criteria = [
(ple.delinked == 0),
if txt: (ple.against_voucher_no == _dn),
criteria.append(ple.voucher_no.like(f"%{txt}%")) (ple.amount < 0),
(ple.company == company),
]
res = ( res = (
qb.from_(ple) qb.from_(ple)
.select( .select(
ple.company,
ple.voucher_type, ple.voucher_type,
ple.voucher_no, ple.voucher_no,
Abs(Sum(ple.amount_in_account_currency)).as_("allocated_amount"), 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", group_by="against_voucher_no",
fields=["against_voucher_type", "against_voucher_no", "Sum(amount_in_account_currency)"], 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