mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-27 08:54:45 +00:00
feat: add "Sync Now" to Plaid Settings (#23602)
This commit is contained in:
@@ -15,6 +15,22 @@ frappe.ui.form.on('Plaid Settings', {
|
|||||||
frm.add_custom_button('Link a new bank account', () => {
|
frm.add_custom_button('Link a new bank account', () => {
|
||||||
new erpnext.integrations.plaidLink(frm);
|
new erpnext.integrations.plaidLink(frm);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
frm.add_custom_button(__("Sync Now"), () => {
|
||||||
|
frappe.call({
|
||||||
|
method: "erpnext.erpnext_integrations.doctype.plaid_settings.plaid_settings.enqueue_synchronization",
|
||||||
|
freeze: true,
|
||||||
|
callback: () => {
|
||||||
|
let bank_transaction_link = '<a href="#List/Bank Transaction">Bank Transaction</a>';
|
||||||
|
|
||||||
|
frappe.msgprint({
|
||||||
|
title: __("Sync Started"),
|
||||||
|
message: __("The sync has started in the background, please check the {0} list for new records.", [bank_transaction_link]),
|
||||||
|
alert: 1
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}).addClass("btn-primary");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -166,7 +166,6 @@ def get_transactions(bank, bank_account=None, start_date=None, end_date=None):
|
|||||||
related_bank = frappe.db.get_values("Bank Account", bank_account, ["bank", "integration_id"], as_dict=True)
|
related_bank = frappe.db.get_values("Bank Account", bank_account, ["bank", "integration_id"], as_dict=True)
|
||||||
access_token = frappe.db.get_value("Bank", related_bank[0].bank, "plaid_access_token")
|
access_token = frappe.db.get_value("Bank", related_bank[0].bank, "plaid_access_token")
|
||||||
account_id = related_bank[0].integration_id
|
account_id = related_bank[0].integration_id
|
||||||
|
|
||||||
else:
|
else:
|
||||||
access_token = frappe.db.get_value("Bank", bank, "plaid_access_token")
|
access_token = frappe.db.get_value("Bank", bank, "plaid_access_token")
|
||||||
account_id = None
|
account_id = None
|
||||||
@@ -228,13 +227,19 @@ def new_bank_transaction(transaction):
|
|||||||
|
|
||||||
def automatic_synchronization():
|
def automatic_synchronization():
|
||||||
settings = frappe.get_doc("Plaid Settings", "Plaid Settings")
|
settings = frappe.get_doc("Plaid Settings", "Plaid Settings")
|
||||||
|
|
||||||
if settings.enabled == 1 and settings.automatic_sync == 1:
|
if settings.enabled == 1 and settings.automatic_sync == 1:
|
||||||
plaid_accounts = frappe.get_all("Bank Account", filters={"integration_id": ["!=", ""]}, fields=["name", "bank"])
|
enqueue_synchronization()
|
||||||
|
|
||||||
for plaid_account in plaid_accounts:
|
|
||||||
frappe.enqueue(
|
@frappe.whitelist()
|
||||||
"erpnext.erpnext_integrations.doctype.plaid_settings.plaid_settings.sync_transactions",
|
def enqueue_synchronization():
|
||||||
bank=plaid_account.bank,
|
plaid_accounts = frappe.get_all("Bank Account",
|
||||||
bank_account=plaid_account.name
|
filters={"integration_id": ["!=", ""]},
|
||||||
)
|
fields=["name", "bank"])
|
||||||
|
|
||||||
|
for plaid_account in plaid_accounts:
|
||||||
|
frappe.enqueue(
|
||||||
|
"erpnext.erpnext_integrations.doctype.plaid_settings.plaid_settings.sync_transactions",
|
||||||
|
bank=plaid_account.bank,
|
||||||
|
bank_account=plaid_account.name
|
||||||
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user