1
0
Fork 0
mirror of https://github.com/maybe-finance/maybe.git synced 2025-07-24 23:59:40 +02:00

Fix signage on transaction imports (#1236)

This commit is contained in:
Zach Gollwitzer 2024-10-03 14:59:24 -04:00 committed by GitHub
parent 1ffa13f3b3
commit 73d61fc990
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -24,9 +24,9 @@ class Import::Row < ApplicationRecord
def signed_amount
if import.type == "TradeImport"
price.to_d * apply_signage_convention(qty.to_d)
price.to_d * apply_trade_signage_convention(qty.to_d)
else
apply_signage_convention(amount.to_d)
apply_transaction_signage_convention(amount.to_d)
end
end
@ -38,10 +38,16 @@ class Import::Row < ApplicationRecord
end
private
def apply_signage_convention(value)
# In the Maybe system, positive quantities == "inflows"
def apply_trade_signage_convention(value)
value * (import.signage_convention == "inflows_positive" ? 1 : -1)
end
# In the Maybe system, positive amounts == "outflows", so we must reverse signage
def apply_transaction_signage_convention(value)
value * (import.signage_convention == "inflows_positive" ? -1 : 1)
end
def required_columns
import.required_column_keys.each do |required_key|
errors.add(required_key, "is required") if self[required_key].blank?