details:   https://code.openbravo.com/erp/devel/pi/rev/f4ae897ed38c
changeset: 32971:f4ae897ed38c
user:      Nono Carballo <nonofce <at> gmail.com>
date:      Wed Nov 08 11:51:54 2017 +0100
summary:   Related to Issue 37033. Added automated test cases

diffstat:

 src-test/src/org/openbravo/test/costing/TestCosting.java      |  334 +++++++++-
 src-test/src/org/openbravo/test/costing/TestCostingUtils.java |   90 ++
 2 files changed, 415 insertions(+), 9 deletions(-)

diffs (truncated from 511 to 300 lines):

diff -r 430d8de0bee8 -r f4ae897ed38c 
src-test/src/org/openbravo/test/costing/TestCosting.java
--- a/src-test/src/org/openbravo/test/costing/TestCosting.java  Wed Nov 08 
09:41:57 2017 +0100
+++ b/src-test/src/org/openbravo/test/costing/TestCosting.java  Wed Nov 08 
11:51:54 2017 +0100
@@ -41,7 +41,9 @@
 import org.hibernate.criterion.Restrictions;
 import org.junit.AfterClass;
 import org.junit.Before;
+import org.junit.FixMethodOrder;
 import org.junit.Test;
+import org.junit.runners.MethodSorters;
 import org.openbravo.base.exception.OBException;
 import org.openbravo.base.provider.OBProvider;
 import org.openbravo.base.secureApp.VariablesSecureApp;
@@ -135,6 +137,7 @@
  * @author aferraz
  */
 
+@FixMethodOrder(MethodSorters.NAME_ASCENDING)
 public class TestCosting extends WeldBaseTest {
 
   // User System
@@ -3445,7 +3448,8 @@
       // Create goods receipt, run costing background, post it and assert it
       ShipmentInOut goodsReceipt = createGoodsReceipt(purchaseOrder, price1, 
quantity1, day1);
 
-      // Create internal consumption, run costing background, post it and 
assert it
+      // Create internal consumption, run costing background, post it and 
assert
+      // it
       InternalConsumption internalConsumtpion = 
createInternalConsumption(product, price1,
           quantity2, day4);
 
@@ -3648,10 +3652,12 @@
       // Run price correction background
       runPriceBackground();
 
-      // Create return from customer, run costing background, post it and 
assert it
+      // Create return from customer, run costing background, post it and 
assert
+      // it
       Order returnFromCustomer = createReturnFromCustomer(goodsShipment, 
price2, quantity3, day3);
 
-      // Create return material receipt, run costing background, post it and 
assert it
+      // Create return material receipt, run costing background, post it and
+      // assert it
       ShipmentInOut returnMaterialReceipt = 
createReturnMaterialReceipt(returnFromCustomer, price3,
           quantity3, day4);
 
@@ -3740,7 +3746,8 @@
       // Create goods receipt, run costing background, post it and assert it
       ShipmentInOut goodsReceipt = createGoodsReceipt(purchaseOrder, price1, 
quantity1, day1);
 
-      // Create internal consumption, run costing background, post it and 
assert it
+      // Create internal consumption, run costing background, post it and 
assert
+      // it
       InternalConsumption internalConsumtpion = 
createInternalConsumption(product, price1,
           quantity2, day2);
 
@@ -4243,7 +4250,8 @@
       ShipmentInOut goodsReceipt2 = createGoodsReceipt(purchaseOrder2, price2, 
quantity4,
           LOCATOR4_ID, day2);
 
-      // Create bill of materials production, run costing background, post it 
and assert it
+      // Create bill of materials production, run costing background, post it 
and
+      // assert it
       ProductionTransaction billOfMaterialsProduction = 
createBillOfMaterialsProduction(product3,
           quantity5, LOCATOR1_ID, day3);
 
@@ -8532,6 +8540,310 @@
     }
   }
 
