From 79573836b1cf0b7d48bf71ca93bb97f01d776ab1 Mon Sep 17 00:00:00 2001 From: Manuel Rego Casasnovas Date: Mon, 19 Mar 2012 18:17:04 +0100 Subject: [PATCH] Prevent NPE if there is not relationship between resource and type of hours via cost category In that case the default price for the hours type is used. FEA: ItEr76S17MoneyCostMonitoringSystem --- .../business/planner/entities/IMoneyCostCalculator.java | 6 +++++- .../business/planner/entities/MoneyCostCalculator.java | 7 +++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/libreplan-business/src/main/java/org/libreplan/business/planner/entities/IMoneyCostCalculator.java b/libreplan-business/src/main/java/org/libreplan/business/planner/entities/IMoneyCostCalculator.java index 40fe17d20..2f6f21230 100644 --- a/libreplan-business/src/main/java/org/libreplan/business/planner/entities/IMoneyCostCalculator.java +++ b/libreplan-business/src/main/java/org/libreplan/business/planner/entities/IMoneyCostCalculator.java @@ -38,7 +38,11 @@ public interface IMoneyCostCalculator { * following formula:
* Sum of all the hours devoted to a task multiplied by the cost of * each hour according to these parameters (type of hour, cost category of - * the resource, date of the work report) + * the resource, date of the work report)
+ * + * If there is not relationship between resource and type of hour through + * the cost categories, the price used is the default one for the type of + * hour. * * @param The * {@link OrderElement} to calculate the money cost diff --git a/libreplan-business/src/main/java/org/libreplan/business/planner/entities/MoneyCostCalculator.java b/libreplan-business/src/main/java/org/libreplan/business/planner/entities/MoneyCostCalculator.java index 09d1322ec..9afd0e21d 100644 --- a/libreplan-business/src/main/java/org/libreplan/business/planner/entities/MoneyCostCalculator.java +++ b/libreplan-business/src/main/java/org/libreplan/business/planner/entities/MoneyCostCalculator.java @@ -66,6 +66,13 @@ public class MoneyCostCalculator implements IMoneyCostCalculator { workReportLine.getResource(), workReportLine.getLocalDate(), workReportLine.getTypeOfWorkHours()); + + // If cost undefined via CostCategory get it from type + if (priceCost == null) { + priceCost = workReportLine.getTypeOfWorkHours() + .getDefaultPrice(); + } + BigDecimal cost = priceCost.multiply(workReportLine.getEffort() .toHoursAsDecimalWithScale(2)); result = result.add(cost);