pricing - fix bug - absorb step consumption
MODIFY
src/integration/pricing/ConsumptionPricer.ts
src/integration/pricing/ConsumptionPricer.ts
@@ -128,7 +128,7 @@ export default class ConsumptionPricer {
const nbSteps = delta.divToInt(dimensionToPrice.stepSize).toNumber();
if (nbSteps > 0) {
pricedData = this.priceConsumptionStep(dimensionToPrice, nbSteps);
- this.absorbConsumption();
+ this.absorbStepConsumption(pricedData);
}
}
} else if (consumptionWh > 0) {
@@ -159,6 +159,13 @@ export default class ConsumptionPricer {
this.pricingModel.pricerContext.lastAbsorbedConsumption = this.consumptionData.cumulatedConsumptionWh;
}
+ private absorbStepConsumption(pricedData?: PricedDimensionData) {
+ // Mark the consumed energy as already priced - to avoid pricing it twice
+ // Make sure to consider the stepSize to avoid absorbing something not yet priced
+ const consumption = Utils.createDecimal(this.consumptionData.cumulatedConsumptionWh).div(pricedData.stepSize).trunc().mul(pricedData.stepSize).toNumber();
+ this.pricingModel.pricerContext.lastAbsorbedConsumption = consumption;
+ }
+
private priceChargingTimeConsumption(): PricedDimensionData {
const activePricingDefinition = this.getActiveDefinition4Dimension(this.actualPricingDefinitions, DimensionType.CHARGING_TIME);
if (activePricingDefinition) {

MODIFY
test/api/BillingTest.ts
test/api/BillingTest.ts
@@ -1250,7 +1250,7 @@ describe('Billing Service', function() {
const transactionID = await testData.generateTransaction(testData.userContext);
assert(transactionID, 'transactionID should not be null');
// Check that we have a new invoice with an invoiceID and an invoiceNumber
- await testData.checkTransactionBillingData(transactionID, BillingInvoiceStatus.PAID, 22);
+ await testData.checkTransactionBillingData(transactionID, BillingInvoiceStatus.PAID, 25);
});
it('should bill the FF+E+E(STEP) with 2 tariffs on COMBO CCS - DC', async () => {
@@ -1265,7 +1265,7 @@ describe('Billing Service', function() {
const transactionID = await testData.generateTransaction(testData.userContext);
assert(transactionID, 'transactionID should not be null');
// Check that we have a new invoice with an invoiceID and an invoiceNumber
- await testData.checkTransactionBillingData(transactionID, BillingInvoiceStatus.PAID, 15.37);
+ await testData.checkTransactionBillingData(transactionID, BillingInvoiceStatus.PAID, 17.37);
});
});

pricing - fix bug - absorb step consumption