mirror of
https://github.com/maybe-finance/maybe.git
synced 2025-08-09 15:35:22 +02:00
Account:: namespace simplifications and cleanup (#2110)
* Flatten Holding model * Flatten balance model * Entries domain renames * Fix valuations reference * Fix trades stream * Fix brakeman warnings * Fix tests * Replace existing entryable type references in DB
This commit is contained in:
parent
f181ba941f
commit
e657c40d19
172 changed files with 1297 additions and 1258 deletions
40
app/models/transaction/transferable.rb
Normal file
40
app/models/transaction/transferable.rb
Normal file
|
@ -0,0 +1,40 @@
|
|||
module Transaction::Transferable
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
included do
|
||||
has_one :transfer_as_inflow, class_name: "Transfer", foreign_key: "inflow_transaction_id", dependent: :destroy
|
||||
has_one :transfer_as_outflow, class_name: "Transfer", foreign_key: "outflow_transaction_id", dependent: :destroy
|
||||
|
||||
# We keep track of rejected transfers to avoid auto-matching them again
|
||||
has_one :rejected_transfer_as_inflow, class_name: "RejectedTransfer", foreign_key: "inflow_transaction_id", dependent: :destroy
|
||||
has_one :rejected_transfer_as_outflow, class_name: "RejectedTransfer", foreign_key: "outflow_transaction_id", dependent: :destroy
|
||||
end
|
||||
|
||||
def transfer
|
||||
transfer_as_inflow || transfer_as_outflow
|
||||
end
|
||||
|
||||
def transfer?
|
||||
transfer.present?
|
||||
end
|
||||
|
||||
def transfer_match_candidates
|
||||
candidates_scope = if self.entry.amount.negative?
|
||||
family_matches_scope.where("inflow_candidates.entryable_id = ?", self.id)
|
||||
else
|
||||
family_matches_scope.where("outflow_candidates.entryable_id = ?", self.id)
|
||||
end
|
||||
|
||||
candidates_scope.map do |match|
|
||||
Transfer.new(
|
||||
inflow_transaction_id: match.inflow_transaction_id,
|
||||
outflow_transaction_id: match.outflow_transaction_id,
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
def family_matches_scope
|
||||
self.entry.account.family.transfer_match_candidates
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue