EventCharges - include syncIDs inside Merge

This commit is contained in:
DanB
2021-04-01 20:58:36 +02:00
parent 1f485d7cf9
commit bb15ed3d54
2 changed files with 2 additions and 6 deletions

View File

@@ -19,7 +19,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
package utils
import (
"fmt"
"reflect"
"regexp"
"strings"
@@ -378,13 +377,10 @@ func TestAppend2(t *testing.T) {
dn.Type = NMMapType
dn.Slice = nil
dn.Map = map[string]*DataNode{}
dnExpect := NewDataNode(testPath)
if _, err := dn.Append(testPath, val1); err != nil {
t.Error(err)
}
fmt.Println(ToJSON(dn.Map["0"]))
fmt.Println(ToJSON(dnExpect))
///
dn.Type = NMSliceType

View File

@@ -47,6 +47,7 @@ type EventCharges struct {
// Merge will merge the event charges into existing
func (ec *EventCharges) Merge(eCs ...*EventCharges) {
ec.syncIDs(eCs...) // so we can compare properly
for _, nEc := range eCs {
if ec.Abstracts != nil {
ec.Abstracts = &Decimal{SumBig(ec.Abstracts.Big, nEc.Abstracts.Big)}
@@ -63,7 +64,7 @@ func (ec *EventCharges) Merge(eCs ...*EventCharges) {
}
// SyncIDs will repopulate Accounting, UnitFactors and Rating IDs if they equal the references in ec
func (ec *EventCharges) SyncIDs(eCs ...*EventCharges) {
func (ec *EventCharges) syncIDs(eCs ...*EventCharges) {
for _, nEc := range eCs {
for _, cIl := range nEc.ChargingIntervals {
for _, cIcrm := range cIl.Increments {
@@ -120,7 +121,6 @@ func (ec *EventCharges) AppendChargingIntervals(cIls ...*ChargingInterval) {
ec.ChargingIntervals = []*ChargingInterval{cIl}
continue
}
if ec.ChargingIntervals[len(ec.ChargingIntervals)-1].CompressEquals(cIl) {
ec.ChargingIntervals[len(ec.ChargingIntervals)-1].CompressFactor += 1
continue