Remove total cost in CDR
MODIFY
src/client/ocpi/CpoOCPIClient.ts
src/client/ocpi/CpoOCPIClient.ts
@@ -145,8 +145,8 @@ export default class CpoOCPIClient extends OCPIClient {
// Build payload
const payload: OCPILocationReference =
{
- 'location_id': siteID,
- 'evse_uids': [OCPIUtils.buildEvseUID(chargingStation)]
+ location_id: siteID,
+ evse_uids: [OCPIUtils.buildEvseUID(chargingStation)]
};
// Log
Logging.logDebug({
@@ -160,7 +160,7 @@ export default class CpoOCPIClient extends OCPIClient {
const response = await this.axiosInstance.post(tokensUrl, payload,
{
headers: {
- Authorization: `Token ${this.ocpiEndpoint.token}`,
+ 'Authorization': `Token ${this.ocpiEndpoint.token}`,
'Content-Type': 'application/json'
},
});
@@ -215,18 +215,20 @@ export default class CpoOCPIClient extends OCPIClient {
// Build payload
const ocpiSession: OCPISession =
{
- 'id': authorizationId,
- 'start_datetime': transaction.timestamp,
- 'kwh': 0,
- 'total_cost': transaction.currentCumulatedPrice,
- 'auth_method': OCPIAuthMethod.AUTH_REQUEST,
- 'auth_id': ocpiToken.auth_id,
- 'location': ocpiLocation,
- 'currency': this.settings.currency,
- 'status': OCPISessionStatus.PENDING,
- 'authorization_id': authorizationId,
- 'last_updated': transaction.timestamp
+ id: authorizationId,
+ start_datetime: transaction.timestamp,
+ kwh: 0,
+ auth_method: OCPIAuthMethod.AUTH_REQUEST,
+ auth_id: ocpiToken.auth_id,
+ location: ocpiLocation,
+ currency: this.settings.currency,
+ status: OCPISessionStatus.PENDING,
+ authorization_id: authorizationId,
+ last_updated: transaction.timestamp
};
+ if (transaction.currentCumulatedPrice > 0) {
+ ocpiSession.total_cost = transaction.currentCumulatedPrice;
+ }
// Log
Logging.logDebug({
tenantID: this.tenant.id,
@@ -269,7 +271,9 @@ export default class CpoOCPIClient extends OCPIClient {
const sessionsUrl = `${this.getEndpointUrl('sessions', ServerAction.OCPI_PUSH_SESSIONS)}/${this.getLocalCountryCode(ServerAction.OCPI_PUSH_SESSIONS)}/${this.getLocalPartyID(ServerAction.OCPI_PUSH_SESSIONS)}/${transaction.ocpiData.session.id}`;
transaction.ocpiData.session.kwh = transaction.currentTotalConsumptionWh / 1000;
transaction.ocpiData.session.last_updated = transaction.currentTimestamp;
+ if (transaction.currentCumulatedPrice > 0) {
transaction.ocpiData.session.total_cost = transaction.currentCumulatedPrice;
+ }
transaction.ocpiData.session.currency = this.settings.currency;
transaction.ocpiData.session.status = OCPISessionStatus.ACTIVE;
transaction.ocpiData.session.charging_periods = await OCPIMapping.buildChargingPeriods(this.tenant.id, transaction);
@@ -277,11 +281,13 @@ export default class CpoOCPIClient extends OCPIClient {
const patchBody: Partial<OCPISession> = {
kwh: transaction.ocpiData.session.kwh,
last_updated: transaction.ocpiData.session.last_updated,
- total_cost: transaction.ocpiData.session.total_cost,
currency: transaction.ocpiData.session.currency,
status: transaction.ocpiData.session.status,
charging_periods: transaction.ocpiData.session.charging_periods
};
+ if (transaction.currentCumulatedPrice > 0) {
+ patchBody.total_cost = transaction.ocpiData.session.total_cost;
+ }
// Log
Logging.logDebug({
tenantID: this.tenant.id,
@@ -327,7 +333,9 @@ export default class CpoOCPIClient extends OCPIClient {
// Get tokens endpoint url
const tokensUrl = `${this.getEndpointUrl('sessions', ServerAction.OCPI_PUSH_SESSIONS)}/${this.getLocalCountryCode(ServerAction.OCPI_PUSH_SESSIONS)}/${this.getLocalPartyID(ServerAction.OCPI_PUSH_SESSIONS)}/${transaction.ocpiData.session.id}`;
transaction.ocpiData.session.kwh = transaction.stop.totalConsumptionWh / 1000;
+ if (transaction.stop.roundedPrice > 0) {
transaction.ocpiData.session.total_cost = transaction.stop.roundedPrice;
+ }
transaction.ocpiData.session.end_datetime = transaction.stop.timestamp;
transaction.ocpiData.session.last_updated = transaction.stop.timestamp;
transaction.ocpiData.session.status = OCPISessionStatus.COMPLETED;
@@ -383,7 +391,6 @@ export default class CpoOCPIClient extends OCPIClient {
total_parking_time: transaction.stop.totalInactivitySecs,
total_time: transaction.stop.totalDurationSecs / 3600, // In hours
total_energy: transaction.stop.totalConsumptionWh / 1000,
- total_cost: transaction.stop.roundedPrice > 0 ? transaction.stop.roundedPrice : 0,
currency: this.settings.currency,
auth_id: transaction.ocpiData.session.auth_id,
authorization_id: transaction.ocpiData.session.authorization_id,
@@ -392,6 +399,9 @@ export default class CpoOCPIClient extends OCPIClient {
charging_periods: await OCPIMapping.buildChargingPeriods(this.tenant.id, transaction),
last_updated: transaction.stop.timestamp
};
+ if (transaction.stop.roundedPrice > 0) {
+ transaction.ocpiData.cdr.total_cost = transaction.stop.roundedPrice;
+ }
// Log
Logging.logDebug({
tenantID: this.tenant.id,
@@ -404,7 +414,7 @@ export default class CpoOCPIClient extends OCPIClient {
const response = await this.axiosInstance.post(cdrsUrl, transaction.ocpiData.cdr,
{
headers: {
- Authorization: `Token ${this.ocpiEndpoint.token}`,
+ 'Authorization': `Token ${this.ocpiEndpoint.token}`,
'Content-Type': 'application/json'
},
});
@@ -514,7 +524,7 @@ export default class CpoOCPIClient extends OCPIClient {
await this.axiosInstance.patch(fullUrl, payload,
{
headers: {
- Authorization: `Token ${this.ocpiEndpoint.token}`,
+ 'Authorization': `Token ${this.ocpiEndpoint.token}`,
'Content-Type': 'application/json'
},
});
@@ -541,7 +551,7 @@ export default class CpoOCPIClient extends OCPIClient {
const response = await this.axiosInstance.get(`${cdrsUrl}/${transaction.ocpiData.cdr.id}`,
{
headers: {
- Authorization: `Token ${this.ocpiEndpoint.token}`
+ 'Authorization': `Token ${this.ocpiEndpoint.token}`
},
});
Logging.logDebug({
@@ -555,7 +565,7 @@ export default class CpoOCPIClient extends OCPIClient {
await this.axiosInstance.post(cdrsUrl, transaction.ocpiData.cdr,
{
headers: {
- Authorization: `Token ${this.ocpiEndpoint.token}`,
+ 'Authorization': `Token ${this.ocpiEndpoint.token}`,
'Content-Type': 'application/json'
},
});
@@ -595,7 +605,7 @@ export default class CpoOCPIClient extends OCPIClient {
const response = await this.axiosInstance.get(sessionsUrl,
{
headers: {
- Authorization: `Token ${this.ocpiEndpoint.token}`
+ 'Authorization': `Token ${this.ocpiEndpoint.token}`
},
});
Logging.logDebug({
@@ -712,7 +722,7 @@ export default class CpoOCPIClient extends OCPIClient {
const response = await this.axiosInstance.get(locationUrl,
{
headers: {
- Authorization: `Token ${this.ocpiEndpoint.token}`
+ 'Authorization': `Token ${this.ocpiEndpoint.token}`
},
});
Logging.logDebug({
@@ -744,14 +754,12 @@ export default class CpoOCPIClient extends OCPIClient {
objectIDsInFailure: [],
objectIDsInSuccess: []
};
-
// Define get option
const options = {
'addChargeBoxID': true,
countryID: this.getLocalCountryCode(ServerAction.OCPI_CHECK_LOCATIONS),
partyID: this.getLocalPartyID(ServerAction.OCPI_CHECK_LOCATIONS)
};
-
// Get all EVSEs from all locations
const locations = await OCPIMapping.getAllLocations(this.tenant, 0, 0, options);
// Loop through locations
@@ -775,7 +783,6 @@ export default class CpoOCPIClient extends OCPIClient {
}
result.total++;
}
-
return result;
}
@@ -794,7 +801,7 @@ export default class CpoOCPIClient extends OCPIClient {
};
// Define get option
const options = {
- 'addChargeBoxID': true,
+ addChargeBoxID: true,
countryID: this.getLocalCountryCode(ServerAction.OCPI_PATCH_STATUS),
partyID: this.getLocalPartyID(ServerAction.OCPI_PATCH_STATUS)
};
@@ -847,8 +854,8 @@ export default class CpoOCPIClient extends OCPIClient {
NotificationHandler.sendOCPIPatchChargingStationsStatusesError(
this.tenant.id,
{
- 'location': location.name,
- 'evseDashboardURL': Utils.buildEvseURL((await TenantStorage.getTenant(this.tenant.id)).subdomain),
+ location: location.name,
+ evseDashboardURL: Utils.buildEvseURL((await TenantStorage.getTenant(this.tenant.id)).subdomain),
}
);
}
@@ -881,19 +888,19 @@ export default class CpoOCPIClient extends OCPIClient {
// Set result
if (sendResult) {
this.ocpiEndpoint.lastPatchJobResult = {
- 'successNbr': sendResult.success,
- 'failureNbr': sendResult.failure,
- 'totalNbr': sendResult.total,
- 'chargeBoxIDsInFailure': _.uniq(sendResult.chargeBoxIDsInFailure),
- 'chargeBoxIDsInSuccess': _.uniq(sendResult.chargeBoxIDsInSuccess)
+ successNbr: sendResult.success,
+ failureNbr: sendResult.failure,
+ totalNbr: sendResult.total,
+ chargeBoxIDsInFailure: _.uniq(sendResult.chargeBoxIDsInFailure),
+ chargeBoxIDsInSuccess: _.uniq(sendResult.chargeBoxIDsInSuccess)
};
} else {
this.ocpiEndpoint.lastPatchJobResult = {
- 'successNbr': 0,
- 'failureNbr': 0,
- 'totalNbr': 0,
- 'chargeBoxIDsInFailure': [],
- 'chargeBoxIDsInSuccess': []
+ successNbr: 0,
+ failureNbr: 0,
+ totalNbr: 0,
+ chargeBoxIDsInFailure: [],
+ chargeBoxIDsInSuccess: []
};
}
// Save

MODIFY
src/server/ocpi/ocpi-services-impl/ocpi-2.1.1/OCPISessionsService.ts
src/server/ocpi/ocpi-services-impl/ocpi-2.1.1/OCPISessionsService.ts
@@ -159,7 +159,6 @@ export default class OCPISessionsService {
userID: transaction.userID
};
}
-
await TransactionStorage.saveTransaction(tenantId, transaction);
await this.updateConnector(tenantId, transaction);
}
@@ -175,7 +174,6 @@ export default class OCPISessionsService {
ocpiError: OCPIStatusCode.CODE_2001_INVALID_PARAMETER_ERROR
});
}
-
const transaction: Transaction = await TransactionStorage.getOCPITransaction(tenantId, cdr.id);
if (!transaction) {
throw new AppError({
@@ -187,7 +185,6 @@ export default class OCPISessionsService {
ocpiError: OCPIStatusCode.CODE_2001_INVALID_PARAMETER_ERROR
});
}
-
if (!cdr.total_cost) {
cdr.total_cost = 0;
}
@@ -200,7 +197,6 @@ export default class OCPISessionsService {
if (!cdr.total_parking_time) {
cdr.total_parking_time = 0;
}
-
transaction.priceUnit = cdr.currency;
transaction.price = cdr.total_cost;
transaction.roundedPrice = Utils.convertToFloat(cdr.total_cost.toFixed(2));
@@ -222,11 +218,9 @@ export default class OCPISessionsService {
inactivityStatus: transaction.currentInactivityStatus,
userID: transaction.userID
};
-
if (!transaction.ocpiData) {
transaction.ocpiData = {};
}
-
transaction.ocpiData.cdr = cdr;
await TransactionStorage.saveTransaction(tenantId, transaction);
await this.updateConnector(tenantId, transaction);

MODIFY
src/types/ocpi/OCPICdr.ts
src/types/ocpi/OCPICdr.ts
@@ -13,7 +13,7 @@ export interface OCPICdr {
meter_id?: string;
currency: string;
charging_periods: OCPIChargingPeriod[];
- total_cost: number;
+ total_cost?: number;
total_energy: number;
total_time: number;
total_parking_time?: number;

Remove total cost in CDR