Skip to content

Commit

Permalink
Temp fix for missing accountables on self hosted instances (#1071)
Browse files Browse the repository at this point in the history
* Temp fix #1068

* Cleanup
  • Loading branch information
zachgoll authored Aug 9, 2024
1 parent e05f03b commit c0908f4
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions app/models/account.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ class Account < ApplicationRecord

delegated_type :accountable, types: Accountable::TYPES, dependent: :destroy

delegate :value, :series, to: :accountable

class << self
def by_group(period: Period.all, currency: Money.default_currency.iso_code)
grouped_accounts = { assets: ValueGroup.new("Assets", currency), liabilities: ValueGroup.new("Liabilities", currency) }
Expand Down Expand Up @@ -75,6 +73,31 @@ def create_with_optional_start_balance!(attributes:, start_date: nil, start_bala
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
latest_sync = syncs.latest
[ latest_sync&.error, *latest_sync&.warnings ].compact.first
Expand Down

0 comments on commit c0908f4

Please sign in to comment.