Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: payment reconciliation tool (backport #27128) #46109

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// For license information, please see license.txt

frappe.provide("erpnext.accounts");
<<<<<<< HEAD
erpnext.accounts.PaymentReconciliationController = frappe.ui.form.Controller.extend({
onload: function() {
const default_company = frappe.defaults.get_default('company');
Expand All @@ -12,6 +13,13 @@ erpnext.accounts.PaymentReconciliationController = frappe.ui.form.Controller.ext
this.frm.set_value('receivable_payable_account', '');

this.frm.set_query("party_type", () => {
=======
erpnext.accounts.PaymentReconciliationController = class PaymentReconciliationController extends frappe.ui.form.Controller {
onload() {
var me = this;

this.frm.set_query("party_type", function() {
>>>>>>> 3e404f15ff (refactor: payment reconciliation tool (#27128))
return {
"filters": {
"name": ["in", Object.keys(frappe.boot.party_account_types)],
Expand Down Expand Up @@ -93,11 +101,47 @@ erpnext.accounts.PaymentReconciliationController = frappe.ui.form.Controller.ext
this.frm.set_value('party', '');
},

<<<<<<< HEAD
party: function() {
this.frm.set_value('receivable_payable_account', '');
this.frm.trigger("clear_child_tables");

if (!this.frm.doc.receivable_payable_account && this.frm.doc.party_type && this.frm.doc.party) {
=======
refresh() {
this.frm.disable_save();

if (this.frm.doc.receivable_payable_account) {
this.frm.add_custom_button(__('Get Unreconciled Entries'), () =>
this.frm.trigger("get_unreconciled_entries")
);
}
if (this.frm.doc.invoices.length && this.frm.doc.payments.length) {
this.frm.add_custom_button(__('Allocate'), () =>
this.frm.trigger("allocate")
);
}
if (this.frm.doc.allocation.length) {
this.frm.add_custom_button(__('Reconcile'), () =>
this.frm.trigger("reconcile")
);
}
}

company() {
var me = this;
this.frm.set_value('receivable_payable_account', '');
me.frm.clear_table("allocation");
me.frm.clear_table("invoices");
me.frm.clear_table("payments");
me.frm.refresh_fields();
me.frm.trigger('party');
}

party() {
var me = this;
if (!me.frm.doc.receivable_payable_account && me.frm.doc.party_type && me.frm.doc.party) {
>>>>>>> 3e404f15ff (refactor: payment reconciliation tool (#27128))
return frappe.call({
method: "erpnext.accounts.party.get_party_account",
args: {
Expand All @@ -109,8 +153,12 @@ erpnext.accounts.PaymentReconciliationController = frappe.ui.form.Controller.ext
if (!r.exc && r.message) {
this.frm.set_value("receivable_payable_account", r.message);
}
<<<<<<< HEAD
this.frm.refresh();

=======
me.frm.refresh();
>>>>>>> 3e404f15ff (refactor: payment reconciliation tool (#27128))
}
});
}
Expand All @@ -133,6 +181,7 @@ erpnext.accounts.PaymentReconciliationController = frappe.ui.form.Controller.ext
return this.frm.call({
doc: this.frm.doc,
method: 'get_unreconciled_entries',
<<<<<<< HEAD
callback: () => {
if (!(this.frm.doc.payments.length || this.frm.doc.invoices.length)) {
frappe.throw({message: __("No Unreconciled Invoices and Payments found for this party and account")});
Expand All @@ -142,11 +191,19 @@ erpnext.accounts.PaymentReconciliationController = frappe.ui.form.Controller.ext
frappe.throw({message: __("No Unreconciled Payments found for this party")});
}
this.frm.refresh();
=======
callback: function(r, rt) {
if (!(me.frm.doc.payments.length || me.frm.doc.invoices.length)) {
frappe.throw({message: __("No invoice and payment records found for this party")});
}
me.frm.refresh();
>>>>>>> 3e404f15ff (refactor: payment reconciliation tool (#27128))
}
});

},

<<<<<<< HEAD
allocate: function() {
let payments = this.frm.fields_dict.payments.grid.get_selected_children();
if (!(payments.length)) {
Expand All @@ -158,11 +215,26 @@ erpnext.accounts.PaymentReconciliationController = frappe.ui.form.Controller.ext
}
return this.frm.call({
doc: this.frm.doc,
=======
allocate() {
var me = this;
let payments = me.frm.fields_dict.payments.grid.get_selected_children();
if (!(payments.length)) {
payments = me.frm.doc.payments;
}
let invoices = me.frm.fields_dict.invoices.grid.get_selected_children();
if (!(invoices.length)) {
invoices = me.frm.doc.invoices;
}
return me.frm.call({
doc: me.frm.doc,
>>>>>>> 3e404f15ff (refactor: payment reconciliation tool (#27128))
method: 'allocate_entries',
args: {
payments: payments,
invoices: invoices
},
<<<<<<< HEAD
callback: () => {
this.frm.refresh();
}
Expand All @@ -171,6 +243,17 @@ erpnext.accounts.PaymentReconciliationController = frappe.ui.form.Controller.ext

reconcile: function() {
var show_dialog = this.frm.doc.allocation.filter(d => d.difference_amount && !d.difference_account);
=======
callback: function() {
me.frm.refresh();
}
});
}

reconcile() {
var me = this;
var show_dialog = me.frm.doc.allocation.filter(d => d.difference_amount && !d.difference_account);
>>>>>>> 3e404f15ff (refactor: payment reconciliation tool (#27128))

if (show_dialog && show_dialog.length) {

Expand Down Expand Up @@ -219,7 +302,11 @@ erpnext.accounts.PaymentReconciliationController = frappe.ui.form.Controller.ext
}]
},
],
<<<<<<< HEAD
primary_action: () => {
=======
primary_action: function() {
>>>>>>> 3e404f15ff (refactor: payment reconciliation tool (#27128))
const args = dialog.get_values()["allocation"];

args.forEach(d => {
Expand Down Expand Up @@ -256,6 +343,7 @@ erpnext.accounts.PaymentReconciliationController = frappe.ui.form.Controller.ext
return this.frm.call({
doc: this.frm.doc,
method: 'reconcile',
<<<<<<< HEAD
callback: () => {
this.frm.clear_table("allocation");
this.frm.refresh();
Expand All @@ -265,3 +353,15 @@ erpnext.accounts.PaymentReconciliationController = frappe.ui.form.Controller.ext
});

$.extend(cur_frm.cscript, new erpnext.accounts.PaymentReconciliationController({frm: cur_frm}));
=======
callback: function(r, rt) {
me.frm.clear_table("allocation");
me.frm.refresh_fields();
me.frm.refresh();
}
});
}
};

extend_cscript(cur_frm.cscript, new erpnext.accounts.PaymentReconciliationController({frm: cur_frm}));
>>>>>>> 3e404f15ff (refactor: payment reconciliation tool (#27128))
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"receivable_payable_account",
"col_break1",
"from_invoice_date",
<<<<<<< HEAD
"from_payment_date",
"minimum_invoice_amount",
"minimum_payment_amount",
Expand All @@ -25,6 +26,19 @@
"payment_limit",
"bank_cash_account",
"cost_center",
=======
"to_invoice_date",
"minimum_invoice_amount",
"maximum_invoice_amount",
"invoice_limit",
"column_break_13",
"from_payment_date",
"to_payment_date",
"minimum_payment_amount",
"maximum_payment_amount",
"payment_limit",
"bank_cash_account",
>>>>>>> 3e404f15ff (refactor: payment reconciliation tool (#27128))
"sec_break1",
"invoices",
"column_break_15",
Expand Down Expand Up @@ -81,7 +95,10 @@
},
{
"depends_on": "eval:(doc.payments).length || (doc.invoices).length",
<<<<<<< HEAD
"description": "If you need to reconcile particular transactions against each other, then please select accordingly. If not, all the transactions will be allocated in FIFO order.",
=======
>>>>>>> 3e404f15ff (refactor: payment reconciliation tool (#27128))
"fieldname": "sec_break1",
"fieldtype": "Section Break",
"label": "Unreconciled Entries"
Expand Down Expand Up @@ -166,7 +183,10 @@
"label": "Maximum Payment Amount"
},
{
<<<<<<< HEAD
"description": "System will fetch all the entries if limit value is zero.",
=======
>>>>>>> 3e404f15ff (refactor: payment reconciliation tool (#27128))
"fieldname": "payment_limit",
"fieldtype": "Int",
"label": "Payment Limit"
Expand All @@ -175,6 +195,7 @@
"fieldname": "maximum_invoice_amount",
"fieldtype": "Currency",
"label": "Maximum Invoice Amount"
<<<<<<< HEAD
},
{
"fieldname": "column_break_11",
Expand All @@ -185,13 +206,19 @@
"fieldtype": "Link",
"label": "Cost Center",
"options": "Cost Center"
=======
>>>>>>> 3e404f15ff (refactor: payment reconciliation tool (#27128))
}
],
"hide_toolbar": 1,
"icon": "icon-resize-horizontal",
"issingle": 1,
"links": [],
<<<<<<< HEAD
"modified": "2022-04-29 15:37:10.246831",
=======
"modified": "2021-08-30 13:05:51.977861",
>>>>>>> 3e404f15ff (refactor: payment reconciliation tool (#27128))
"modified_by": "Administrator",
"module": "Accounts",
"name": "Payment Reconciliation",
Expand All @@ -216,6 +243,9 @@
],
"sort_field": "modified",
"sort_order": "DESC",
<<<<<<< HEAD
"states": [],
=======
>>>>>>> 3e404f15ff (refactor: payment reconciliation tool (#27128))
"track_changes": 1
}
Loading
Loading