mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
account ID fixes
This commit is contained in:
@@ -144,7 +144,7 @@ func (self *ApierV1) SetAccount(attr utils.AttrSetAccount, reply *string) error
|
||||
ub = bal
|
||||
} else { // Not found in db, create it here
|
||||
ub = &engine.Account{
|
||||
Id: accID,
|
||||
ID: accID,
|
||||
}
|
||||
}
|
||||
if len(attr.ActionPlanId) != 0 {
|
||||
@@ -395,7 +395,7 @@ func (self *ApierV1) modifyBalance(aType string, attr *AttrAddBalance, reply *st
|
||||
if _, err := self.AccountDb.GetAccount(accID); err != nil {
|
||||
// create account if not exists
|
||||
account := &engine.Account{
|
||||
Id: accID,
|
||||
ID: accID,
|
||||
}
|
||||
if err := self.AccountDb.SetAccount(account); err != nil {
|
||||
*reply = err.Error()
|
||||
@@ -487,7 +487,7 @@ func (self *ApierV1) SetBalance(attr *AttrSetBalance, reply *string) error {
|
||||
if _, err := self.AccountDb.GetAccount(accID); err != nil {
|
||||
// create account if not exists
|
||||
account := &engine.Account{
|
||||
Id: accID,
|
||||
ID: accID,
|
||||
}
|
||||
if err := self.AccountDb.SetAccount(account); err != nil {
|
||||
*reply = err.Error()
|
||||
|
||||
@@ -41,15 +41,15 @@ func TestSetAccounts(t *testing.T) {
|
||||
cgrTenant := "cgrates.org"
|
||||
iscTenant := "itsyscom.com"
|
||||
b10 := &engine.Balance{Value: 10, Weight: 10}
|
||||
cgrAcnt1 := &engine.Account{Id: utils.ConcatenatedKey(cgrTenant, "account1"),
|
||||
cgrAcnt1 := &engine.Account{ID: utils.ConcatenatedKey(cgrTenant, "account1"),
|
||||
BalanceMap: map[string]engine.BalanceChain{utils.MONETARY + utils.OUT: engine.BalanceChain{b10}}}
|
||||
cgrAcnt2 := &engine.Account{Id: utils.ConcatenatedKey(cgrTenant, "account2"),
|
||||
cgrAcnt2 := &engine.Account{ID: utils.ConcatenatedKey(cgrTenant, "account2"),
|
||||
BalanceMap: map[string]engine.BalanceChain{utils.MONETARY + utils.OUT: engine.BalanceChain{b10}}}
|
||||
cgrAcnt3 := &engine.Account{Id: utils.ConcatenatedKey(cgrTenant, "account3"),
|
||||
cgrAcnt3 := &engine.Account{ID: utils.ConcatenatedKey(cgrTenant, "account3"),
|
||||
BalanceMap: map[string]engine.BalanceChain{utils.MONETARY + utils.OUT: engine.BalanceChain{b10}}}
|
||||
iscAcnt1 := &engine.Account{Id: utils.ConcatenatedKey(iscTenant, "account1"),
|
||||
iscAcnt1 := &engine.Account{ID: utils.ConcatenatedKey(iscTenant, "account1"),
|
||||
BalanceMap: map[string]engine.BalanceChain{utils.MONETARY + utils.OUT: engine.BalanceChain{b10}}}
|
||||
iscAcnt2 := &engine.Account{Id: utils.ConcatenatedKey(iscTenant, "account2"),
|
||||
iscAcnt2 := &engine.Account{ID: utils.ConcatenatedKey(iscTenant, "account2"),
|
||||
BalanceMap: map[string]engine.BalanceChain{utils.MONETARY + utils.OUT: engine.BalanceChain{b10}}}
|
||||
for _, account := range []*engine.Account{cgrAcnt1, cgrAcnt2, cgrAcnt3, iscAcnt1, iscAcnt2} {
|
||||
if err := apierAcntsAcntStorage.SetAccount(account); err != nil {
|
||||
|
||||
@@ -102,7 +102,7 @@ func (self *ApierV2) SetAccount(attr AttrSetAccount, reply *string) error {
|
||||
ub = bal
|
||||
} else { // Not found in db, create it here
|
||||
ub = &engine.Account{
|
||||
Id: accID,
|
||||
ID: accID,
|
||||
}
|
||||
}
|
||||
if attr.ActionPlanIDs != nil {
|
||||
|
||||
@@ -173,7 +173,7 @@ func (mig MigratorRC8) migrateAccounts() error {
|
||||
}
|
||||
// transfer data into new structurse
|
||||
newAcc := &engine.Account{
|
||||
Id: oldAcc.Id,
|
||||
ID: oldAcc.Id,
|
||||
BalanceMap: make(map[string]engine.BalanceChain, len(oldAcc.BalanceMap)),
|
||||
UnitCounters: make(engine.UnitCounters, len(oldAcc.UnitCounters)),
|
||||
ActionTriggers: make(engine.ActionTriggers, len(oldAcc.ActionTriggers)),
|
||||
@@ -181,12 +181,12 @@ func (mig MigratorRC8) migrateAccounts() error {
|
||||
Disabled: oldAcc.Disabled,
|
||||
}
|
||||
// fix id
|
||||
idElements := strings.Split(newAcc.Id, utils.CONCATENATED_KEY_SEP)
|
||||
idElements := strings.Split(newAcc.ID, utils.CONCATENATED_KEY_SEP)
|
||||
if len(idElements) != 3 {
|
||||
log.Printf("Malformed account ID %s", oldAcc.Id)
|
||||
continue
|
||||
}
|
||||
newAcc.Id = fmt.Sprintf("%s:%s", idElements[1], idElements[2])
|
||||
newAcc.ID = fmt.Sprintf("%s:%s", idElements[1], idElements[2])
|
||||
// balances
|
||||
balanceErr := false
|
||||
for oldBalKey, oldBalChain := range oldAcc.BalanceMap {
|
||||
@@ -344,7 +344,7 @@ func (mig MigratorRC8) migrateAccounts() error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err := mig.db.Cmd("SET", utils.ACCOUNT_PREFIX+newAcc.Id, result).Err; err != nil {
|
||||
if err := mig.db.Cmd("SET", utils.ACCOUNT_PREFIX+newAcc.ID, result).Err; err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,7 +63,7 @@ ENABLE_ACNT,*enable_account,,,,,,,,,,,,,,false,false,10`
|
||||
csvr.WriteToDatabase(false, false)
|
||||
ratingDbAcntActs.CacheRatingAll()
|
||||
acntDbAcntActs.CacheAccountingAll()
|
||||
expectAcnt := &engine.Account{Id: "cgrates.org:1"}
|
||||
expectAcnt := &engine.Account{ID: "cgrates.org:1"}
|
||||
if acnt, err := acntDbAcntActs.GetAccount("cgrates.org:1"); err != nil {
|
||||
t.Error(err)
|
||||
} else if acnt == nil {
|
||||
@@ -82,7 +82,7 @@ func TestAcntActsDisableAcnt(t *testing.T) {
|
||||
if err := at.Execute(); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
expectAcnt := &engine.Account{Id: "cgrates.org:1", Disabled: true}
|
||||
expectAcnt := &engine.Account{ID: "cgrates.org:1", Disabled: true}
|
||||
if acnt, err := acntDbAcntActs.GetAccount(acnt1Tag); err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(expectAcnt, acnt) {
|
||||
@@ -99,7 +99,7 @@ func TestAcntActsEnableAcnt(t *testing.T) {
|
||||
if err := at.Execute(); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
expectAcnt := &engine.Account{Id: "cgrates.org:1", Disabled: false}
|
||||
expectAcnt := &engine.Account{ID: "cgrates.org:1", Disabled: false}
|
||||
if acnt, err := acntDbAcntActs.GetAccount(acnt1Tag); err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(expectAcnt, acnt) {
|
||||
|
||||
@@ -1164,9 +1164,9 @@ func TestTutLocalSetAccount(t *testing.T) {
|
||||
t.Errorf("Accounts received: %+v", acnts)
|
||||
} else {
|
||||
acnt := acnts[0]
|
||||
dta, _ := utils.NewTAFromAccountKey(acnt.Id)
|
||||
dta, _ := utils.NewTAFromAccountKey(acnt.ID)
|
||||
if dta.Tenant != attrs.Tenant || dta.Account != attrs.Account {
|
||||
t.Error("Unexpected account id received: ", acnt.Id)
|
||||
t.Error("Unexpected account id received: ", acnt.ID)
|
||||
}
|
||||
if balances := acnt.BalanceMap["*monetary"]; len(balances) != 1 {
|
||||
t.Errorf("Unexpected balances found: %+v", balances)
|
||||
@@ -1194,9 +1194,9 @@ func TestTutLocalSetAccount(t *testing.T) {
|
||||
t.Errorf("Accounts received: %+v", acnts)
|
||||
} else {
|
||||
acnt := acnts[0]
|
||||
dta, _ := utils.NewTAFromAccountKey(acnt.Id)
|
||||
dta, _ := utils.NewTAFromAccountKey(acnt.ID)
|
||||
if dta.Tenant != attrs.Tenant || dta.Account != attrs.Account {
|
||||
t.Error("Unexpected account id received: ", acnt.Id)
|
||||
t.Error("Unexpected account id received: ", acnt.ID)
|
||||
}
|
||||
if balances := acnt.BalanceMap["*monetary"]; len(balances) != 1 {
|
||||
t.Errorf("Unexpected balances found: %+v", balances)
|
||||
@@ -1225,9 +1225,9 @@ func TestTutLocalSetAccount(t *testing.T) {
|
||||
t.Errorf("Accounts received: %+v", acnts)
|
||||
} else {
|
||||
acnt := acnts[0]
|
||||
dta, _ := utils.NewTAFromAccountKey(acnt.Id)
|
||||
dta, _ := utils.NewTAFromAccountKey(acnt.ID)
|
||||
if dta.Tenant != attrs.Tenant || dta.Account != attrs.Account {
|
||||
t.Error("Unexpected account id received: ", acnt.Id)
|
||||
t.Error("Unexpected account id received: ", acnt.ID)
|
||||
}
|
||||
if balances := acnt.BalanceMap["*monetary"]; len(balances) != 1 {
|
||||
t.Errorf("Unexpected balances found: %+v", balances)
|
||||
|
||||
Reference in New Issue
Block a user