1
0
Fork 0
mirror of https://github.com/maybe-finance/maybe.git synced 2025-07-19 13:19:39 +02:00

Show an error notification if account cannot be manually synced (#761)

This commit is contained in:
Jakub Kottnauer 2024-05-20 16:34:48 +02:00 committed by GitHub
parent 34811d8fd8
commit 30c19b9d2e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 91 additions and 84 deletions

View file

@ -74,14 +74,22 @@ class AccountsController < ApplicationController
end
def sync
@account.sync_later if @account.can_sync?
if @account.can_sync?
@account.sync_later
respond_to do |format|
format.html { redirect_to account_path(@account), notice: t(".success") }
format.turbo_stream do
render turbo_stream: turbo_stream.append("notification-tray", partial: "shared/notification", locals: { type: "success", content: { body: t(".success") } })
end
end
else
respond_to do |format|
format.html { redirect_to account_path(@account), notice: t(".cannot_sync") }
format.turbo_stream do
render turbo_stream: turbo_stream.append("notification-tray", partial: "shared/notification", locals: { type: "error", content: { body: t(".cannot_sync") } })
end
end
end
end
private

View file

@ -17,10 +17,8 @@ module Account::Syncable
self.balances.upsert_all(calculator.daily_balances, unique_by: :index_account_balances_on_account_id_date_currency_unique)
self.balances.where("date < ?", effective_start_date).delete_all
new_balance = calculator.daily_balances.select { |b| b[:currency] == self.currency }.last[:balance]
self.balance = new_balance
self.save!
update!(status: "ok", last_sync_date: Date.today)
update!(status: "ok", last_sync_date: Date.today, balance: new_balance)
rescue => e
update!(status: "error")
Rails.logger.error("Failed to sync account #{id}: #{e.message}")

View file

@ -38,6 +38,7 @@ en:
summary:
new: New account
sync:
cannot_sync: Account cannot be synced at the moment
success: Account sync started
update:
success: Account updated successfully