Fix simple pricing computation: do not trunc.
MODIFY
src/integration/pricing/simple-pricing/SimplePricingIntegration.ts
src/integration/pricing/simple-pricing/SimplePricingIntegration.ts
@@ -23,6 +23,7 @@ export default class SimplePricingIntegration extends PricingIntegration<SimpleP
return this.computePrice(transaction, consumptionData);
}
+ // eslint-disable-next-line @typescript-eslint/require-await
private async computePrice(transaction: Transaction, consumptionData: Consumption): Promise<PricedConsumption> {
let amount: number;
let roundedAmount: number;
@@ -38,7 +39,7 @@ export default class SimplePricingIntegration extends PricingIntegration<SimpleP
amount: amount,
roundedAmount: roundedAmount,
currencyCode: this.settings.currency,
- cumulatedAmount: 0
+ cumulatedAmount: transaction.currentCumulatedPrice ? transaction.currentCumulatedPrice + amount : amount
};
return pricedConsumption;
}

MODIFY
src/server/ocpp/utils/OCPPUtils.ts
src/server/ocpp/utils/OCPPUtils.ts
@@ -215,11 +215,7 @@ export default class OCPPUtils {
consumption.roundedAmount = pricedConsumption.roundedAmount;
consumption.currencyCode = pricedConsumption.currencyCode;
consumption.pricingSource = pricedConsumption.pricingSource;
- if (pricedConsumption.cumulatedAmount) {
consumption.cumulatedAmount = pricedConsumption.cumulatedAmount;
- } else {
- consumption.cumulatedAmount = Utils.truncTo(transaction.currentCumulatedPrice + consumption.amount, 3);
- }
transaction.currentCumulatedPrice = consumption.cumulatedAmount;
}
break;
@@ -233,11 +229,7 @@ export default class OCPPUtils {
consumption.roundedAmount = pricedConsumption.roundedAmount;
consumption.currencyCode = pricedConsumption.currencyCode;
consumption.pricingSource = pricedConsumption.pricingSource;
- if (pricedConsumption.cumulatedAmount) {
consumption.cumulatedAmount = pricedConsumption.cumulatedAmount;
- } else {
- consumption.cumulatedAmount = Utils.truncTo(transaction.currentCumulatedPrice + consumption.amount, 3);
- }
transaction.currentCumulatedPrice = consumption.cumulatedAmount;
// Update Transaction
if (!transaction.stop) {

MODIFY
src/utils/Utils.ts
src/utils/Utils.ts
@@ -475,11 +475,11 @@ export default class Utils {
}
public static computeSimplePrice(pricePerkWh: number, consumptionWh: number): number {
- return Utils.truncTo(pricePerkWh * (consumptionWh / 1000), 6);
+ return Utils.roundTo(pricePerkWh * (consumptionWh / 1000), 6);
}
public static computeSimpleRoundedPrice(pricePerkWh: number, consumptionWh: number): number {
- return Utils.truncTo(pricePerkWh * (consumptionWh / 1000), 2);
+ return Utils.roundTo(pricePerkWh * (consumptionWh / 1000), 2);
}
public static convertUserToObjectID(user: User | UserToken | string): ObjectID | null {

Fix simple pricing computation: do not trunc.