1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2025-02-20 14:54:15 +01:00

(bug) unable to credit wallet amount

This commit is contained in:
Du Peng 2022-12-12 16:25:29 +01:00
parent 766c08a302
commit 3224daf791
2 changed files with 3 additions and 3 deletions

View File

@ -23,7 +23,7 @@ class API::WalletController < API::ApiController
@wallet = Wallet.find(credit_params[:id])
authorize @wallet
service = WalletService.new(user: current_user, wallet: @wallet)
transaction = service.credit(credit_params[:amount])
transaction = service.credit(credit_params[:amount].to_f)
if transaction
service.create_avoir(transaction, credit_params[:avoir_date], credit_params[:avoir_description]) if credit_params[:avoir]
render :show

View File

@ -15,7 +15,7 @@ class Wallet < ApplicationRecord
def credit(amount)
if amount.is_a?(Numeric) && amount >= 0
self.amount += amount
self.amount = (BigDecimal(self.amount.to_s) + BigDecimal(amount.to_s)).to_f
return save
end
false
@ -23,7 +23,7 @@ class Wallet < ApplicationRecord
def debit(amount)
if amount.is_a?(Numeric) && amount >= 0
self.amount -= amount
self.amount = (BigDecimal(self.amount.to_s) - BigDecimal(amount.to_s)).to_f
return save
end
false