+  /**
+   * Test for issue 37033. Test Plan No. 1, No Cost Adjustment
+   * 
+   * <ul>
+   * <li>Create a product with purchase price 10.00</li>
+   * <li>Create and process a purchase order for one unit of product</li>
+   * <li>Create and process a goods receipt for one unit of product from 
purchase order</li>
+   * <li>Create an invoice from goods receipt</li>
+   * <li>Create a second invoice from same goods receipt</li>
+   * <li>Complete the second invoice</li>
+   * <li>Complete the first invoice</li>
+   * <li>Set "Enable Automatic Price Difference Correction" preference</li>
+   * <li>Run Costing Background process</li>
+   * <li>Asserts the original transaction cost is 10.00</li>
+   * <li>Asserts the total cost is 10.00</li>
+   * <li>Asserts the unit cost is 10.00</li>
+   * </ul>
+   */
+  @Test
+  public void testIssue37033_NoCostAdjustment() throws Exception {
+    try {
+      OBContext.setOBContext(USER_ID, ROLE_ID, CLIENT_ID, ORGANIZATION_ID);
+      OBContext.setAdminMode(true);
+
+      Product costingProduct = createProduct("product37033-A", new 
BigDecimal("10.00"));
+
+      Order purchaseOrder = createPurchaseOrder(costingProduct, new 
BigDecimal("10.00"),
+          BigDecimal.ONE, 0);
+      ShipmentInOut goodsReceipt = 
createMovementFromOrder(purchaseOrder.getId(), false,
+          BigDecimal.ONE, LOCATOR1_ID, 0);
+      completeDocument(goodsReceipt);
+
+      Invoice firstInvoice = createInvoiceFromMovement(goodsReceipt.getId(), 
false, new BigDecimal(
+          "10.00"), BigDecimal.ONE, 0);
+      Invoice secondInvoice = createInvoiceFromMovement(goodsReceipt.getId(), 
false,
+          new BigDecimal("10.00"), BigDecimal.ONE, 0);
+
+      secondInvoice = OBDal.getInstance().get(Invoice.class, 
secondInvoice.getId());
+      OBDal.getInstance().refresh(secondInvoice);
+      completeDocument(secondInvoice);
+
+      firstInvoice = OBDal.getInstance().get(Invoice.class, 
firstInvoice.getId());
+      OBDal.getInstance().refresh(firstInvoice);
+      completeDocument(firstInvoice);
+
+      TestCostingUtils.enableAutomaticPriceDifferenceCorrectionPreference();
+      runCostingBackground();
+      TestCostingUtils.disableAutomaticPriceDifferenceCorrectionPreference();
+
+      costingProduct = OBDal.getInstance().get(Product.class, 
costingProduct.getId());
+      OBDal.getInstance().refresh(costingProduct);
+
+      
TestCostingUtils.assertOriginalTotalAndUnitCostOfProductTransaction(costingProduct,
 10, 10,
+          10);
+
+    } catch (Exception e) {
+      System.out.println(e.getMessage());
+      throw new OBException(e);
+    } finally {
+      OBContext.restorePreviousMode();
+    }
+  }
+
+  /**
+   * Test for issue 37033. Test Plan No. 2, Cost adjustment to increase cost
+   * 
+   * <ul>
+   * <li>Create a product with purchase price 10.00</li>
+   * <li>Create and process a purchase order for one unit of product</li>
+   * <li>Create and process a goods receipt for one unit of product from 
purchase order</li>
+   * <li>Create an invoice from goods receipt</li>
+   * <li>Create a second invoice from same goods receipt</li>
+   * <li>Set unit price 20.00 in invoice line</li>
+   * <li>Complete the second invoice</li>
+   * <li>Complete the first invoice</li>
+   * <li>Set "Enable Automatic Price Difference Correction" preference</li>
+   * <li>Run Costing Background process</li>
+   * <li>Asserts the original transaction cost is 10.00</li>
+   * <li>Asserts the total cost is 15.00</li>
+   * <li>Asserts the unit cost is 15.00</li>
+   * </ul>
+   */
+  @Test
+  public void testIssue37033_CostAdjustmentToIncreaseCost() throws Exception {
+    try {
+      OBContext.setOBContext(USER_ID, ROLE_ID, CLIENT_ID, ORGANIZATION_ID);
+      OBContext.setAdminMode(true);
+
+      Product costingProduct = createProduct("product37033-B", new 
BigDecimal("10.00"));
+
+      Order purchaseOrder = createPurchaseOrder(costingProduct, new 
BigDecimal("10.00"),
+          BigDecimal.ONE, 0);
+      ShipmentInOut goodsReceipt = 
createMovementFromOrder(purchaseOrder.getId(), false,
+          BigDecimal.ONE, LOCATOR1_ID, 0);
+      completeDocument(goodsReceipt);
+
+      Invoice firstInvoice = createInvoiceFromMovement(goodsReceipt.getId(), 
false, new BigDecimal(
+          "10.00"), BigDecimal.ONE, 0);
+      Invoice secondInvoice = createInvoiceFromMovement(goodsReceipt.getId(), 
false,
+          new BigDecimal("20.00"), BigDecimal.ONE, 0);
+
+      secondInvoice = OBDal.getInstance().get(Invoice.class, 
secondInvoice.getId());
+      OBDal.getInstance().refresh(secondInvoice);
+      completeDocument(secondInvoice);
+
+      firstInvoice = OBDal.getInstance().get(Invoice.class, 
firstInvoice.getId());
+      OBDal.getInstance().refresh(firstInvoice);
+      completeDocument(firstInvoice);
+
+      TestCostingUtils.enableAutomaticPriceDifferenceCorrectionPreference();
+      runCostingBackground();
+      TestCostingUtils.disableAutomaticPriceDifferenceCorrectionPreference();
+
+      costingProduct = OBDal.getInstance().get(Product.class, 
costingProduct.getId());
+      OBDal.getInstance().refresh(costingProduct);
+
+      
TestCostingUtils.assertOriginalTotalAndUnitCostOfProductTransaction(costingProduct,
 10, 15,
+          15);
+
+    } catch (Exception e) {
+      System.out.println(e.getMessage());
+      throw new OBException(e);
+    } finally {
+      OBContext.restorePreviousMode();
+    }
+  }
+
+  /**
+   * Test for issue 37033. Test Plan No. 3, Cost adjustment to decrease cost
+   * 
+   * <ul>
+   * <li>Create a product with purchase price 10.00</li>
+   * <li>Create and process a purchase order for one unit of product</li>
+   * <li>Create and process a goods receipt for one unit of product from 
purchase order</li>
+   * <li>Create an invoice from goods receipt</li>
+   * <li>Create a second invoice from same goods receipt</li>
+   * <li>Set unit price 5.00 in invoice line</li>
+   * <li>Complete the second invoice</li>
+   * <li>Complete the first invoice</li>
+   * <li>Set "Enable Automatic Price Difference Correction" preference</li>
+   * <li>Run Costing Background process</li>
+   * <li>Asserts the original transaction cost is 10.00</li>
+   * <li>Asserts the total cost is 7.50</li>
+   * <li>Asserts the unit cost is 7.50</li>
+   * </ul>
+   */
+  @Test
+  public void testIssue37033_CostAdjustmentToDecreaseCost() throws Exception {
+    try {
+      OBContext.setOBContext(USER_ID, ROLE_ID, CLIENT_ID, ORGANIZATION_ID);
+      OBContext.setAdminMode(true);
+
+      Product costingProduct = createProduct("product37033-C", new 
BigDecimal("10.00"));
+
+      Order purchaseOrder = createPurchaseOrder(costingProduct, new 
BigDecimal("10.00"),
+          BigDecimal.ONE, 0);
+      ShipmentInOut goodsReceipt = 
createMovementFromOrder(purchaseOrder.getId(), false,
+          BigDecimal.ONE, LOCATOR1_ID, 0);
+      completeDocument(goodsReceipt);
+
+      Invoice firstInvoice = createInvoiceFromMovement(goodsReceipt.getId(), 
false, new BigDecimal(
+          "10.00"), BigDecimal.ONE, 0);
+      Invoice secondInvoice = createInvoiceFromMovement(goodsReceipt.getId(), 
false,
+          new BigDecimal("5.00"), BigDecimal.ONE, 0);
+
+      secondInvoice = OBDal.getInstance().get(Invoice.class, 
secondInvoice.getId());
+      OBDal.getInstance().refresh(secondInvoice);
+      completeDocument(secondInvoice);
+
+      firstInvoice = OBDal.getInstance().get(Invoice.class, 
firstInvoice.getId());
+      OBDal.getInstance().refresh(firstInvoice);
+      completeDocument(firstInvoice);
+
+      TestCostingUtils.enableAutomaticPriceDifferenceCorrectionPreference();
+      runCostingBackground();
+      TestCostingUtils.disableAutomaticPriceDifferenceCorrectionPreference();
+
+      costingProduct = OBDal.getInstance().get(Product.class, 
costingProduct.getId());
+      OBDal.getInstance().refresh(costingProduct);
+
+      
TestCostingUtils.assertOriginalTotalAndUnitCostOfProductTransaction(costingProduct,
 10, 7, 7);
+
+    } catch (Exception e) {
+      System.out.println(e.getMessage());
+      throw new OBException(e);
+    } finally {
+      OBContext.restorePreviousMode();
+    }
+  }
+
+  /**
+   * Test for issue 37033. Test Plan No. 4, Cost adjustment to increase cost 
with receipt partially
+   * invoiced
+   * 
+   * <ul>
+   * <li>Create a product with purchase price 10.00</li>
+   * <li>Create and process a purchase order for two unit of product</li>
+   * <li>Create and process a goods receipt for two unit of product from 
purchase order</li>
+   * <li>Create an invoice from goods receipt</li>
+   * <li>Set unit price 11.00 and quantity to 1 in invoice line</li>
+   * <li>Complete the invoice</li>
+   * <li>Set "Enable Automatic Price Difference Correction" preference</li>
+   * <li>Run Costing Background process</li>
+   * <li>Asserts the original transaction cost is 20.00</li>
+   * <li>Asserts the total cost is 21</li>
+   * <li>Asserts the unit cost is 21</li>
+   * </ul>
+   */
+  @Test
+  public void 
testIssue37033_CostAdjustmentToIncreaseCostWithReceiptPartiallyInvoiced()
+      throws Exception {
+    try {
+      OBContext.setOBContext(USER_ID, ROLE_ID, CLIENT_ID, ORGANIZATION_ID);
+      OBContext.setAdminMode(true);
+
+      Product costingProduct = createProduct("product37033-D", new 
BigDecimal("10.00"));
+
+      Order purchaseOrder = createPurchaseOrder(costingProduct, new 
BigDecimal("10.00"),
+          new BigDecimal("2"), 0);
+      ShipmentInOut goodsReceipt = 
createMovementFromOrder(purchaseOrder.getId(), false,
+          new BigDecimal("2"), LOCATOR1_ID, 0);
+      completeDocument(goodsReceipt);
+
+      Invoice purchaseInvoice = 
createInvoiceFromMovement(goodsReceipt.getId(), false,
+          new BigDecimal("11.00"), BigDecimal.ONE, 0);
+      
purchaseInvoice.getInvoiceLineList().get(0).setInvoicedQuantity(BigDecimal.ONE);
+      OBDal.getInstance().flush();
+      completeDocument(purchaseInvoice);
+
+      TestCostingUtils.enableAutomaticPriceDifferenceCorrectionPreference();

------------------------------------------------------------------------------
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