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 25637 7441045bf9fd
parent 25636 a502f548532a
child 25638 3a0b18f1e0bb
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 11 14:13:06 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 11 14:13:06 2014 +0100
+++ b/src/org/openbravo/costing/LandedCostProcess.java	Mon Dec 01 16:49:43 2014 +0100
@@ -170,7 +170,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