Fixes bug 28286 LandedCostLineAmt should always be created in the same order
authorAlvaro Ferraz <alvaro.ferraz@openbravo.com>
Mon, 01 Dec 2014 16:49:43 +0100
changeset 25493 1f26de8763c0
parent 25492 107d831cf383
child 25494 4ae6c365fd3e
Fixes bug 28286 LandedCostLineAmt should always be created in the same order

In order to help JUnit tests assert landed cost, an orderBy clause has been added when creating Landed Cost Receipt Line Amount lines, to be always created in the same order.
src/org/openbravo/costing/LandedCostDistributionByAmount.java
src/org/openbravo/costing/LandedCostProcess.java
--- a/src/org/openbravo/costing/LandedCostDistributionByAmount.java	Thu Dec 04 16:58:28 2014 +0100
+++ b/src/org/openbravo/costing/LandedCostDistributionByAmount.java	Mon Dec 01 16:49:43 2014 +0100
@@ -145,7 +145,8 @@
     qry.append("   and lcr." + LCReceipt.PROPERTY_LANDEDCOST + ".id = :landedCost");
     qry.append(" group by lcr.id, iol.id, trx." + MaterialTransaction.PROPERTY_CURRENCY + ".id");
     if (doOrderBy) {
-      qry.append(" order by sum(tc." + TransactionCost.PROPERTY_COST + ")");
+      qry.append(" order by iol." + ShipmentInOutLine.PROPERTY_LINENO);
+      qry.append(" , sum(tc." + TransactionCost.PROPERTY_COST + ")");
     }
 
     Query qryReceiptCosts = OBDal.getInstance().getSession().createQuery(qry.toString());
--- a/src/org/openbravo/costing/LandedCostProcess.java	Thu Dec 04 16:58:28 2014 +0100
+++ b/src/org/openbravo/costing/LandedCostProcess.java	Mon Dec 01 16:49:43 2014 +0100
@@ -165,7 +165,10 @@
   }
 
   private void distributeAmounts(LandedCost landedCost) {
-    for (LandedCostCost lcCost : landedCost.getLandedCostCostList()) {
+    OBCriteria<LandedCostCost> criteria = OBDal.getInstance().createCriteria(LandedCostCost.class);
+    criteria.add(Restrictions.eq(LandedCostCost.PROPERTY_LANDEDCOST, landedCost));
+    criteria.addOrderBy(LandedCostCost.PROPERTY_LINENO, true);
+    for (LandedCostCost lcCost : criteria.list()) {
       log.debug("Start Distributing lcCost {}", lcCost.getIdentifier());
       // Load distribution algorithm
       LandedCostDistributionAlgorithm lcDistAlg = getDistributionAlgorithm(lcCost