Author: diveshdutta
Date: Sat Nov 5 16:33:58 2016
New Revision: 1768243
URL:
http://svn.apache.org/viewvc?rev=1768243&view=revLog:
Improvement: Total Actual cost of production run need to be passed on to produced stock's unit cost for completed production run. Produced Item's inventory item i.e. = Total Actual Cost/ Produced in Stock.
(OFBIZ-7111)
Thanks: Swapnil Shah for suggesting the improvmeent and Anuj Jain for providing the patch
Modified:
ofbiz/trunk/applications/manufacturing/src/main/java/org/apache/ofbiz/manufacturing/jobshopmgt/ProductionRunServices.java
Modified: ofbiz/trunk/applications/manufacturing/src/main/java/org/apache/ofbiz/manufacturing/jobshopmgt/ProductionRunServices.java
URL:
http://svn.apache.org/viewvc/ofbiz/trunk/applications/manufacturing/src/main/java/org/apache/ofbiz/manufacturing/jobshopmgt/ProductionRunServices.java?rev=1768243&r1=1768242&r2=1768243&view=diff==============================================================================
--- ofbiz/trunk/applications/manufacturing/src/main/java/org/apache/ofbiz/manufacturing/jobshopmgt/ProductionRunServices.java (original)
+++ ofbiz/trunk/applications/manufacturing/src/main/java/org/apache/ofbiz/manufacturing/jobshopmgt/ProductionRunServices.java Sat Nov 5 16:33:58 2016
@@ -1684,8 +1684,25 @@ public class ProductionRunServices {
}
outputMap = dispatcher.runSync("getProductCost", UtilMisc.<String, Object>toMap("userLogin", userLogin, "productId", productionRun.getProductProduced().getString("productId"), "currencyUomId", (String)partyAccountingPreference.get("baseCurrencyUomId"), "costComponentTypePrefix", "EST_STD"));
unitCost = (BigDecimal)outputMap.get("productCost");
- if (unitCost == null) {
- unitCost = ZERO;
+ if (unitCost != null && unitCost.compareTo(BigDecimal.ZERO) == 0) {
+ BigDecimal totalCost = ZERO;
+ List<GenericValue> tasks = productionRun.getProductionRunRoutingTasks();
+ // generic_cost
+ List<GenericValue> actualGenCosts = EntityQuery.use(delegator).from("CostComponent").where("workEffortId", productionRunId, "costUomId", (String) partyAccountingPreference.get("baseCurrencyUomId")).queryList();
+ for (GenericValue actualGenCost : actualGenCosts) {
+ totalCost = totalCost.add((BigDecimal) actualGenCost.get("cost"));
+ }
+ for (GenericValue task : tasks) {
+ List<GenericValue> otherCosts = EntityQuery.use(delegator).from("CostComponent").where("workEffortId", task.get("workEffortId"), "costUomId", (String) partyAccountingPreference.get("baseCurrencyUomId")).queryList();
+ for (GenericValue otherCost : otherCosts) {
+ totalCost = totalCost.add((BigDecimal) otherCost.get("cost"));
+ }
+ }
+ if (totalCost != null) {
+ unitCost = totalCost.divide(quantity);
+ } else {
+ unitCost = BigDecimal.ZERO;
+ }
}
// Before creating InvntoryItem and InventoryItemDetails, check weather the record of ProductFacility exist in the system or not