details: https://code.openbravo.com/erp/devel/pi/rev/e087d572eed7 changeset: 25653:e087d572eed7 user: Unai Martirena <unai.martirena <at> openbravo.com> date: Wed Dec 31 11:03:15 2014 +0100 summary: Fixes bug 28502: Inv Amt Update takes into account Costing Rule warehouse dim
The problem was that the process was checking if the warehouse in Inventory Amount Update is null or not, and if not, it uses it. This is correct when the Costing Rule is set as Warehouse Dimension, but if is not, it should not use it, and even if the Costing Rule is not set as Warehouse Dimension and the warehouse field is hidden in Inventory Amount Lines, it is filled with the Warehouse set in session value. details: https://code.openbravo.com/erp/devel/pi/rev/5d9b7b151669 changeset: 25654:5d9b7b151669 user: Unai Martirena <unai.martirena <at> openbravo.com> date: Wed Dec 31 13:50:58 2014 +0100 summary: Fixes bug 28509: Inventory Amt Update now works with negative stock. In this case the Qty Count and Qty Book have been reverted in the Physical Inventory Lines and negate them to make them positive, maintaining the difference between them to create the same transaction quantity. Also getInventoryClosingCost function in AverageAlgorithm has been changed to negate the cost obtained from an inventory closing when the movement qty is positive (closing from negative to 0), because the cost obtained was negative, and this is wrong. details: https://code.openbravo.com/erp/devel/pi/rev/2161bdf91225 changeset: 25655:2161bdf91225 user: Unai Martirena <unai.martirena <at> openbravo.com> date: Wed Dec 31 16:16:00 2014 +0100 summary: Fixes Bug 28487: Fixed Null Pointer Exception. The problem was that in updateBDCostingTimeRange function inside AverageCostAdjustment class, the code was trying to get the movement date of a Inventory Transaction related to a Costing record. But not all costing have Inventory Transaction, so it was giving a NPE. Now, if there is a previous Costing record than the one created due to a backdated transaction, this Costing will be shortened till transaction process date, and the new Backdated costing record will start at that moment. This only happens the first time that a related transaction is found that is not a backdated transaction, because if is done with a backdated transaction time overlap can happen. details: https://code.openbravo.com/erp/devel/pi/rev/e96a15e0c289 changeset: 25656:e96a15e0c289 user: Unai Martirena <unai.martirena <at> openbravo.com> date: Fri Jan 02 13:01:06 2015 +0100 summary: Fixed bug 28052: Wrong message processing a Shipment with a partial reservation. Reallocation function executed when trying to complete a Goods Shipment, was changed to launch a not enough stock error if the quantity pending to release exceeds the available existent in the line's storage bin. diffstat: src-db/database/model/functions/M_RESERVATION_REALLOCATE.xml | 4 + src/org/openbravo/costing/AverageAlgorithm.java | 3 + src/org/openbravo/costing/AverageCostAdjustment.java | 33 ++++++++--- src/org/openbravo/costing/InventoryAmountUpdateProcess.java | 8 +- 4 files changed, 35 insertions(+), 13 deletions(-) diffs (112 lines): diff -r c778327fb6eb -r e96a15e0c289 src-db/database/model/functions/M_RESERVATION_REALLOCATE.xml --- a/src-db/database/model/functions/M_RESERVATION_REALLOCATE.xml Tue Dec 30 22:17:38 2014 +0000 +++ b/src-db/database/model/functions/M_RESERVATION_REALLOCATE.xml Fri Jan 02 13:01:06 2015 +0100 @@ -156,6 +156,10 @@ p_message := '@MoreQuantityToReleaseThanPending@'||' @of@'||' @Product@: '||v_product_value||', @AttributeSetInstance@: '||COALESCE(v_attr_description, '-')|| ', @UOM@: '||v_uom_value||' @And@'||' @StorageBin@: '||COALESCE(v_locator_value, '-'); END IF; + IF (v_pendingtoreallocate > v_stock_onhand) THEN + RAISE_APPLICATION_ERROR(-20000, '@NotEnoughAvailableStock@'||' @of@'||' @Product@: '||v_product_value||', @AttributeSetInstance@: '||COALESCE(v_attr_description, '-')|| ', @UOM@: '||v_uom_value||' @And@'||' @StorageBin@: '||COALESCE(v_locator_value, '-')); + END IF; + -- Check that quantity to release is lower than available quantity considering other reservations allocated stock. IF (v_pendingtoreallocate > v_stock_onhand - (v_stock_alloc - v_this_sd_alloc)) THEN RAISE_APPLICATION_ERROR(-20000, '@CannotReallocateAllQuantity@'||' @of@'||' @Product@: '||v_product_value||', @AttributeSetInstance@: '||COALESCE(v_attr_description, '-')|| ', @UOM@: '||v_uom_value||' @And@'||' @StorageBin@: '||COALESCE(v_locator_value, '-')); diff -r c778327fb6eb -r e96a15e0c289 src/org/openbravo/costing/AverageAlgorithm.java --- a/src/org/openbravo/costing/AverageAlgorithm.java Tue Dec 30 22:17:38 2014 +0000 +++ b/src/org/openbravo/costing/AverageAlgorithm.java Fri Jan 02 13:01:06 2015 +0100 @@ -104,6 +104,9 @@ transaction.getProduct(), costOrg, transaction.getMovementDate(), costDimensions, transaction.getStorageBin(), transaction.getAttributeSetValue(), costCurrency, costingRule.isBackdatedTransactionsFixed()); + if (transaction.getMovementQuantity().signum() == 1) { + cost = cost.negate(); + } return cost; } diff -r c778327fb6eb -r e96a15e0c289 src/org/openbravo/costing/AverageCostAdjustment.java --- a/src/org/openbravo/costing/AverageCostAdjustment.java Tue Dec 30 22:17:38 2014 +0000 +++ b/src/org/openbravo/costing/AverageCostAdjustment.java Fri Jan 02 13:01:06 2015 +0100 @@ -212,7 +212,7 @@ log.debug("Process related transaction {}", trx.getIdentifier()); BigDecimal trxSignMultiplier = new BigDecimal(trx.getMovementQuantity().signum()); BigDecimal trxAdjAmt = BigDecimal.ZERO; - if (StringUtils.isNotEmpty(bdCostingId)) { + if (StringUtils.isNotEmpty(bdCostingId) && !isBackdatedTransaction(trx)) { // If there is a backdated source adjustment pending modify the dates of its m_costing. updateBDCostingTimeRange(trx); // This update is done only on the first related transaction. @@ -762,18 +762,13 @@ Costing curCosting = getTrxCurrentCosting(trx); if (curCosting != null) { - if (curCosting.getInventoryTransaction().getMovementDate() - .before(bdCosting.getInventoryTransaction().getMovementDate())) { - bdCosting.setEndingDate(curCosting.getEndingDate()); - curCosting.setEndingDate(trx.getTransactionProcessDate()); - } else { - curCosting.setEndingDate(bdCosting.getEndingDate()); - bdCosting.setEndingDate(trx.getTransactionProcessDate()); - } + bdCosting.setEndingDate(curCosting.getEndingDate()); + curCosting.setEndingDate(trx.getTransactionProcessDate()); OBDal.getInstance().save(curCosting); } else { // There isn't any previous costing. bdCosting.setEndingDate(trx.getTransactionProcessDate()); + } bdCosting.setStartingDate(trx.getTransactionProcessDate()); bdCosting.setPermanent(Boolean.TRUE); @@ -848,4 +843,24 @@ } return false; } + + /** + * Returns true if a transaction is a backdated transaction (has related backdated transaction + * adjustments). + * + * @param trx + * MaterialTransaction to check if is backdated or not. + * @return boolean + */ + private boolean isBackdatedTransaction(MaterialTransaction trx) { + OBCriteria<CostAdjustmentLine> critLines = OBDal.getInstance().createCriteria( + CostAdjustmentLine.class); + critLines.add(Restrictions.eq(CostAdjustmentLine.PROPERTY_INVENTORYTRANSACTION, trx)); + critLines.add(Restrictions.eq(CostAdjustmentLine.PROPERTY_ISBACKDATEDTRX, true)); + final List<CostAdjustmentLine> critLinesList = critLines.list(); + if (critLinesList.size() > 0) { + return true; + } + return false; + } } diff -r c778327fb6eb -r e96a15e0c289 src/org/openbravo/costing/InventoryAmountUpdateProcess.java --- a/src/org/openbravo/costing/InventoryAmountUpdateProcess.java Tue Dec 30 22:17:38 2014 +0000 +++ b/src/org/openbravo/costing/InventoryAmountUpdateProcess.java Fri Jan 02 13:01:06 2015 +0100 @@ -92,7 +92,7 @@ OrganizationStructureProvider osp = OBContext.getOBContext() .getOrganizationStructureProvider(rule.getClient().getId()); final Set<String> childOrgs = osp.getChildTree(rule.getOrganization().getId(), true); - if (line.getWarehouse() == null) { + if (!rule.isWarehouseDimension()) { createInventories(lineId, null, ruleId, childOrgs, line.getReferenceDate()); } else { createInventories(lineId, line.getWarehouse(), ruleId, childOrgs, @@ -220,10 +220,10 @@ } else { openInventoryLine = insertInventoryLine(inv.getInitInventory(), line.getProduct().getId(), attrSetInsId, uomId, orderUOMId, locatorId, - BigDecimal.ZERO, qty, BigDecimal.ZERO, orderQty == null ? null : orderQty, lineNo, - closingInventoryLine, line.getUnitCost()); + BigDecimal.ZERO, qty.negate(), BigDecimal.ZERO, orderQty == null ? null : orderQty, + lineNo, closingInventoryLine, line.getUnitCost()); insertInventoryLine(inv.getCloseInventory(), line.getProduct().getId(), attrSetInsId, - uomId, orderUOMId, locatorId, qty == null ? null : qty, BigDecimal.ZERO, + uomId, orderUOMId, locatorId, qty == null ? null : qty.negate(), BigDecimal.ZERO, orderQty == null ? null : orderQty, BigDecimal.ZERO, lineNo, openInventoryLine, null); } ------------------------------------------------------------------------------ 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