mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-21 15:18:44 +05:00
Adding account info in responder.RefundIncrements, update accountSummary after refund
This commit is contained in:
@@ -899,7 +899,8 @@ func (cd *CallDescriptor) MaxDebit() (cc *CallCost, err error) {
|
||||
}
|
||||
|
||||
// refundIncrements has no locks
|
||||
func (cd *CallDescriptor) refundIncrements() (err error) {
|
||||
// returns the updated account referenced by the CallDescriptor
|
||||
func (cd *CallDescriptor) refundIncrements() (acnt *Account, err error) {
|
||||
accountsCache := make(map[string]*Account)
|
||||
for _, increment := range cd.Increments {
|
||||
account, found := accountsCache[increment.BalanceInfo.AccountID]
|
||||
@@ -935,11 +936,12 @@ func (cd *CallDescriptor) refundIncrements() (err error) {
|
||||
account.countUnits(-increment.Cost, utils.MONETARY, cc, balance)
|
||||
}
|
||||
}
|
||||
acnt = accountsCache[utils.ConcatenatedKey(cd.Tenant, cd.Account)]
|
||||
return
|
||||
|
||||
}
|
||||
|
||||
func (cd *CallDescriptor) RefundIncrements() (err error) {
|
||||
func (cd *CallDescriptor) RefundIncrements() (acnt *Account, err error) {
|
||||
// get account list for locking
|
||||
// all must be locked in order to use cache
|
||||
cd.Increments.Decompress()
|
||||
@@ -953,7 +955,7 @@ func (cd *CallDescriptor) RefundIncrements() (err error) {
|
||||
}
|
||||
}
|
||||
_, err = guardian.Guardian.Guard(func() (iface interface{}, err error) {
|
||||
err = cd.refundIncrements()
|
||||
acnt, err = cd.refundIncrements()
|
||||
return
|
||||
}, 0, accMap.Slice()...)
|
||||
return
|
||||
|
||||
@@ -197,11 +197,11 @@ func (rs *Responder) MaxDebit(arg *CallDescriptor, reply *CallCost) (err error)
|
||||
return
|
||||
}
|
||||
|
||||
func (rs *Responder) RefundIncrements(arg *CallDescriptor, reply *float64) (err error) {
|
||||
func (rs *Responder) RefundIncrements(arg *CallDescriptor, reply *Account) (err error) {
|
||||
cacheKey := utils.REFUND_INCR_CACHE_PREFIX + arg.CgrID + arg.RunID
|
||||
if item, err := rs.getCache().Get(cacheKey); err == nil && item != nil {
|
||||
if item.Value != nil {
|
||||
*reply = *(item.Value.(*float64))
|
||||
*reply = *(item.Value.(*Account))
|
||||
}
|
||||
return item.Err
|
||||
}
|
||||
@@ -229,9 +229,20 @@ func (rs *Responder) RefundIncrements(arg *CallDescriptor, reply *float64) (err
|
||||
return err
|
||||
}
|
||||
if !rs.usageAllowed(arg.TOR, arg.GetDuration()) {
|
||||
return utils.ErrMaxUsageExceeded
|
||||
err = utils.ErrMaxUsageExceeded
|
||||
rs.getCache().Cache(cacheKey, &utils.ResponseCacheItem{
|
||||
Err: err,
|
||||
})
|
||||
return
|
||||
}
|
||||
if acnt, err := arg.RefundIncrements(); err != nil {
|
||||
rs.getCache().Cache(cacheKey, &utils.ResponseCacheItem{
|
||||
Err: err,
|
||||
})
|
||||
return err
|
||||
} else if acnt != nil {
|
||||
*reply = *acnt
|
||||
}
|
||||
err = arg.RefundIncrements()
|
||||
rs.getCache().Cache(cacheKey, &utils.ResponseCacheItem{
|
||||
Value: reply,
|
||||
Err: err,
|
||||
|
||||
Reference in New Issue
Block a user