From 285e093e62a8cece1f39787eef0730dfbc2210bf Mon Sep 17 00:00:00 2001 From: Zach Gollwitzer Date: Fri, 9 Aug 2024 12:33:05 -0400 Subject: [PATCH 1/2] Temp fix #1068 --- app/models/account.rb | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/app/models/account.rb b/app/models/account.rb index e71390d6..68a6cdc6 100644 --- a/app/models/account.rb +++ b/app/models/account.rb @@ -28,7 +28,7 @@ class Account < ApplicationRecord delegated_type :accountable, types: Accountable::TYPES, dependent: :destroy - delegate :value, :series, to: :accountable + delegate :value, to: :accountable class << self def by_group(period: Period.all, currency: Money.default_currency.iso_code) @@ -75,6 +75,31 @@ class Account < ApplicationRecord 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 -- 2.53.0 From 34c70ee49d38b5975d15954cbe14cdb31fb5513e Mon Sep 17 00:00:00 2001 From: Zach Gollwitzer Date: Fri, 9 Aug 2024 12:36:51 -0400 Subject: [PATCH 2/2] Cleanup --- app/models/account.rb | 2 -- 1 file changed, 2 deletions(-) diff --git a/app/models/account.rb b/app/models/account.rb index 68a6cdc6..0efa8542 100644 --- a/app/models/account.rb +++ b/app/models/account.rb @@ -28,8 +28,6 @@ class Account < ApplicationRecord delegated_type :accountable, types: Accountable::TYPES, dependent: :destroy - delegate :value, 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) } -- 2.53.0