Skip to content

Commit

Permalink
Merge pull request #70 from vshn/fix/sales_order
Browse files Browse the repository at this point in the history
Fix salesOrder being overwritten and therefore creating wrong odoo records
  • Loading branch information
TheBigLee authored Dec 22, 2023
2 parents a236353 + 7387074 commit 868cd23
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 13 deletions.
15 changes: 8 additions & 7 deletions pkg/cloudscale/objectstorage.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,15 +84,16 @@ func (o *ObjectStorage) GetMetrics(ctx context.Context, billingDate time.Time) (
continue
}
appuioManaged := true
if o.salesOrder == "" {
salesOrder := o.salesOrder
if salesOrder == "" {
appuioManaged = false
o.salesOrder, err = controlAPI.GetSalesOrder(ctx, o.controlApiClient, nsTenants[bd.Namespace])
salesOrder, err = controlAPI.GetSalesOrder(ctx, o.controlApiClient, nsTenants[bd.Namespace])
if err != nil {
logger.Error(err, "unable to sync bucket", "namespace", bd.Namespace)
continue
}
}
records, err := o.createOdooRecord(bucketMetricsData, bd, appuioManaged)
records, err := o.createOdooRecord(bucketMetricsData, bd, appuioManaged, salesOrder)
if err != nil {
logger.Error(err, "unable to create Odoo Record", "namespace", bd.Namespace)
continue
Expand All @@ -104,7 +105,7 @@ func (o *ObjectStorage) GetMetrics(ctx context.Context, billingDate time.Time) (
return allRecords, nil
}

func (o *ObjectStorage) createOdooRecord(bucketMetricsData cloudscale.BucketMetricsData, b BucketDetail, appuioManaged bool) ([]odoo.OdooMeteredBillingRecord, error) {
func (o *ObjectStorage) createOdooRecord(bucketMetricsData cloudscale.BucketMetricsData, b BucketDetail, appuioManaged bool, salesOrder string) ([]odoo.OdooMeteredBillingRecord, error) {
if len(bucketMetricsData.TimeSeries) != 1 {
return nil, fmt.Errorf("there must be exactly one metrics data point, found %d", len(bucketMetricsData.TimeSeries))
}
Expand Down Expand Up @@ -137,7 +138,7 @@ func (o *ObjectStorage) createOdooRecord(bucketMetricsData cloudscale.BucketMetr
InstanceID: instanceId,
ItemDescription: "AppCat Cloudscale ObjectStorage",
ItemGroupDescription: itemGroup,
SalesOrder: o.salesOrder,
SalesOrder: salesOrder,
UnitID: o.uomMapping[units[productIdStorage]],
ConsumedUnits: storageBytesValue,
TimeRange: odoo.TimeRange{
Expand All @@ -150,7 +151,7 @@ func (o *ObjectStorage) createOdooRecord(bucketMetricsData cloudscale.BucketMetr
InstanceID: instanceId,
ItemDescription: "AppCat Cloudscale ObjectStorage",
ItemGroupDescription: itemGroup,
SalesOrder: o.salesOrder,
SalesOrder: salesOrder,
UnitID: o.uomMapping[units[productIdTrafficOut]],
ConsumedUnits: trafficOutValue,
TimeRange: odoo.TimeRange{
Expand All @@ -163,7 +164,7 @@ func (o *ObjectStorage) createOdooRecord(bucketMetricsData cloudscale.BucketMetr
InstanceID: instanceId,
ItemDescription: "AppCat Cloudscale ObjectStorage",
ItemGroupDescription: itemGroup,
SalesOrder: o.salesOrder,
SalesOrder: salesOrder,
UnitID: o.uomMapping[units[productIdQueryRequests]],
ConsumedUnits: queryRequestsValue,
TimeRange: odoo.TimeRange{
Expand Down
7 changes: 4 additions & 3 deletions pkg/exoscale/dbaas.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,9 +209,10 @@ func (ds *DBaaS) AggregateDBaaS(ctx context.Context, exoscaleDBaaS []*egoscale.D

itemGroup := fmt.Sprintf("APPUiO Managed - Zone: %s / Namespace: %s", ds.clusterId, dbaasDetail.Namespace)
instanceId := fmt.Sprintf("%s/%s", dbaasDetail.Zone, dbaasDetail.DBName)
if ds.salesOrder == "" {
salesOrder := ds.salesOrder
if salesOrder == "" {
itemGroup = fmt.Sprintf("APPUiO Cloud - Zone: %s / Namespace: %s", ds.clusterId, dbaasDetail.Namespace)
ds.salesOrder, err = controlAPI.GetSalesOrder(ctx, ds.controlApiClient, dbaasDetail.Organization)
salesOrder, err = controlAPI.GetSalesOrder(ctx, ds.controlApiClient, dbaasDetail.Organization)
if err != nil {
logger.Error(err, "Unable to sync DBaaS, cannot get salesOrder", "namespace", dbaasDetail.Namespace)
continue
Expand All @@ -223,7 +224,7 @@ func (ds *DBaaS) AggregateDBaaS(ctx context.Context, exoscaleDBaaS []*egoscale.D
InstanceID: instanceId,
ItemDescription: "Exoscale DBaaS " + dbaasTypes[*dbaasUsage.Type],
ItemGroupDescription: itemGroup,
SalesOrder: ds.salesOrder,
SalesOrder: salesOrder,
UnitID: ds.uomMapping[odoo.InstanceHour],
ConsumedUnits: 1,
TimeRange: odoo.TimeRange{
Expand Down
7 changes: 4 additions & 3 deletions pkg/exoscale/objectstorage.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,10 @@ func (o *ObjectStorage) getOdooMeteredBillingRecords(ctx context.Context, sosBuc

itemGroup := fmt.Sprintf("APPUiO Managed - Zone: %s / Namespace: %s", o.clusterId, bucketDetail.Namespace)
instanceId := fmt.Sprintf("%s/%s", bucketDetail.Zone, bucketDetail.BucketName)
if o.salesOrder == "" {
salesOrder := o.salesOrder
if salesOrder == "" {
itemGroup = fmt.Sprintf("APPUiO Cloud - Zone: %s / Namespace: %s", o.clusterId, bucketDetail.Namespace)
o.salesOrder, err = controlAPI.GetSalesOrder(ctx, o.controlApiClient, bucketDetail.Organization)
salesOrder, err = controlAPI.GetSalesOrder(ctx, o.controlApiClient, bucketDetail.Organization)
if err != nil {
logger.Error(err, "unable to sync bucket", "namespace", bucketDetail.Namespace)
continue
Expand All @@ -126,7 +127,7 @@ func (o *ObjectStorage) getOdooMeteredBillingRecords(ctx context.Context, sosBuc
InstanceID: instanceId,
ItemDescription: "AppCat Exoscale ObjectStorage",
ItemGroupDescription: itemGroup,
SalesOrder: o.salesOrder,
SalesOrder: salesOrder,
UnitID: o.uomMapping[odoo.GBDay],
ConsumedUnits: value,
TimeRange: odoo.TimeRange{
Expand Down

0 comments on commit 868cd23

Please sign in to comment.