fix(Payment Reconciliation): clear child tables on company/party change (#28008)
This commit is contained in:
parent
15e9b5170d
commit
1a6e98ed48
@ -4,9 +4,14 @@
|
|||||||
frappe.provide("erpnext.accounts");
|
frappe.provide("erpnext.accounts");
|
||||||
erpnext.accounts.PaymentReconciliationController = class PaymentReconciliationController extends frappe.ui.form.Controller {
|
erpnext.accounts.PaymentReconciliationController = class PaymentReconciliationController extends frappe.ui.form.Controller {
|
||||||
onload() {
|
onload() {
|
||||||
var me = this;
|
const default_company = frappe.defaults.get_default('company');
|
||||||
|
this.frm.set_value('company', default_company);
|
||||||
|
|
||||||
this.frm.set_query("party_type", function() {
|
this.frm.set_value('party_type', '');
|
||||||
|
this.frm.set_value('party', '');
|
||||||
|
this.frm.set_value('receivable_payable_account', '');
|
||||||
|
|
||||||
|
this.frm.set_query("party_type", () => {
|
||||||
return {
|
return {
|
||||||
"filters": {
|
"filters": {
|
||||||
"name": ["in", Object.keys(frappe.boot.party_account_types)],
|
"name": ["in", Object.keys(frappe.boot.party_account_types)],
|
||||||
@ -14,44 +19,30 @@ erpnext.accounts.PaymentReconciliationController = class PaymentReconciliationCo
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
this.frm.set_query('receivable_payable_account', function() {
|
this.frm.set_query('receivable_payable_account', () => {
|
||||||
check_mandatory(me.frm);
|
|
||||||
return {
|
return {
|
||||||
filters: {
|
filters: {
|
||||||
"company": me.frm.doc.company,
|
"company": this.frm.doc.company,
|
||||||
"is_group": 0,
|
"is_group": 0,
|
||||||
"account_type": frappe.boot.party_account_types[me.frm.doc.party_type]
|
"account_type": frappe.boot.party_account_types[this.frm.doc.party_type]
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
this.frm.set_query('bank_cash_account', function() {
|
this.frm.set_query('bank_cash_account', () => {
|
||||||
check_mandatory(me.frm, true);
|
|
||||||
return {
|
return {
|
||||||
filters:[
|
filters:[
|
||||||
['Account', 'company', '=', me.frm.doc.company],
|
['Account', 'company', '=', this.frm.doc.company],
|
||||||
['Account', 'is_group', '=', 0],
|
['Account', 'is_group', '=', 0],
|
||||||
['Account', 'account_type', 'in', ['Bank', 'Cash']]
|
['Account', 'account_type', 'in', ['Bank', 'Cash']]
|
||||||
]
|
]
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
this.frm.set_value('party_type', '');
|
|
||||||
this.frm.set_value('party', '');
|
|
||||||
this.frm.set_value('receivable_payable_account', '');
|
|
||||||
|
|
||||||
var check_mandatory = (frm, only_company=false) => {
|
|
||||||
var title = __("Mandatory");
|
|
||||||
if (only_company && !frm.doc.company) {
|
|
||||||
frappe.throw({message: __("Please Select a Company First"), title: title});
|
|
||||||
} else if (!frm.doc.company || !frm.doc.party_type) {
|
|
||||||
frappe.throw({message: __("Please Select Both Company and Party Type First"), title: title});
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
refresh() {
|
refresh() {
|
||||||
this.frm.disable_save();
|
this.frm.disable_save();
|
||||||
|
|
||||||
this.frm.set_df_property('invoices', 'cannot_delete_rows', true);
|
this.frm.set_df_property('invoices', 'cannot_delete_rows', true);
|
||||||
this.frm.set_df_property('payments', 'cannot_delete_rows', true);
|
this.frm.set_df_property('payments', 'cannot_delete_rows', true);
|
||||||
this.frm.set_df_property('allocation', 'cannot_delete_rows', true);
|
this.frm.set_df_property('allocation', 'cannot_delete_rows', true);
|
||||||
@ -85,76 +76,92 @@ erpnext.accounts.PaymentReconciliationController = class PaymentReconciliationCo
|
|||||||
}
|
}
|
||||||
|
|
||||||
company() {
|
company() {
|
||||||
var me = this;
|
this.frm.set_value('party', '');
|
||||||
this.frm.set_value('receivable_payable_account', '');
|
this.frm.set_value('receivable_payable_account', '');
|
||||||
me.frm.clear_table("allocation");
|
}
|
||||||
me.frm.clear_table("invoices");
|
|
||||||
me.frm.clear_table("payments");
|
party_type() {
|
||||||
me.frm.refresh_fields();
|
this.frm.set_value('party', '');
|
||||||
me.frm.trigger('party');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
party() {
|
party() {
|
||||||
var me = this;
|
this.frm.set_value('receivable_payable_account', '');
|
||||||
if (!me.frm.doc.receivable_payable_account && me.frm.doc.party_type && me.frm.doc.party) {
|
this.frm.trigger("clear_child_tables");
|
||||||
|
|
||||||
|
if (!this.frm.doc.receivable_payable_account && this.frm.doc.party_type && this.frm.doc.party) {
|
||||||
return frappe.call({
|
return frappe.call({
|
||||||
method: "erpnext.accounts.party.get_party_account",
|
method: "erpnext.accounts.party.get_party_account",
|
||||||
args: {
|
args: {
|
||||||
company: me.frm.doc.company,
|
company: this.frm.doc.company,
|
||||||
party_type: me.frm.doc.party_type,
|
party_type: this.frm.doc.party_type,
|
||||||
party: me.frm.doc.party
|
party: this.frm.doc.party
|
||||||
},
|
},
|
||||||
callback: function(r) {
|
callback: (r) => {
|
||||||
if (!r.exc && r.message) {
|
if (!r.exc && r.message) {
|
||||||
me.frm.set_value("receivable_payable_account", r.message);
|
this.frm.set_value("receivable_payable_account", r.message);
|
||||||
}
|
}
|
||||||
me.frm.refresh();
|
this.frm.refresh();
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
get_unreconciled_entries() {
|
receivable_payable_account() {
|
||||||
var me = this;
|
this.frm.trigger("clear_child_tables");
|
||||||
return this.frm.call({
|
this.frm.refresh();
|
||||||
doc: me.frm.doc,
|
|
||||||
method: 'get_unreconciled_entries',
|
|
||||||
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();
|
|
||||||
|
clear_child_tables() {
|
||||||
|
this.frm.clear_table("invoices");
|
||||||
|
this.frm.clear_table("payments");
|
||||||
|
this.frm.clear_table("allocation");
|
||||||
|
this.frm.refresh_fields();
|
||||||
|
}
|
||||||
|
|
||||||
|
get_unreconciled_entries() {
|
||||||
|
this.frm.clear_table("allocation");
|
||||||
|
return this.frm.call({
|
||||||
|
doc: this.frm.doc,
|
||||||
|
method: 'get_unreconciled_entries',
|
||||||
|
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")});
|
||||||
|
} else if (!(this.frm.doc.invoices.length)) {
|
||||||
|
frappe.throw({message: __("No Outstanding Invoices found for this party")});
|
||||||
|
} else if (!(this.frm.doc.payments.length)) {
|
||||||
|
frappe.throw({message: __("No Unreconciled Payments found for this party")});
|
||||||
|
}
|
||||||
|
this.frm.refresh();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
allocate() {
|
allocate() {
|
||||||
var me = this;
|
let payments = this.frm.fields_dict.payments.grid.get_selected_children();
|
||||||
let payments = me.frm.fields_dict.payments.grid.get_selected_children();
|
|
||||||
if (!(payments.length)) {
|
if (!(payments.length)) {
|
||||||
payments = me.frm.doc.payments;
|
payments = this.frm.doc.payments;
|
||||||
}
|
}
|
||||||
let invoices = me.frm.fields_dict.invoices.grid.get_selected_children();
|
let invoices = this.frm.fields_dict.invoices.grid.get_selected_children();
|
||||||
if (!(invoices.length)) {
|
if (!(invoices.length)) {
|
||||||
invoices = me.frm.doc.invoices;
|
invoices = this.frm.doc.invoices;
|
||||||
}
|
}
|
||||||
return me.frm.call({
|
return this.frm.call({
|
||||||
doc: me.frm.doc,
|
doc: this.frm.doc,
|
||||||
method: 'allocate_entries',
|
method: 'allocate_entries',
|
||||||
args: {
|
args: {
|
||||||
payments: payments,
|
payments: payments,
|
||||||
invoices: invoices
|
invoices: invoices
|
||||||
},
|
},
|
||||||
callback: function() {
|
callback: () => {
|
||||||
me.frm.refresh();
|
this.frm.refresh();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
reconcile() {
|
reconcile() {
|
||||||
var me = this;
|
var show_dialog = this.frm.doc.allocation.filter(d => d.difference_amount && !d.difference_account);
|
||||||
var show_dialog = me.frm.doc.allocation.filter(d => d.difference_amount && !d.difference_account);
|
|
||||||
|
|
||||||
if (show_dialog && show_dialog.length) {
|
if (show_dialog && show_dialog.length) {
|
||||||
|
|
||||||
@ -186,10 +193,10 @@ erpnext.accounts.PaymentReconciliationController = class PaymentReconciliationCo
|
|||||||
label: __("Difference Account"),
|
label: __("Difference Account"),
|
||||||
fieldname: 'difference_account',
|
fieldname: 'difference_account',
|
||||||
reqd: 1,
|
reqd: 1,
|
||||||
get_query: function() {
|
get_query: () => {
|
||||||
return {
|
return {
|
||||||
filters: {
|
filters: {
|
||||||
company: me.frm.doc.company,
|
company: this.frm.doc.company,
|
||||||
is_group: 0
|
is_group: 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -203,7 +210,7 @@ erpnext.accounts.PaymentReconciliationController = class PaymentReconciliationCo
|
|||||||
}]
|
}]
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
primary_action: function() {
|
primary_action: () => {
|
||||||
const args = dialog.get_values()["allocation"];
|
const args = dialog.get_values()["allocation"];
|
||||||
|
|
||||||
args.forEach(d => {
|
args.forEach(d => {
|
||||||
@ -211,7 +218,7 @@ erpnext.accounts.PaymentReconciliationController = class PaymentReconciliationCo
|
|||||||
"difference_account", d.difference_account);
|
"difference_account", d.difference_account);
|
||||||
});
|
});
|
||||||
|
|
||||||
me.reconcile_payment_entries();
|
this.reconcile_payment_entries();
|
||||||
dialog.hide();
|
dialog.hide();
|
||||||
},
|
},
|
||||||
primary_action_label: __('Reconcile Entries')
|
primary_action_label: __('Reconcile Entries')
|
||||||
@ -237,15 +244,12 @@ erpnext.accounts.PaymentReconciliationController = class PaymentReconciliationCo
|
|||||||
}
|
}
|
||||||
|
|
||||||
reconcile_payment_entries() {
|
reconcile_payment_entries() {
|
||||||
var me = this;
|
|
||||||
|
|
||||||
return this.frm.call({
|
return this.frm.call({
|
||||||
doc: me.frm.doc,
|
doc: this.frm.doc,
|
||||||
method: 'reconcile',
|
method: 'reconcile',
|
||||||
callback: function(r, rt) {
|
callback: () => {
|
||||||
me.frm.clear_table("allocation");
|
this.frm.clear_table("allocation");
|
||||||
me.frm.refresh_fields();
|
this.frm.refresh();
|
||||||
me.frm.refresh();
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -450,7 +450,8 @@ def update_reference_in_journal_entry(d, journal_entry, do_not_save=False):
|
|||||||
|
|
||||||
# new row with references
|
# new row with references
|
||||||
new_row = journal_entry.append("accounts")
|
new_row = journal_entry.append("accounts")
|
||||||
new_row.update(jv_detail.as_dict().copy())
|
|
||||||
|
new_row.update((frappe.copy_doc(jv_detail)).as_dict())
|
||||||
|
|
||||||
new_row.set(d["dr_or_cr"], d["allocated_amount"])
|
new_row.set(d["dr_or_cr"], d["allocated_amount"])
|
||||||
new_row.set('debit' if d['dr_or_cr'] == 'debit_in_account_currency' else 'credit',
|
new_row.set('debit' if d['dr_or_cr'] == 'debit_in_account_currency' else 'credit',
|
||||||
|
Loading…
x
Reference in New Issue
Block a user