details:   https://code.openbravo.com/erp/devel/pi/rev/53de8c237978
changeset: 33970:53de8c237978
user:      Alvaro Ferraz <alvaro.ferraz <at> openbravo.com>
date:      Wed May 16 18:30:19 2018 +0200
summary:   Fixes issue 38307: Wrong NSC when trx has no unit cost adjustments

When calculating the trxPrice we should take into account every adjustment 
amount (unit cost or not unit cost), but negative stock corrections.

details:   https://code.openbravo.com/erp/devel/pi/rev/6d9d6f538641
changeset: 33971:6d9d6f538641
user:      Alvaro Ferraz <alvaro.ferraz <at> openbravo.com>
date:      Thu May 17 13:14:16 2018 +0200
summary:   Related to issue 38307: Remove unused prices in 
TestCostingLandedCost.java

diffstat:

 src-test/src/org/openbravo/test/costing/TestCostingLandedCost.java          |  
308 +++++----
 src-test/src/org/openbravo/test/costing/TestCostingNoSourceAdjustments.java |  
  8 +-
 src/org/openbravo/costing/AverageCostAdjustment.java                        |  
177 +++--
 3 files changed, 270 insertions(+), 223 deletions(-)

diffs (truncated from 1178 to 300 lines):

diff -r 4b209651d928 -r 6d9d6f538641 
src-test/src/org/openbravo/test/costing/TestCostingLandedCost.java
--- a/src-test/src/org/openbravo/test/costing/TestCostingLandedCost.java        
Thu May 17 10:28:43 2018 +0200
+++ b/src-test/src/org/openbravo/test/costing/TestCostingLandedCost.java        
Thu May 17 13:14:16 2018 +0200
@@ -70,8 +70,9 @@
 
     try {
 
-      OBContext.setOBContext(TestCostingConstants.OPENBRAVO_USER_ID, 
TestCostingConstants.QATESTING_ROLE_ID,
-          TestCostingConstants.QATESTING_CLIENT_ID, 
TestCostingConstants.SPAIN_ORGANIZATION_ID);
+      OBContext.setOBContext(TestCostingConstants.OPENBRAVO_USER_ID,
+          TestCostingConstants.QATESTING_ROLE_ID, 
TestCostingConstants.QATESTING_CLIENT_ID,
+          TestCostingConstants.SPAIN_ORGANIZATION_ID);
       OBContext.setAdminMode(true);
 
       // Create a new product for the test
@@ -130,7 +131,7 @@
       List<MaterialTransaction> transactionList1 = 
TestCostingUtils.getProductTransactions(product1
           .getId());
       List<ProductCostingAssert> productCostingAssertList1 = new 
ArrayList<ProductCostingAssert>();
-      productCostingAssertList1.add(new 
ProductCostingAssert(transactionList1.get(0), price1,
+      productCostingAssertList1.add(new 
ProductCostingAssert(transactionList1.get(0), price5,
           price1, price5, quantity1));
       TestCostingUtils.assertProductCosting(product1.getId(), 
productCostingAssertList1);
 
@@ -138,7 +139,7 @@
       List<MaterialTransaction> transactionList2 = 
TestCostingUtils.getProductTransactions(product2
           .getId());
       List<ProductCostingAssert> productCostingAssertList2 = new 
ArrayList<ProductCostingAssert>();
-      productCostingAssertList2.add(new 
ProductCostingAssert(transactionList2.get(0), price2,
+      productCostingAssertList2.add(new 
ProductCostingAssert(transactionList2.get(0), price6,
           price2, price6, quantity2));
       TestCostingUtils.assertProductCosting(product2.getId(), 
productCostingAssertList2);
 
@@ -199,8 +200,9 @@
 
     try {
 
-      OBContext.setOBContext(TestCostingConstants.OPENBRAVO_USER_ID, 
TestCostingConstants.QATESTING_ROLE_ID,
-          TestCostingConstants.QATESTING_CLIENT_ID, 
TestCostingConstants.SPAIN_ORGANIZATION_ID);
+      OBContext.setOBContext(TestCostingConstants.OPENBRAVO_USER_ID,
+          TestCostingConstants.QATESTING_ROLE_ID, 
TestCostingConstants.QATESTING_CLIENT_ID,
+          TestCostingConstants.SPAIN_ORGANIZATION_ID);
       OBContext.setAdminMode(true);
 
       // Create a new product for the test
@@ -255,7 +257,7 @@
       List<MaterialTransaction> transactionList1 = 
TestCostingUtils.getProductTransactions(product1
           .getId());
       List<ProductCostingAssert> productCostingAssertList1 = new 
ArrayList<ProductCostingAssert>();
-      productCostingAssertList1.add(new 
ProductCostingAssert(transactionList1.get(0), price1,
+      productCostingAssertList1.add(new 
ProductCostingAssert(transactionList1.get(0), price6,
           price1, price6, quantity1));
       TestCostingUtils.assertProductCosting(product1.getId(), 
productCostingAssertList1);
 
@@ -263,7 +265,7 @@
       List<MaterialTransaction> transactionList2 = 
TestCostingUtils.getProductTransactions(product2
           .getId());
       List<ProductCostingAssert> productCostingAssertList2 = new 
ArrayList<ProductCostingAssert>();
-      productCostingAssertList2.add(new 
ProductCostingAssert(transactionList2.get(0), price2,
+      productCostingAssertList2.add(new 
ProductCostingAssert(transactionList2.get(0), price7,
           price2, price7, quantity2));
       TestCostingUtils.assertProductCosting(product2.getId(), 
productCostingAssertList2);
 
@@ -355,8 +357,9 @@
 
     try {
 
-      OBContext.setOBContext(TestCostingConstants.OPENBRAVO_USER_ID, 
TestCostingConstants.QATESTING_ROLE_ID,
-          TestCostingConstants.QATESTING_CLIENT_ID, 
TestCostingConstants.SPAIN_ORGANIZATION_ID);
+      OBContext.setOBContext(TestCostingConstants.OPENBRAVO_USER_ID,
+          TestCostingConstants.QATESTING_ROLE_ID, 
TestCostingConstants.QATESTING_CLIENT_ID,
+          TestCostingConstants.SPAIN_ORGANIZATION_ID);
       OBContext.setAdminMode(true);
 
       // Create a new product for the test
@@ -445,7 +448,7 @@
       List<MaterialTransaction> transactionList1 = 
TestCostingUtils.getProductTransactions(product1
           .getId());
       List<ProductCostingAssert> productCostingAssertList1 = new 
ArrayList<ProductCostingAssert>();
-      productCostingAssertList1.add(new 
ProductCostingAssert(transactionList1.get(0), price1,
+      productCostingAssertList1.add(new 
ProductCostingAssert(transactionList1.get(0), price9,
           price1, price9, quantity2));
       TestCostingUtils.assertProductCosting(product1.getId(), 
productCostingAssertList1);
 
@@ -453,7 +456,7 @@
       List<MaterialTransaction> transactionList2 = 
TestCostingUtils.getProductTransactions(product2
           .getId());
       List<ProductCostingAssert> productCostingAssertList2 = new 
ArrayList<ProductCostingAssert>();
-      productCostingAssertList2.add(new 
ProductCostingAssert(transactionList2.get(0), price10,
+      productCostingAssertList2.add(new 
ProductCostingAssert(transactionList2.get(0), price11,
           price10, price11, quantity1));
       TestCostingUtils.assertProductCosting(product2.getId(), 
productCostingAssertList2);
 
@@ -552,8 +555,9 @@
 
     try {
 
-      OBContext.setOBContext(TestCostingConstants.OPENBRAVO_USER_ID, 
TestCostingConstants.QATESTING_ROLE_ID,
-          TestCostingConstants.QATESTING_CLIENT_ID, 
TestCostingConstants.SPAIN_ORGANIZATION_ID);
+      OBContext.setOBContext(TestCostingConstants.OPENBRAVO_USER_ID,
+          TestCostingConstants.QATESTING_ROLE_ID, 
TestCostingConstants.QATESTING_CLIENT_ID,
+          TestCostingConstants.SPAIN_ORGANIZATION_ID);
       OBContext.setAdminMode(true);
 
       // Create a new product for the test
@@ -610,7 +614,7 @@
       List<MaterialTransaction> transactionList = 
TestCostingUtils.getProductTransactions(product
           .getId());
       List<ProductCostingAssert> productCostingAssertList1 = new 
ArrayList<ProductCostingAssert>();
-      productCostingAssertList1.add(new 
ProductCostingAssert(transactionList.get(0), price1,
+      productCostingAssertList1.add(new 
ProductCostingAssert(transactionList.get(0), price4,
           price1, price4, quantity1));
       TestCostingUtils.assertProductCosting(product.getId(), 
productCostingAssertList1);
 
@@ -650,8 +654,9 @@
 
     try {
 
-      OBContext.setOBContext(TestCostingConstants.OPENBRAVO_USER_ID, 
TestCostingConstants.QATESTING_ROLE_ID,
-          TestCostingConstants.QATESTING_CLIENT_ID, 
TestCostingConstants.SPAIN_ORGANIZATION_ID);
+      OBContext.setOBContext(TestCostingConstants.OPENBRAVO_USER_ID,
+          TestCostingConstants.QATESTING_ROLE_ID, 
TestCostingConstants.QATESTING_CLIENT_ID,
+          TestCostingConstants.SPAIN_ORGANIZATION_ID);
       OBContext.setAdminMode(true);
 
       // Create a new product for the test
@@ -688,7 +693,7 @@
       List<MaterialTransaction> transactionList = 
TestCostingUtils.getProductTransactions(product
           .getId());
       List<ProductCostingAssert> productCostingAssertList1 = new 
ArrayList<ProductCostingAssert>();
-      productCostingAssertList1.add(new 
ProductCostingAssert(transactionList.get(0), price1,
+      productCostingAssertList1.add(new 
ProductCostingAssert(transactionList.get(0), price4,
           price1, price4, quantity1));
       TestCostingUtils.assertProductCosting(product.getId(), 
productCostingAssertList1);
 
@@ -730,8 +735,9 @@
 
     try {
 
-      OBContext.setOBContext(TestCostingConstants.OPENBRAVO_USER_ID, 
TestCostingConstants.QATESTING_ROLE_ID,
-          TestCostingConstants.QATESTING_CLIENT_ID, 
TestCostingConstants.SPAIN_ORGANIZATION_ID);
+      OBContext.setOBContext(TestCostingConstants.OPENBRAVO_USER_ID,
+          TestCostingConstants.QATESTING_ROLE_ID, 
TestCostingConstants.QATESTING_CLIENT_ID,
+          TestCostingConstants.SPAIN_ORGANIZATION_ID);
       OBContext.setAdminMode(true);
 
       // Create a new product for the test
@@ -788,7 +794,7 @@
       List<MaterialTransaction> transactionList = 
TestCostingUtils.getProductTransactions(product
           .getId());
       List<ProductCostingAssert> productCostingAssertList1 = new 
ArrayList<ProductCostingAssert>();
-      productCostingAssertList1.add(new 
ProductCostingAssert(transactionList.get(0), price1,
+      productCostingAssertList1.add(new 
ProductCostingAssert(transactionList.get(0), price6,
           price1, price6, quantity1));
       TestCostingUtils.assertProductCosting(product.getId(), 
productCostingAssertList1);
 
@@ -830,8 +836,9 @@
 
     try {
 
-      OBContext.setOBContext(TestCostingConstants.OPENBRAVO_USER_ID, 
TestCostingConstants.QATESTING_ROLE_ID,
-          TestCostingConstants.QATESTING_CLIENT_ID, 
TestCostingConstants.SPAIN_ORGANIZATION_ID);
+      OBContext.setOBContext(TestCostingConstants.OPENBRAVO_USER_ID,
+          TestCostingConstants.QATESTING_ROLE_ID, 
TestCostingConstants.QATESTING_CLIENT_ID,
+          TestCostingConstants.SPAIN_ORGANIZATION_ID);
       OBContext.setAdminMode(true);
 
       // Create a new product for the test
@@ -888,7 +895,7 @@
       List<MaterialTransaction> transactionList = 
TestCostingUtils.getProductTransactions(product
           .getId());
       List<ProductCostingAssert> productCostingAssertList1 = new 
ArrayList<ProductCostingAssert>();
-      productCostingAssertList1.add(new 
ProductCostingAssert(transactionList.get(0), price1,
+      productCostingAssertList1.add(new 
ProductCostingAssert(transactionList.get(0), price6,
           price1, price6, quantity1));
       TestCostingUtils.assertProductCosting(product.getId(), 
productCostingAssertList1);
 
@@ -933,8 +940,9 @@
 
     try {
 
-      OBContext.setOBContext(TestCostingConstants.OPENBRAVO_USER_ID, 
TestCostingConstants.QATESTING_ROLE_ID,
-          TestCostingConstants.QATESTING_CLIENT_ID, 
TestCostingConstants.SPAIN_ORGANIZATION_ID);
+      OBContext.setOBContext(TestCostingConstants.OPENBRAVO_USER_ID,
+          TestCostingConstants.QATESTING_ROLE_ID, 
TestCostingConstants.QATESTING_CLIENT_ID,
+          TestCostingConstants.SPAIN_ORGANIZATION_ID);
       OBContext.setAdminMode(true);
 
       // Create a new product for the test
@@ -991,7 +999,7 @@
       List<MaterialTransaction> transactionList = 
TestCostingUtils.getProductTransactions(product
           .getId());
       List<ProductCostingAssert> productCostingAssertList1 = new 
ArrayList<ProductCostingAssert>();
-      productCostingAssertList1.add(new 
ProductCostingAssert(transactionList.get(0), price1,
+      productCostingAssertList1.add(new 
ProductCostingAssert(transactionList.get(0), price6,
           price1, price6, quantity1));
       TestCostingUtils.assertProductCosting(product.getId(), 
productCostingAssertList1);
 
@@ -1049,8 +1057,9 @@
 
     try {
 
-      OBContext.setOBContext(TestCostingConstants.OPENBRAVO_USER_ID, 
TestCostingConstants.QATESTING_ROLE_ID,
-          TestCostingConstants.QATESTING_CLIENT_ID, 
TestCostingConstants.SPAIN_ORGANIZATION_ID);
+      OBContext.setOBContext(TestCostingConstants.OPENBRAVO_USER_ID,
+          TestCostingConstants.QATESTING_ROLE_ID, 
TestCostingConstants.QATESTING_CLIENT_ID,
+          TestCostingConstants.SPAIN_ORGANIZATION_ID);
       OBContext.setAdminMode(true);
 
       // Create a new product for the test
@@ -1118,9 +1127,9 @@
       List<MaterialTransaction> transactionList = 
TestCostingUtils.getProductTransactions(product
           .getId());
       List<ProductCostingAssert> productCostingAssertList1 = new 
ArrayList<ProductCostingAssert>();
-      productCostingAssertList1.add(new 
ProductCostingAssert(transactionList.get(0), price1,
+      productCostingAssertList1.add(new 
ProductCostingAssert(transactionList.get(0), price5,
           price1, price5, quantity1));
-      productCostingAssertList1.add(new 
ProductCostingAssert(transactionList.get(1), price7, null,
+      productCostingAssertList1.add(new 
ProductCostingAssert(transactionList.get(1), price6, null,
           price7, quantity1.add(quantity3.negate())));
       TestCostingUtils.assertProductCosting(product.getId(), 
productCostingAssertList1);
 
@@ -1221,8 +1230,9 @@
 
     try {
 
-      OBContext.setOBContext(TestCostingConstants.OPENBRAVO_USER_ID, 
TestCostingConstants.QATESTING_ROLE_ID,
-          TestCostingConstants.QATESTING_CLIENT_ID, 
TestCostingConstants.SPAIN_ORGANIZATION_ID);
+      OBContext.setOBContext(TestCostingConstants.OPENBRAVO_USER_ID,
+          TestCostingConstants.QATESTING_ROLE_ID, 
TestCostingConstants.QATESTING_CLIENT_ID,
+          TestCostingConstants.SPAIN_ORGANIZATION_ID);
       OBContext.setAdminMode(true);
 
       // Create a new product for the test
@@ -1264,7 +1274,7 @@
       List<MaterialTransaction> transactionList1 = 
TestCostingUtils.getProductTransactions(product1
           .getId());
       List<ProductCostingAssert> productCostingAssertList1 = new 
ArrayList<ProductCostingAssert>();
-      productCostingAssertList1.add(new 
ProductCostingAssert(transactionList1.get(0), price1,
+      productCostingAssertList1.add(new 
ProductCostingAssert(transactionList1.get(0), price4,
           price1, price4, quantity1));
       TestCostingUtils.assertProductCosting(product1.getId(), 
productCostingAssertList1);
 
@@ -1319,8 +1329,9 @@
 
     try {
 
-      OBContext.setOBContext(TestCostingConstants.OPENBRAVO_USER_ID, 
TestCostingConstants.QATESTING_ROLE_ID,
-          TestCostingConstants.QATESTING_CLIENT_ID, 
TestCostingConstants.SPAIN_ORGANIZATION_ID);
+      OBContext.setOBContext(TestCostingConstants.OPENBRAVO_USER_ID,
+          TestCostingConstants.QATESTING_ROLE_ID, 
TestCostingConstants.QATESTING_CLIENT_ID,
+          TestCostingConstants.SPAIN_ORGANIZATION_ID);
       OBContext.setAdminMode(true);
 
       // Create a new product for the test
@@ -1377,7 +1388,7 @@
       List<MaterialTransaction> transactionList = 
TestCostingUtils.getProductTransactions(product
           .getId());
       List<ProductCostingAssert> productCostingAssertList1 = new 
ArrayList<ProductCostingAssert>();
-      productCostingAssertList1.add(new 
ProductCostingAssert(transactionList.get(0), price1,
+      productCostingAssertList1.add(new 
ProductCostingAssert(transactionList.get(0), price6,
           price1, price6, quantity1));
       TestCostingUtils.assertProductCosting(product.getId(), 
productCostingAssertList1);
 
@@ -1498,8 +1509,9 @@
 
     try {
 
-      OBContext.setOBContext(TestCostingConstants.OPENBRAVO_USER_ID, 
TestCostingConstants.QATESTING_ROLE_ID,
-          TestCostingConstants.QATESTING_CLIENT_ID, 
TestCostingConstants.SPAIN_ORGANIZATION_ID);
+      OBContext.setOBContext(TestCostingConstants.OPENBRAVO_USER_ID,
+          TestCostingConstants.QATESTING_ROLE_ID, 
TestCostingConstants.QATESTING_CLIENT_ID,
+          TestCostingConstants.SPAIN_ORGANIZATION_ID);
       OBContext.setAdminMode(true);
 
       // Create a new product for the test
@@ -1556,7 +1568,7 @@
       List<MaterialTransaction> transactionList = 
TestCostingUtils.getProductTransactions(product
           .getId());
       List<ProductCostingAssert> productCostingAssertList1 = new 
ArrayList<ProductCostingAssert>();
-      productCostingAssertList1.add(new 
ProductCostingAssert(transactionList.get(0), price1,
+      productCostingAssertList1.add(new 
ProductCostingAssert(transactionList.get(0), price6,
           price1, price6, quantity1));
       TestCostingUtils.assertProductCosting(product.getId(), 
productCostingAssertList1);
 
@@ -1618,7 +1630,7 @@
       List<MaterialTransaction> transactionList2 = 
TestCostingUtils.getProductTransactions(product
           .getId());
       List<ProductCostingAssert> productCostingAssertList2 = new 
ArrayList<ProductCostingAssert>();
-      productCostingAssertList2.add(new 
ProductCostingAssert(transactionList2.get(0), price1,
+      productCostingAssertList2.add(new 
ProductCostingAssert(transactionList2.get(0), price7,
           price1, price7, quantity1));
       TestCostingUtils.assertProductCosting(product.getId(), 
productCostingAssertList2);
 
@@ -1667,8 +1679,9 @@
 
     try {
 
-      OBContext.setOBContext(TestCostingConstants.OPENBRAVO_USER_ID, 
TestCostingConstants.QATESTING_ROLE_ID,
-          TestCostingConstants.QATESTING_CLIENT_ID, 
TestCostingConstants.SPAIN_ORGANIZATION_ID);

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Openbravo-commits mailing list
Openbravo-commits@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/openbravo-commits

Reply via email to