chore: move functions to a separate file in utils
This commit is contained in:
parent
5981c7e0ad
commit
25fe752185
@ -154,6 +154,7 @@ frappe.ui.form.on('Payment Entry', {
|
||||
frm.events.set_dynamic_labels(frm);
|
||||
frm.events.show_general_ledger(frm);
|
||||
erpnext.accounts.ledger_preview.show_accounting_ledger_preview(frm);
|
||||
erpnext.accounts.unreconcile_payments.add_unreconcile_btn(frm);
|
||||
},
|
||||
|
||||
validate_company: (frm) => {
|
||||
|
@ -184,22 +184,7 @@ erpnext.accounts.SalesInvoiceController = class SalesInvoiceController extends e
|
||||
}
|
||||
}
|
||||
|
||||
if (doc.docstatus == 1) {
|
||||
frappe.call({
|
||||
"method": "erpnext.accounts.doctype.unreconcile_payments.unreconcile_payments.doc_has_payments",
|
||||
"args": {
|
||||
"doctype": this.frm.doc.doctype,
|
||||
"docname": this.frm.doc.name
|
||||
},
|
||||
callback: function(r) {
|
||||
if (r.message) {
|
||||
me.frm.add_custom_button(__("Un-Reconcile"), function() {
|
||||
erpnext.utils.build_unreconcile_dialog(cur_frm);
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
erpnext.accounts.unreconcile_payments.add_unreconcile_btn(me.frm);
|
||||
}
|
||||
|
||||
|
||||
|
@ -117,15 +117,22 @@ def get_linked_payments_for_doc(
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def create_unreconcile_doc_for_selection(
|
||||
company: str = None, dt: str = None, dn: str = None, selections: list = None
|
||||
):
|
||||
def create_unreconcile_doc_for_selection(selections=None):
|
||||
if selections:
|
||||
selections = frappe.json.loads(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.company = row.get("company")
|
||||
unrecon.voucher_type = row.get("voucher_type")
|
||||
unrecon.voucher_no = row.get("voucher_no")
|
||||
unrecon.add_references()
|
||||
|
||||
# remove unselected references
|
||||
unrecon.allocations = [
|
||||
x
|
||||
for x in unrecon.allocations
|
||||
if x.reference_doctype == row.get("against_voucher_type")
|
||||
and x.reference_name == row.get("against_voucher_no")
|
||||
]
|
||||
unrecon.save().submit()
|
||||
|
@ -16,7 +16,8 @@ import "./utils/customer_quick_entry";
|
||||
import "./utils/supplier_quick_entry";
|
||||
import "./call_popup/call_popup";
|
||||
import "./utils/dimension_tree_filter";
|
||||
import "./utils/ledger_preview.js"
|
||||
import "./utils/ledger_preview.js";
|
||||
import "./utils/unreconcile.js";
|
||||
import "./utils/barcode_scanner";
|
||||
import "./telephony";
|
||||
import "./templates/call_link.html";
|
||||
|
@ -769,61 +769,8 @@ erpnext.utils.update_child_items = function(opts) {
|
||||
dialog.show();
|
||||
}
|
||||
|
||||
erpnext.utils.build_unreconcile_dialog = function(frm) {
|
||||
if (['Sales Invoice', 'Purchase Invoice', 'Payment Entry', 'Journal Entry'].includes(frm.doc.doctype)) {
|
||||
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,
|
||||
},
|
||||
];
|
||||
|
||||
// get linked payments
|
||||
frappe.call({
|
||||
"method": "erpnext.accounts.doctype.unreconcile_payments.unreconcile_payments.get_linked_payments_for_doc",
|
||||
"args": {
|
||||
"company": frm.doc.company,
|
||||
"doctype": frm.doc.doctype,
|
||||
"docname": 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();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
erpnext.utils.map_current_doc = function(opts) {
|
||||
function _map() {
|
||||
|
106
erpnext/public/js/utils/unreconcile.js
Normal file
106
erpnext/public/js/utils/unreconcile.js
Normal file
@ -0,0 +1,106 @@
|
||||
frappe.provide('erpnext.accounts');
|
||||
|
||||
erpnext.accounts.unreconcile_payments = {
|
||||
add_unreconcile_btn(frm) {
|
||||
if (frm.doc.docstatus == 1) {
|
||||
frappe.call({
|
||||
"method": "erpnext.accounts.doctype.unreconcile_payments.unreconcile_payments.doc_has_payments",
|
||||
"args": {
|
||||
"doctype": frm.doc.doctype,
|
||||
"docname": frm.doc.name
|
||||
},
|
||||
callback: function(r) {
|
||||
if (r.message) {
|
||||
frm.add_custom_button(__("Un-Reconcile"), function() {
|
||||
erpnext.accounts.unreconcile_payments.build_unreconcile_dialog(frm);
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
build_unreconcile_dialog(frm) {
|
||||
if (['Sales Invoice', 'Purchase Invoice', 'Payment Entry', 'Journal Entry'].includes(frm.doc.doctype)) {
|
||||
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,
|
||||
},
|
||||
];
|
||||
|
||||
// get linked payments
|
||||
frappe.call({
|
||||
"method": "erpnext.accounts.doctype.unreconcile_payments.unreconcile_payments.get_linked_payments_for_doc",
|
||||
"args": {
|
||||
"company": frm.doc.company,
|
||||
"doctype": frm.doc.doctype,
|
||||
"docname": 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 creates unreconcile doc for each row
|
||||
if (['Sales Invoice', 'Purchase Invoice'].includes(frm.doc.doctype)) {
|
||||
let selection_map = selected_allocations.map(function(elem) {
|
||||
return {
|
||||
company: elem.company,
|
||||
voucher_type: elem.voucher_type,
|
||||
voucher_no: elem.voucher_no,
|
||||
against_voucher_type: frm.doc.doctype,
|
||||
against_voucher_no: frm.doc.name
|
||||
};
|
||||
|
||||
});
|
||||
|
||||
erpnext.utils.create_unreconcile_docs(selection_map);
|
||||
d.hide();
|
||||
}
|
||||
|
||||
} else {
|
||||
frappe.msgprint("No Selection");
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
d.show();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
create_unreconcile_docs(selection_map) {
|
||||
frappe.call({
|
||||
"method": "erpnext.accounts.doctype.unreconcile_payments.unreconcile_payments.create_unreconcile_doc_for_selection",
|
||||
"args": {
|
||||
"selections": selection_map
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user