JoaoJandre commented on code in PR #8347:
URL: https://github.com/apache/cloudstack/pull/8347#discussion_r1561533659


##########
framework/quota/src/main/java/org/apache/cloudstack/quota/QuotaManagerImpl.java:
##########
@@ -367,9 +369,22 @@ protected BigDecimal aggregateQuotaTariffsValues(UsageVO 
usageRecord, List<Quota
         PresetVariables presetVariables = 
getPresetVariables(hasAnyQuotaTariffWithActivationRule, usageRecord);
         BigDecimal aggregatedQuotaTariffsValue = BigDecimal.ZERO;
 
+        quotaTariffs.sort(Comparator.comparing(QuotaTariffVO::getPosition));
+
+        List<Tariff> lastTariffs = new ArrayList<>();
+
+
         for (QuotaTariffVO quotaTariff : quotaTariffs) {
             if (isQuotaTariffInPeriodToBeApplied(usageRecord, quotaTariff, 
accountToString)) {
-                aggregatedQuotaTariffsValue = 
aggregatedQuotaTariffsValue.add(getQuotaTariffValueToBeApplied(quotaTariff, 
jsInterpreter, presetVariables));
+
+                BigDecimal tariffValue = 
getQuotaTariffValueToBeApplied(quotaTariff, jsInterpreter, presetVariables, 
lastTariffs);
+
+                aggregatedQuotaTariffsValue = 
aggregatedQuotaTariffsValue.add(tariffValue);
+
+                Tariff tariffPresetVariable = new Tariff();
+                tariffPresetVariable.setId(quotaTariff.getUuid());
+                tariffPresetVariable.setValue(tariffValue);
+                lastTariffs.add(tariffPresetVariable);

Review Comment:
   The tariff does not need an activation rule to have a position. You could 
have a tariff with only a value but at position 2 if you wanted.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to