fix: make transaction date of the oldest transaction as the last integration date (#22000)
* fix: make transaction date of the oldest transaction as the last integration date * chore: remove blank line after docstring
This commit is contained in:
parent
0032d7765f
commit
706524f1ae
@ -124,10 +124,11 @@ def add_account_subtype(account_subtype):
|
|||||||
|
|
||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
def sync_transactions(bank, bank_account):
|
def sync_transactions(bank, bank_account):
|
||||||
|
'''Sync transactions based on the last integration date as the start date, after the sync is completed
|
||||||
last_sync_date = frappe.db.get_value("Bank Account", bank_account, "last_integration_date")
|
add the transaction date of the oldest transaction as the last integration date'''
|
||||||
if last_sync_date:
|
last_transaction_date = frappe.db.get_value("Bank Account", bank_account, "last_integration_date")
|
||||||
start_date = formatdate(last_sync_date, "YYYY-MM-dd")
|
if last_transaction_date:
|
||||||
|
start_date = formatdate(last_transaction_date, "YYYY-MM-dd")
|
||||||
else:
|
else:
|
||||||
start_date = formatdate(add_months(today(), -12), "YYYY-MM-dd")
|
start_date = formatdate(add_months(today(), -12), "YYYY-MM-dd")
|
||||||
end_date = formatdate(today(), "YYYY-MM-dd")
|
end_date = formatdate(today(), "YYYY-MM-dd")
|
||||||
@ -139,12 +140,14 @@ def sync_transactions(bank, bank_account):
|
|||||||
for transaction in reversed(transactions):
|
for transaction in reversed(transactions):
|
||||||
result += new_bank_transaction(transaction)
|
result += new_bank_transaction(transaction)
|
||||||
|
|
||||||
|
if result:
|
||||||
|
end_date = frappe.db.get_value('Bank Transaction', result.pop(), 'date')
|
||||||
|
|
||||||
frappe.logger().info("Plaid added {} new Bank Transactions from '{}' between {} and {}".format(
|
frappe.logger().info("Plaid added {} new Bank Transactions from '{}' between {} and {}".format(
|
||||||
len(result), bank_account, start_date, end_date))
|
len(result), bank_account, start_date, end_date))
|
||||||
|
|
||||||
frappe.db.set_value("Bank Account", bank_account, "last_integration_date", getdate(end_date))
|
frappe.db.set_value("Bank Account", bank_account, "last_integration_date", end_date)
|
||||||
|
|
||||||
return result
|
|
||||||
except Exception:
|
except Exception:
|
||||||
frappe.log_error(frappe.get_traceback(), _("Plaid transactions sync error"))
|
frappe.log_error(frappe.get_traceback(), _("Plaid transactions sync error"))
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user