Fixes on the resources budget calculation algorithm

FEA: ItEr77S17AutomaticBudgeting
This commit is contained in:
Lorenzo Tilve Álvaro 2013-06-14 21:03:45 +02:00
parent cd63d13805
commit b65c34382f

View file

@ -1726,37 +1726,37 @@ public abstract class OrderElement extends IntegrationEntity implements
public BigDecimal calculateBudgetFromCriteriaAndCostCategories() { public BigDecimal calculateBudgetFromCriteriaAndCostCategories() {
BigDecimal totalBudget = new BigDecimal(0); BigDecimal totalBudget = new BigDecimal(0);
BigDecimal costPerHour = new BigDecimal(0);
Configuration configuration = Registry.getConfigurationDAO() Configuration configuration = Registry.getConfigurationDAO()
.getConfiguration(); .getConfiguration();
TypeOfWorkHours typeofWorkHours = configuration TypeOfWorkHours typeofWorkHours = configuration
.getBudgetDefaultTypeOfWorkHours(); .getBudgetDefaultTypeOfWorkHours();
if (!configuration.isEnabledAutomaticBudget()
if (typeofWorkHours == null) { || (configuration.getBudgetDefaultTypeOfWorkHours() == null)) {
return totalBudget; return totalBudget;
} }
// FIXME: This workarounds LazyException when adding new // FIXME: This workarounds LazyException when adding new
// criteria but disables the refresh on changes // criteria but disables the refresh on changes
for (CriterionRequirement requirement : getCriterionRequirements()) { BigDecimal costPerHour = new BigDecimal(0);
BigDecimal hours = new BigDecimal(getWorkHours()); BigDecimal hours = new BigDecimal(0);
try {
totalBudget = totalBudget.add(costPerHour.multiply(hours));
for (CriterionRequirement requirement : getCriterionRequirements()) {
hours = new BigDecimal(getWorkHours());
try {
if (requirement.getCriterion().getCostCategory() != null) {
costPerHour = requirement.getCriterion().getCostCategory() costPerHour = requirement.getCriterion().getCostCategory()
.getHourCostByCode(typeofWorkHours.getCode()) .getHourCostByCode(typeofWorkHours.getCode())
.getPriceCost(); .getPriceCost();
totalBudget = totalBudget.add(costPerHour.multiply(hours)); totalBudget = totalBudget.add(costPerHour.multiply(hours));
} catch (InstanceNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} }
totalBudget = totalBudget.add(costPerHour.multiply(hours)); } catch (InstanceNotFoundException e) {
// Nothing to do, the budget is kept to 0
}
} }
for (HoursGroup hoursGroup : getHoursGroups()) { for (HoursGroup hoursGroup : getHoursGroups()) {
BigDecimal hours = new BigDecimal(hoursGroup.getWorkingHours()); hours = new BigDecimal(hoursGroup.getWorkingHours());
for (CriterionRequirement crit : hoursGroup for (CriterionRequirement crit : hoursGroup
.getCriterionRequirements()) { .getCriterionRequirements()) {
@ -1772,9 +1772,9 @@ public abstract class OrderElement extends IntegrationEntity implements
costPerHour = new BigDecimal(0); costPerHour = new BigDecimal(0);
} }
} }
}
totalBudget = totalBudget.add(costPerHour.multiply(hours)); totalBudget = totalBudget.add(costPerHour.multiply(hours));
} }
}
return totalBudget; return totalBudget;
} }