Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix salesOrder being overwritten and therefore creating wrong odoo records #70

Merged
merged 1 commit into from
Dec 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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