Current sync
This commit is contained in:
@@ -1,4 +1,25 @@
|
||||
class MoneyMove < ApplicationRecord
|
||||
belongs_to :from_homie, class_name: 'Homie'
|
||||
belongs_to :to_homie, class_name: 'Homie'
|
||||
belongs_to :homie
|
||||
|
||||
def create_move(params)
|
||||
common_params = { description: params[:description] }
|
||||
|
||||
move_from = MoneyMove.new(
|
||||
common_params + {
|
||||
homie_id: params[:from_homie_id],
|
||||
amount: -BigDecimal.new(params[:amount])
|
||||
}
|
||||
)
|
||||
move_to = MoneyMove.new(
|
||||
common_params + {
|
||||
homie_id: params[:from_homie_id],
|
||||
amount: BigDecimal.new(params[:amount])
|
||||
}
|
||||
)
|
||||
|
||||
MoneyMove.transaction do
|
||||
move_from.save!
|
||||
move_to.save!
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user