mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2025-02-21 15:54:22 +01:00
(bug) unable to credit wallet amount
This commit is contained in:
parent
766c08a302
commit
3224daf791
@ -23,7 +23,7 @@ class API::WalletController < API::ApiController
|
|||||||
@wallet = Wallet.find(credit_params[:id])
|
@wallet = Wallet.find(credit_params[:id])
|
||||||
authorize @wallet
|
authorize @wallet
|
||||||
service = WalletService.new(user: current_user, wallet: @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
|
if transaction
|
||||||
service.create_avoir(transaction, credit_params[:avoir_date], credit_params[:avoir_description]) if credit_params[:avoir]
|
service.create_avoir(transaction, credit_params[:avoir_date], credit_params[:avoir_description]) if credit_params[:avoir]
|
||||||
render :show
|
render :show
|
||||||
|
@ -15,7 +15,7 @@ class Wallet < ApplicationRecord
|
|||||||
|
|
||||||
def credit(amount)
|
def credit(amount)
|
||||||
if amount.is_a?(Numeric) && amount >= 0
|
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
|
return save
|
||||||
end
|
end
|
||||||
false
|
false
|
||||||
@ -23,7 +23,7 @@ class Wallet < ApplicationRecord
|
|||||||
|
|
||||||
def debit(amount)
|
def debit(amount)
|
||||||
if amount.is_a?(Numeric) && amount >= 0
|
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
|
return save
|
||||||
end
|
end
|
||||||
false
|
false
|
||||||
|
Loading…
x
Reference in New Issue
Block a user