handle settling records for homie

This commit is contained in:
Bilal
2020-09-17 15:00:55 +03:00
parent 0e5682a9a0
commit f459052fcb
4 changed files with 38 additions and 0 deletions

View File

@@ -10,4 +10,18 @@ class Homie < ApplicationRecord
{ homie: homie, amount: total }
end
end
def settle
total = MoneyMove.where(homie_id: id).all.sum(:amount)
all_money_moves = MoneyMove.where(homie_id: id).all
transaction do
all_money_moves.destroy_all
MoneyMove.create_settle_record(id, total)
end
true
rescue StandardError => e
false
end
end