details: https://code.openbravo.com/erp/devel/pi/rev/ecf72f76195b changeset: 26085:ecf72f76195b user: Unai Martirena <unai.martirena <at> openbravo.com> date: Thu Feb 26 15:23:25 2015 +0100 summary: Fixes bug 29080: getStartingDate() method does not fail in Costing Background.
An OBQuery is being executed in getStartingDate() method inside AverageAlgorithm. There are 2 parameters in this OBQuery that are not setting properly, 'client' and 'org'. The whereclause is filtering by 'id' of these properties and instead of passing the id of these objects, the object was being passed to the OBQuery. These sometimes works but other times don't, so this has been changed to always setting the id's as parameters. details: https://code.openbravo.com/erp/devel/pi/rev/67607f6caaee changeset: 26086:67607f6caaee user: Unai Martirena <unai.martirena <at> openbravo.com> date: Thu Feb 26 15:29:20 2015 +0100 summary: Fixes bug 29076: Division by zero error managed in Costing Background. Under certain circumnstance a division by zero error was happening in Cost Adjustments process inside Costing Background (when calculating backdated adjustments of a transaction of movementqty zero). This problem has been managed by being sure that this division will not happen again. If the movementqty of the transaction is zero, the cost of the full transaction will be zero as well. details: https://code.openbravo.com/erp/devel/pi/rev/4b1565029827 changeset: 26087:4b1565029827 user: Unai Martirena <unai.martirena <at> openbravo.com> date: Thu Feb 26 15:36:55 2015 +0100 summary: Fixes bug 29079: Fixed Costing Background infinite loop. Costing Background process, due to Cost Adjustments new implementation, on a certain point of the code, it was not applying correctly a setScale method to round a value of the expected cost. This was causing to have allways a difference between the expected cost and unitcost. Because of this, an adjustment was being created to adjust this difference, and to adjust all related transactions, causing an infinite loop diffstat: src/org/openbravo/costing/AverageAlgorithm.java | 6 +- src/org/openbravo/costing/AverageCostAdjustment.java | 35 ++++++++++++++----- 2 files changed, 28 insertions(+), 13 deletions(-) diffs (90 lines): diff -r ca0b1242f774 -r 4b1565029827 src/org/openbravo/costing/AverageAlgorithm.java --- a/src/org/openbravo/costing/AverageAlgorithm.java Thu Feb 26 15:56:04 2015 +0100 +++ b/src/org/openbravo/costing/AverageAlgorithm.java Thu Feb 26 15:36:55 2015 +0100 @@ -11,7 +11,7 @@ * under the License. * The Original Code is Openbravo ERP. * The Initial Developer of the Original Code is Openbravo SLU - * All portions are Copyright (C) 2012-2014 Openbravo SLU + * All portions are Copyright (C) 2012-2015 Openbravo SLU * All Rights Reserved. * Contributor(s): ______________________________________. ************************************************************************* @@ -198,9 +198,9 @@ } // FIXME: remove when manufacturing costs are fully migrated if (product.isProduction()) { - costQry.setNamedParameter("client", costOrg.getClient()); + costQry.setNamedParameter("client", costOrg.getClient().getId()); } else { - costQry.setNamedParameter("org", costOrg); + costQry.setNamedParameter("org", costOrg.getId()); } List<Costing> costList = costQry.list(); diff -r ca0b1242f774 -r 4b1565029827 src/org/openbravo/costing/AverageCostAdjustment.java --- a/src/org/openbravo/costing/AverageCostAdjustment.java Thu Feb 26 15:56:04 2015 +0100 +++ b/src/org/openbravo/costing/AverageCostAdjustment.java Thu Feb 26 15:36:55 2015 +0100 @@ -135,8 +135,13 @@ log.debug("Starting average cost {}", cost == null ? "not cost" : cost.toPlainString()); if (cost != null && (AverageAlgorithm.modifiesAverage(trxType) || !baseCAL.isBackdatedTrx())) { BigDecimal trxCost = CostAdjustmentUtils.getTrxCost(basetrx, false, getCostCurrency()); - BigDecimal trxPrice = trxCost.add(adjustmentBalance.multiply(signMultiplier)).divide( - basetrx.getMovementQuantity().abs(), costCurPrecission, RoundingMode.HALF_UP); + BigDecimal trxPrice = null; + if (basetrx.getMovementQuantity().signum() == 0) { + trxPrice = BigDecimal.ZERO; + } else { + trxPrice = trxCost.add(adjustmentBalance.multiply(signMultiplier)).divide( + basetrx.getMovementQuantity().abs(), costCurPrecission, RoundingMode.HALF_UP); + } if (checkNegativeStockCorrection && currentStock.compareTo(basetrx.getMovementQuantity()) < 0 && cost.compareTo(trxPrice) != 0 && !baseCAL.isNegativeStockCorrection() && AverageAlgorithm.modifiesAverage(trxType)) { @@ -286,9 +291,14 @@ } log.debug("New average cost: {}", cost.toPlainString()); Costing curCosting = trx.getMaterialMgmtCostingList().get(0); - BigDecimal trxPrice = curCosting.getPrice().multiply(trx.getMovementQuantity().abs()) - .add(trxAdjAmt.multiply(trxSignMultiplier)) - .divide(trx.getMovementQuantity().abs(), costCurPrecission, RoundingMode.HALF_UP); + BigDecimal trxPrice = null; + if (trx.getMovementQuantity().signum() == 0) { + trxPrice = BigDecimal.ZERO; + } else { + trxPrice = curCosting.getPrice().multiply(trx.getMovementQuantity().abs()) + .add(trxAdjAmt.multiply(trxSignMultiplier)) + .divide(trx.getMovementQuantity().abs(), costCurPrecission, RoundingMode.HALF_UP); + } if (checkNegativeStockCorrection && currentStock.compareTo(trx.getMovementQuantity()) < 0 && cost.compareTo(trxPrice) != 0) { @@ -333,8 +343,8 @@ } else if (cost != null && !isVoidedTrx(trx, currentTrxType)) { if (!trx.isCostPermanent()) { // Check current trx unit cost matches new expected cost - BigDecimal expectedCost = cost.multiply(trx.getMovementQuantity().abs() - .setScale(costCurPrecission, RoundingMode.HALF_UP)); + BigDecimal expectedCost = cost.multiply(trx.getMovementQuantity().abs()).setScale( + costCurPrecission, RoundingMode.HALF_UP); BigDecimal unitCost = CostAdjustmentUtils.getTrxCost(trx, true, OBDal.getInstance() .get(Currency.class, strCurrentCurId)); unitCost = unitCost.add(trxAdjAmt); @@ -360,9 +370,14 @@ cost = currentValueAmt.add(adjustmentBalance).divide(currentStock, costCurPrecission, RoundingMode.HALF_UP); } - BigDecimal trxPrice = curCosting.getPrice().multiply(trx.getMovementQuantity().abs()) - .add(trxAdjAmt.multiply(trxSignMultiplier)) - .divide(trx.getMovementQuantity().abs(), costCurPrecission, RoundingMode.HALF_UP); + BigDecimal trxPrice = null; + if (trx.getMovementQuantity().signum() == 0) { + trxPrice = BigDecimal.ZERO; + } else { + trxPrice = curCosting.getPrice().multiply(trx.getMovementQuantity().abs()) + .add(trxAdjAmt.multiply(trxSignMultiplier)) + .divide(trx.getMovementQuantity().abs(), costCurPrecission, RoundingMode.HALF_UP); + } if (curCosting.getCost().compareTo(cost) != 0) { curCosting.setPermanent(Boolean.FALSE); OBDal.getInstance().save(curCosting); ------------------------------------------------------------------------------ Dive into the World of Parallel Programming The Go Parallel Website, sponsored by Intel and developed in partnership with Slashdot Media, is your hub for all things parallel software development, from weekly thought leadership blogs to news, videos, case studies, tutorials and more. Take a look and join the conversation now. http://goparallel.sourceforge.net/ _______________________________________________ Openbravo-commits mailing list Openbravo-commits@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/openbravo-commits