details: https://code.openbravo.com/erp/devel/pi/rev/fb92cb9bd2eb changeset: 27086:fb92cb9bd2eb user: Alvaro Ferraz <alvaro.ferraz <at> openbravo.com> date: Fri Jul 03 11:08:17 2015 +0200 summary: Fixes issue 30232: Costing record not referencing transaction
getRelatedTransactions method in AverageCostAdjustment.java was creating an HQL query with a wrong parenthesis. Because of that Order By clause did not appear in the query, what was causing wrong Costing entries. Also, when this error happens, current costing will be updated with the new cost, instead of creating a new costing with a null transaction. diffstat: src/org/openbravo/costing/AverageCostAdjustment.java | 42 ++++++------------- 1 files changed, 13 insertions(+), 29 deletions(-) diffs (62 lines): diff -r adc2491ee60b -r fb92cb9bd2eb src/org/openbravo/costing/AverageCostAdjustment.java --- a/src/org/openbravo/costing/AverageCostAdjustment.java Mon Jul 06 12:32:17 2015 +0200 +++ b/src/org/openbravo/costing/AverageCostAdjustment.java Fri Jul 03 11:08:17 2015 +0200 @@ -431,35 +431,20 @@ + OBDateUtils.formatDate(new Date())); } if (currentCosting.getCost().compareTo(cost) != 0) { - basetrx = getTransaction(); - Date newDate = new Date(); - Date dateTo = currentCosting.getEndingDate(); - currentCosting.setEndingDate(newDate); + // Update existing costing + currentCosting.setPermanent(Boolean.FALSE); OBDal.getInstance().save(currentCosting); - Costing newCosting = OBProvider.getInstance().get(Costing.class); - newCosting.setCost(cost); - newCosting.setCurrency((Currency) OBDal.getInstance().getProxy(Currency.ENTITY_NAME, - strCurrentCurId)); - newCosting.setStartingDate(newDate); - newCosting.setEndingDate(dateTo); - newCosting.setInventoryTransaction(null); - newCosting.setProduct(basetrx.getProduct()); - if (isManufacturingProduct) { - newCosting.setOrganization((Organization) OBDal.getInstance().getProxy( - Organization.ENTITY_NAME, "0")); - } else { - newCosting.setOrganization((Organization) OBDal.getInstance().getProxy( - Organization.ENTITY_NAME, strCostOrgId)); + OBDal.getInstance().flush(); + + if (currentCosting.getOriginalCost() == null) { + currentCosting.setOriginalCost(currentCosting.getCost()); } - newCosting.setQuantity(null); - newCosting.setTotalMovementQuantity(currentStock); - newCosting.setPrice(cost); - newCosting.setCostType("AVA"); - newCosting.setManual(Boolean.FALSE); - newCosting.setPermanent(Boolean.TRUE); - newCosting.setProduction(trxType == TrxType.ManufacturingProduced); - newCosting.setWarehouse((Warehouse) getCostDimensions().get(CostDimension.Warehouse)); - OBDal.getInstance().save(newCosting); + currentCosting.setPrice(cost); + currentCosting.setCost(cost); + currentCosting.setTotalMovementQuantity(currentStock); + currentCosting.setManual(Boolean.FALSE); + currentCosting.setPermanent(Boolean.TRUE); + OBDal.getInstance().save(currentCosting); } } } @@ -617,9 +602,8 @@ wh.append(" trx." + MaterialTransaction.PROPERTY_MOVEMENTQUANTITY + " = :trxqty"); wh.append(" and trx." + MaterialTransaction.PROPERTY_ID + " > :trxid"); wh.append(" )))))"); - wh.append(" )))"); + wh.append(" ))))"); } - wh.append(")"); wh.append(" and org.id in (:orgs)"); if (warehouse != null) { wh.append(" and loc." + Locator.PROPERTY_WAREHOUSE + " = :warehouse"); ------------------------------------------------------------------------------ Don't Limit Your Business. Reach for the Cloud. GigeNET's Cloud Solutions provide you with the tools and support that you need to offload your IT needs and focus on growing your business. Configured For All Businesses. Start Your Cloud Today. https://www.gigenetcloud.com/ _______________________________________________ Openbravo-commits mailing list Openbravo-commits@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/openbravo-commits