mirror of
https://github.com/we-promise/sure.git
synced 2026-04-19 20:14:08 +00:00
Allow transfers based on transactions in different currencies (#903)
* Allow transfers between transactions in different currencies * Review fixes
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
class Account::Transfer < ApplicationRecord
|
||||
has_many :transactions, dependent: :nullify
|
||||
|
||||
validate :transaction_count, :from_different_accounts, :net_zero_flows, :all_transactions_marked
|
||||
validate :net_zero_flows, if: :single_currency_transfer?
|
||||
validate :transaction_count, :from_different_accounts, :all_transactions_marked
|
||||
|
||||
def inflow_transaction
|
||||
transactions.find { |t| t.inflow? }
|
||||
@@ -32,6 +33,10 @@ class Account::Transfer < ApplicationRecord
|
||||
|
||||
private
|
||||
|
||||
def single_currency_transfer?
|
||||
transactions.map(&:currency).uniq.size == 1
|
||||
end
|
||||
|
||||
def transaction_count
|
||||
unless transactions.size == 2
|
||||
errors.add :transactions, "must have exactly 2 transactions"
|
||||
|
||||
Reference in New Issue
Block a user