pricing - resolution org/site/site area
MODIFY
src/integration/pricing/PricingEngine.ts
src/integration/pricing/PricingEngine.ts
@@ -116,9 +116,15 @@ export default class PricingEngine {
static async priceFinalConsumption(tenant: Tenant, transaction: Transaction, consumptionData: Consumption): Promise<PricingConsumptionData> {
// Check the restrictions to find the pricing definition matching the current context
- const actualPricingDefinitions = transaction.pricingModel.pricingDefinitions.filter((pricingDefinition) =>
+ let actualPricingDefinitions = transaction.pricingModel.pricingDefinitions.filter((pricingDefinition) =>
PricingEngine.checkPricingDefinitionRestrictions(pricingDefinition, consumptionData)
);
+ // Having more than one pricing definition this NOT a normal situation.
+ // This means that two different tariff matches the same criteria. This should not happen!
+ if (actualPricingDefinitions.length > 1) {
+ // TODO - to be clarified! - Shall we mix several pricing definition for a single transaction?
+ actualPricingDefinitions = [ actualPricingDefinitions?.[0] ];
+ }
// Build the consumption data for each dimension
const flatFee: PricingDimensionData = PricingEngine.priceFlatFeeConsumption(actualPricingDefinitions, consumptionData);
const energy: PricingDimensionData = PricingEngine.priceEnergyConsumption(actualPricingDefinitions, consumptionData);

MODIFY
test/api/BillingTest.ts
test/api/BillingTest.ts
@@ -248,9 +248,11 @@ class TestData {
assert(company, 'The Company should not be null');
await this.createTariff4Company(company.id);
- const site = (await this.adminUserService.siteApi.readAll({}, { limit: 0, skip: 0 }))?.data?.result?.[0];
- assert(site, 'The Site should not be null');
- await this.createTariff4Site(site.id);
+ const sites = (await this.adminUserService.siteApi.readAll({}, { limit: 0, skip: 0 }))?.data?.result;
+ const selectedSites = sites.filter((site) => site.name === 'ut-site-stop');
+ assert(selectedSites, 'Sites should not be null');
+ assert(selectedSites[0], 'The Site should not be null');
+ await this.createTariff4Site(selectedSites[0].id);
}
public async createTariff4Company(companyID: string): Promise<void> {
@@ -270,7 +272,7 @@ class TestData {
name: 'GREEN Tariff',
description: 'Tariff for low EVSE',
restrictions: {
- maxPowerkW: 40000,
+ maxPowerkW: 40,
},
dimensions: {
flatFee: {
@@ -316,7 +318,7 @@ class TestData {
name: 'RED Tariff',
description: 'Tariff for fast chargers',
restrictions: {
- minPowerkW: 40000,
+ minPowerkW: 40,
},
dimensions: {
flatFee: {

pricing - resolution org/site/site area