Skip to content

Commit

Permalink
refactor: check for running job while using reconciliation tool
Browse files Browse the repository at this point in the history
  • Loading branch information
ruthra-kumar committed Mar 27, 2023
1 parent 17c270c commit 8972938
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,28 @@ erpnext.accounts.PaymentReconciliationController = class PaymentReconciliationCo
this.frm.change_custom_button_type('Get Unreconciled Entries', null, 'default');
this.frm.change_custom_button_type('Allocate', null, 'default');
}

// check for any running reconciliation jobs
if (this.frm.doc.receivable_payable_account) {
this.frm.call({
'method': "erpnext.accounts.doctype.auto_reconcile.auto_reconcile.is_any_doc_running",
"args": {
for_filter: {
company: this.frm.doc.company,
party_type: this.frm.doc.party_type,
party: this.frm.doc.party,
receivable_payable_account: this.frm.doc.receivable_payable_account
}
}
}).then(r => {
if (r.message) {
let doc_link = frappe.utils.get_form_link("Auto Reconcile", r.message[0][0], true);
let msg = __("Auto Reconciliation Job: {0} is running for this party. Can't reconcile now.", [doc_link]);
this.frm.dashboard.add_comment(msg, "yellow");
}
});
}

}

company() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@
from frappe.model.document import Document
from frappe.query_builder.custom import ConstantColumn
from frappe.query_builder.functions import IfNull
from frappe.utils import flt, getdate, nowdate, today
from frappe.utils import flt, get_link_to_form, getdate, nowdate, today

import erpnext
from erpnext.accounts.doctype.auto_reconcile.auto_reconcile import is_any_doc_running
from erpnext.accounts.utils import (
QueryPaymentLedger,
get_outstanding_invoices,
Expand Down Expand Up @@ -297,6 +298,22 @@ def get_allocated_entry(self, pay, inv, allocated_amount):

@frappe.whitelist()
def reconcile(self):
running_doc = is_any_doc_running(
dict(
company=self.company,
party_type=self.party_type,
party=self.party,
receivable_payable_account=self.receivable_payable_account,
)
)
if running_doc:
frappe.throw(
_(
"An Auto Reconciliation Job {0} is running for the same filters. Cannot reconcile now"
).format(get_link_to_form("Auto Reconcile", running_doc[0][0]))
)
return

self.validate_allocation()
dr_or_cr = (
"credit_in_account_currency"
Expand Down

0 comments on commit 8972938

Please sign in to comment.