mirror of
https://github.com/maybe-finance/maybe.git
synced 2025-07-29 10:09:39 +02:00
Fix signage on transaction imports (#1236)
This commit is contained in:
parent
1ffa13f3b3
commit
73d61fc990
1 changed files with 9 additions and 3 deletions
|
@ -24,9 +24,9 @@ class Import::Row < ApplicationRecord
|
||||||
|
|
||||||
def signed_amount
|
def signed_amount
|
||||||
if import.type == "TradeImport"
|
if import.type == "TradeImport"
|
||||||
price.to_d * apply_signage_convention(qty.to_d)
|
price.to_d * apply_trade_signage_convention(qty.to_d)
|
||||||
else
|
else
|
||||||
apply_signage_convention(amount.to_d)
|
apply_transaction_signage_convention(amount.to_d)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -38,10 +38,16 @@ class Import::Row < ApplicationRecord
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
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)
|
value * (import.signage_convention == "inflows_positive" ? 1 : -1)
|
||||||
end
|
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
|
def required_columns
|
||||||
import.required_column_keys.each do |required_key|
|
import.required_column_keys.each do |required_key|
|
||||||
errors.add(required_key, "is required") if self[required_key].blank?
|
errors.add(required_key, "is required") if self[required_key].blank?
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue