mirror of
https://github.com/maybe-finance/maybe.git
synced 2025-07-25 16:19:40 +02:00
Temp fix for missing accountables on self hosted instances (#1071)
* Temp fix #1068 * Cleanup
This commit is contained in:
parent
e05f03b314
commit
c0908f454a
1 changed files with 25 additions and 2 deletions
|
@ -28,8 +28,6 @@ class Account < ApplicationRecord
|
||||||
|
|
||||||
delegated_type :accountable, types: Accountable::TYPES, dependent: :destroy
|
delegated_type :accountable, types: Accountable::TYPES, dependent: :destroy
|
||||||
|
|
||||||
delegate :value, :series, to: :accountable
|
|
||||||
|
|
||||||
class << self
|
class << self
|
||||||
def by_group(period: Period.all, currency: Money.default_currency.iso_code)
|
def by_group(period: Period.all, currency: Money.default_currency.iso_code)
|
||||||
grouped_accounts = { assets: ValueGroup.new("Assets", currency), liabilities: ValueGroup.new("Liabilities", currency) }
|
grouped_accounts = { assets: ValueGroup.new("Assets", currency), liabilities: ValueGroup.new("Liabilities", currency) }
|
||||||
|
@ -75,6 +73,31 @@ class Account < ApplicationRecord
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Start of temporary fix for #1068
|
||||||
|
# ==========================================================================
|
||||||
|
|
||||||
|
# TODO: Both `series` and `value` methods are a temporary fix for #1068, which appears to be a data corruption issue.
|
||||||
|
# Every account should have an accountable no matter what, but some self hosted instances seem to have missing accountables.
|
||||||
|
# When this is fixed, we can add this back to `delegate :value, :series, to: :accountable`
|
||||||
|
def series(period: Period.all, currency: self.currency)
|
||||||
|
if accountable.present?
|
||||||
|
accountable.series(period: period, currency: currency)
|
||||||
|
else
|
||||||
|
TimeSeries.new([])
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def value
|
||||||
|
if accountable.present?
|
||||||
|
accountable.value
|
||||||
|
else
|
||||||
|
balance_money
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# ==========================================================================
|
||||||
|
# End of temporary fix for #1068
|
||||||
|
|
||||||
def alert
|
def alert
|
||||||
latest_sync = syncs.latest
|
latest_sync = syncs.latest
|
||||||
[ latest_sync&.error, *latest_sync&.warnings ].compact.first
|
[ latest_sync&.error, *latest_sync&.warnings ].compact.first
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue