details: https://code.openbravo.com/erp/devel/pi/rev/6fc5c9829dff changeset: 33189:6fc5c9829dff user: David Miguelez <david.miguelez <at> openbravo.com> date: Mon Jan 15 12:58:08 2018 +0100 summary: Fixes Issue 37279. Corrects Transactions affected by Average cost adjustments
When a Cost Adjustment is created, some transactions are affected by this change For Average Cost adjustment, the transactions that modifies the average cost, but has used the actual average cost in it's calculation must be taken into account. details: https://code.openbravo.com/erp/devel/pi/rev/77e3e788178b changeset: 33190:77e3e788178b user: David Miguelez <david.miguelez <at> openbravo.com> date: Wed Jan 17 16:50:04 2018 +0100 summary: Related to Issue 37279. Fixes automated test after fixing issue: * Changed amounts of automated test LC3LC4 * Changed logic asserting the distributed amount of a Landed Cost between it's related Recipt lines * For each transacion it calculates it's cost as the original Transaction Cost plus the Cost of the previous Unit Cost adjustments * Reload and refresh the Landed Cost object when needed * Add isNeedPosting variable to costAdjustmentAssertLine and use it to check if a transaction has been posted or not details: https://code.openbravo.com/erp/devel/pi/rev/a773422cce1f changeset: 33191:a773422cce1f user: Nono Carballo <nonofce <at> gmail.com> date: Wed Jan 17 16:56:19 2018 +0100 summary: Added test for issue 32729 details: https://code.openbravo.com/erp/devel/pi/rev/7918fd33ee23 changeset: 33192:7918fd33ee23 user: David Miguelez <david.miguelez <at> openbravo.com> date: Wed Jan 17 17:05:17 2018 +0100 summary: Related to Issue 32729. Code Review changes Improvmentes in automated tests: * Set more meaningful names * Avoid Dal refresh when possible * Set final to parameters in methods when possible diffstat: src-test/src/org/openbravo/test/costing/TestCosting.java | 787 ++++++++++++-- src/org/openbravo/costing/AverageCostAdjustment.java | 55 + 2 files changed, 723 insertions(+), 119 deletions(-) diffs (truncated from 1219 to 300 lines): diff -r 120a6a75f9b7 -r 7918fd33ee23 src-test/src/org/openbravo/test/costing/TestCosting.java --- a/src-test/src/org/openbravo/test/costing/TestCosting.java Tue Jan 16 17:16:51 2018 +0100 +++ b/src-test/src/org/openbravo/test/costing/TestCosting.java Wed Jan 17 17:05:17 2018 +0100 @@ -19,8 +19,10 @@ package org.openbravo.test.costing; +import static org.hamcrest.Matchers.equalTo; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertThat; import static org.junit.Assert.assertTrue; import java.lang.reflect.Method; @@ -30,6 +32,7 @@ import java.util.ArrayList; import java.util.Calendar; import java.util.Collections; +import java.util.Comparator; import java.util.Date; import java.util.HashMap; import java.util.List; @@ -48,6 +51,7 @@ import org.openbravo.base.provider.OBProvider; import org.openbravo.base.secureApp.VariablesSecureApp; import org.openbravo.base.structure.BaseOBObject; +import org.openbravo.base.weld.WeldUtils; import org.openbravo.base.weld.test.WeldBaseTest; import org.openbravo.costing.CancelCostAdjustment; import org.openbravo.costing.CostingBackground; @@ -62,12 +66,14 @@ import org.openbravo.costing.ReactivateLandedCost; import org.openbravo.dal.core.DalUtil; import org.openbravo.dal.core.OBContext; +import org.openbravo.dal.core.SessionHandler; import org.openbravo.dal.service.OBCriteria; import org.openbravo.dal.service.OBDal; import org.openbravo.dal.service.OBQuery; import org.openbravo.database.ConnectionProvider; import org.openbravo.erpCommon.ad_forms.AcctServer; import org.openbravo.erpCommon.ad_process.VerifyBOM; +import org.openbravo.materialmgmt.InventoryCountProcess; import org.openbravo.model.ad.access.User; import org.openbravo.model.ad.datamodel.Table; import org.openbravo.model.ad.process.ProcessInstance; @@ -112,11 +118,13 @@ import org.openbravo.model.materialmgmt.cost.LandedCost; import org.openbravo.model.materialmgmt.cost.LandedCostCost; import org.openbravo.model.materialmgmt.cost.TransactionCost; +import org.openbravo.model.materialmgmt.onhandquantity.StorageDetail; import org.openbravo.model.materialmgmt.transaction.InternalConsumption; import org.openbravo.model.materialmgmt.transaction.InternalConsumptionLine; import org.openbravo.model.materialmgmt.transaction.InternalMovement; import org.openbravo.model.materialmgmt.transaction.InternalMovementLine; import org.openbravo.model.materialmgmt.transaction.InventoryCount; +import org.openbravo.model.materialmgmt.transaction.InventoryCountLine; import org.openbravo.model.materialmgmt.transaction.MaterialTransaction; import org.openbravo.model.materialmgmt.transaction.ProductionLine; import org.openbravo.model.materialmgmt.transaction.ProductionPlan; @@ -140,6 +148,9 @@ @FixMethodOrder(MethodSorters.NAME_ASCENDING) public class TestCosting extends WeldBaseTest { + private static final String INVENTORY_OPENING = "O"; + private static final String INVENTORY_NORMAL = "N"; + // User System private static String USERADMIN_ID = "0"; // User Openbravo @@ -230,6 +241,8 @@ private static String MOVEMENTIN_ID = "0450583047434254835B2B36B2E5B018"; // Goods Shipment with documentNo: 500014 private static String MOVEMENTOUT_ID = "2BCCC64DA82A48C3976B4D007315C2C9"; + // RTV Shipment doctype id + private static String RTV_SHIPMENT_DOCTYPE_ID = "4CBEA8CB77BB4208BCAD66235DC39AF2"; private static boolean runBefore = true; @@ -4743,21 +4756,19 @@ final BigDecimal price2 = new BigDecimal("110.00"); final BigDecimal price3 = new BigDecimal("1500.00"); final BigDecimal price4 = new BigDecimal("210.00"); - final BigDecimal price5 = new BigDecimal("130.00"); - final BigDecimal price6 = new BigDecimal("126.0936"); - final BigDecimal price7 = new BigDecimal("115.0600"); - final BigDecimal price8 = new BigDecimal("126.0933"); - final BigDecimal price9 = new BigDecimal("138.7029"); - final BigDecimal price10 = new BigDecimal("146.5664"); - final BigDecimal price11 = new BigDecimal("138.7030"); - final BigDecimal price12 = new BigDecimal("119.7281"); - final BigDecimal price13 = new BigDecimal("121.7382"); - final BigDecimal price14 = new BigDecimal("144.8463"); - final BigDecimal price15 = new BigDecimal("142.2134"); + final BigDecimal price5 = new BigDecimal("156.9044"); + final BigDecimal price6 = new BigDecimal("124.4582"); + final BigDecimal price7 = new BigDecimal("139.5180"); + final BigDecimal price8 = new BigDecimal("159.8375"); + final BigDecimal price9 = new BigDecimal("136.9043"); + final BigDecimal price10 = new BigDecimal("173.4708"); + final BigDecimal price11 = new BigDecimal("195.1500"); + final BigDecimal price12 = new BigDecimal("133.1465"); + final BigDecimal price13 = new BigDecimal("133.1467"); + final BigDecimal price14 = new BigDecimal("165.4719"); + final BigDecimal price15 = new BigDecimal("178.1911"); final BigDecimal price16 = new BigDecimal("84.9400"); final BigDecimal price17 = new BigDecimal("93.4338"); - final BigDecimal price18 = new BigDecimal("88.9665"); - final BigDecimal price19 = new BigDecimal("97.8632"); final BigDecimal quantity1 = new BigDecimal("11"); final BigDecimal quantity2 = new BigDecimal("7"); final BigDecimal quantity3 = new BigDecimal("15"); @@ -4767,6 +4778,24 @@ final BigDecimal quantity7 = BigDecimal.ONE; final BigDecimal quantity8 = new BigDecimal("3"); final BigDecimal amount1 = new BigDecimal("500"); + final BigDecimal unitPrice = new BigDecimal("124.4580"); + final BigDecimal unitPrice2 = new BigDecimal("133.1466"); + final BigDecimal unitPrice3 = new BigDecimal("156.9044"); + final BigDecimal unitPrice4 = new BigDecimal("165.4721"); + final BigDecimal costingAssertFinalCost = new BigDecimal("141.5753"); + final BigDecimal costAdjustmentAssertLineAmount = new BigDecimal("225.90"); + final BigDecimal costAdjustmentAssertLineAmount2 = new BigDecimal("284.98"); + final BigDecimal costAdjustmentAssertLineAmount3 = new BigDecimal("414.14"); + final BigDecimal costAdjustmentAssertLineAmount4 = new BigDecimal("708.19"); + final BigDecimal costAdjustmentAssertLineAmount5 = new BigDecimal("140.97"); + final BigDecimal costAdjustmentAssertLineAmount6 = new BigDecimal("112.78"); + final BigDecimal costAdjustmentAssertLineAmount7 = new BigDecimal("258.47"); + final BigDecimal costAdjustmentAssertLineAmount8 = new BigDecimal("248.14"); + final BigDecimal costAdjustmentAssertLineAmount9 = new BigDecimal("375.00"); + final BigDecimal costAdjustmentAssertLinePrice = new BigDecimal("90.6018"); + final BigDecimal costAdjustmentAssertLinePrice2 = new BigDecimal("99.6614"); + final BigDecimal costAdjustmentAssertLinePrice3 = new BigDecimal("88.3692"); + final BigDecimal costAdjustmentAssertLinePrice4 = new BigDecimal("96.8883"); final String costType = "AVA"; try { @@ -4845,10 +4874,10 @@ .get(0), price1, price6, price1)); productTransactionAssertList1.add(new ProductTransactionAssert(OBDal.getInstance() .get(ShipmentInOut.class, goodsReceipt12.getId()).getMaterialMgmtShipmentInOutLineList() - .get(0), price1, price7, price1)); + .get(0), price1, price7, unitPrice)); productTransactionAssertList1.add(new ProductTransactionAssert(OBDal.getInstance() .get(ShipmentInOut.class, goodsReceipt13.getId()).getMaterialMgmtShipmentInOutLineList() - .get(0), price1, price8, price1)); + .get(0), price1, price8, unitPrice2)); assertProductTransaction(product1.getId(), productTransactionAssertList1); // Assert product transactions 2 @@ -4858,10 +4887,10 @@ .get(0), price2, price9, price2)); productTransactionAssertList2.add(new ProductTransactionAssert(OBDal.getInstance() .get(ShipmentInOut.class, goodsReceipt22.getId()).getMaterialMgmtShipmentInOutLineList() - .get(0), price2, price10, price5)); + .get(0), price2, price10, unitPrice3)); productTransactionAssertList2.add(new ProductTransactionAssert(OBDal.getInstance() .get(ShipmentInOut.class, goodsReceipt23.getId()).getMaterialMgmtShipmentInOutLineList() - .get(0), price2, price11, price2)); + .get(0), price2, price11, unitPrice4)); assertProductTransaction(product2.getId(), productTransactionAssertList2); // Assert product costing 1 @@ -4870,11 +4899,11 @@ productCostingAssertList1.add(new ProductCostingAssert(null, null, null, price1, null, costType)); productCostingAssertList1.add(new ProductCostingAssert(transactionList1.get(0), price1, - price1, price6, quantity1)); - productCostingAssertList1.add(new ProductCostingAssert(transactionList1.get(1), price1, + price1, price6, quantity5)); + productCostingAssertList1.add(new ProductCostingAssert(transactionList1.get(1), unitPrice, price1, price12, quantity1.add(quantity3))); - productCostingAssertList1.add(new ProductCostingAssert(transactionList1.get(2), price1, - price1, price13, quantity1.add(quantity3).add(quantity5))); + productCostingAssertList1.add(new ProductCostingAssert(transactionList1.get(2), price13, + price1, costingAssertFinalCost, quantity1.add(quantity3).add(quantity5))); assertProductCosting(product1.getId(), productCostingAssertList1); // Assert product costing 2 @@ -4886,7 +4915,7 @@ price2, price9, quantity2)); productCostingAssertList2.add(new ProductCostingAssert(transactionList2.get(1), price5, price2, price14, quantity2.add(quantity4))); - productCostingAssertList2.add(new ProductCostingAssert(transactionList2.get(2), price2, + productCostingAssertList2.add(new ProductCostingAssert(transactionList2.get(2), unitPrice4, price2, price15, quantity2.add(quantity4).add(quantity6))); assertProductCosting(product2.getId(), productCostingAssertList2); @@ -4906,16 +4935,36 @@ quantity5.multiply(price1).add(quantity5.multiply(price16).negate()), day0, true, false)); costAdjustmentAssertLineList11.add(new CostAdjustmentAssert(transactionList2.get(2), "LC", quantity6.multiply(price2).add(quantity6.multiply(price17).negate()), day0, true, false)); + costAdjustmentAssertLineList11.add(new CostAdjustmentAssert(transactionList1.get(1), "LC", + costAdjustmentAssertLineAmount, day2, false, true, true)); + costAdjustmentAssertLineList11.add(new CostAdjustmentAssert(transactionList1.get(2), "LC", + costAdjustmentAssertLineAmount2, day3, false, true, true)); + costAdjustmentAssertLineList11.add(new CostAdjustmentAssert(transactionList2.get(1), "LC", + costAdjustmentAssertLineAmount3, day2, false, true, true)); + costAdjustmentAssertLineList11.add(new CostAdjustmentAssert(transactionList2.get(2), "LC", + costAdjustmentAssertLineAmount4, day3, false, true, true)); costAdjustmentAssertList1.add(costAdjustmentAssertLineList11); List<CostAdjustmentAssert> costAdjustmentAssertLineList12 = new ArrayList<CostAdjustmentAssert>(); costAdjustmentAssertLineList12.add(new CostAdjustmentAssert(transactionList1.get(0), "LC", - quantity1.multiply(price1).add(quantity1.multiply(price18).negate()), day5, true, false)); + quantity1.multiply(price1) + .add(quantity1.multiply(costAdjustmentAssertLinePrice).negate()), day5, true, false)); costAdjustmentAssertLineList12.add(new CostAdjustmentAssert(transactionList2.get(0), "LC", - quantity2.multiply(price2).add(quantity2.multiply(price19).negate()), day5, true, false)); + quantity2.multiply(price2).add( + quantity2.multiply(costAdjustmentAssertLinePrice2).negate()), day5, true, false)); costAdjustmentAssertLineList12.add(new CostAdjustmentAssert(transactionList1.get(2), "LC", - quantity5.multiply(price1).add(quantity5.multiply(price18).negate()), day5, true, false)); + quantity5.multiply(price1).add( + quantity5.multiply(costAdjustmentAssertLinePrice3).negate()), day5, true, false)); costAdjustmentAssertLineList12.add(new CostAdjustmentAssert(transactionList2.get(2), "LC", - quantity6.multiply(price2).add(quantity6.multiply(price19).negate()), day5, true, false)); + quantity6.multiply(price2).add( + quantity6.multiply(costAdjustmentAssertLinePrice4).negate()), day5, true, false)); + costAdjustmentAssertLineList12.add(new CostAdjustmentAssert(transactionList1.get(1), "LC", + costAdjustmentAssertLineAmount5, day5, false, true, true)); + costAdjustmentAssertLineList12.add(new CostAdjustmentAssert(transactionList1.get(2), "LC", + costAdjustmentAssertLineAmount6, day5, false, true, true)); + costAdjustmentAssertLineList12.add(new CostAdjustmentAssert(transactionList2.get(1), "LC", + costAdjustmentAssertLineAmount7, day5, false, true, true)); + costAdjustmentAssertLineList12.add(new CostAdjustmentAssert(transactionList2.get(2), "LC", + costAdjustmentAssertLineAmount8, day5, false, true, true)); costAdjustmentAssertList1.add(costAdjustmentAssertLineList12); assertCostAdjustment(costAdjustmentList1, costAdjustmentAssertList1); @@ -4935,20 +4984,42 @@ quantity5.multiply(price1).add(quantity5.multiply(price16).negate()), day0, true, false)); costAdjustmentAssertLineList21.add(new CostAdjustmentAssert(transactionList2.get(2), "LC", quantity6.multiply(price2).add(quantity6.multiply(price17).negate()), day0, true, false)); + costAdjustmentAssertLineList21.add(new CostAdjustmentAssert(transactionList1.get(1), "LC", + costAdjustmentAssertLineAmount, day2, false, true, true)); + costAdjustmentAssertLineList21.add(new CostAdjustmentAssert(transactionList1.get(2), "LC", + costAdjustmentAssertLineAmount2, day3, false, true, true)); + costAdjustmentAssertLineList21.add(new CostAdjustmentAssert(transactionList2.get(1), "LC", + costAdjustmentAssertLineAmount3, day2, false, true, true)); + costAdjustmentAssertLineList21.add(new CostAdjustmentAssert(transactionList2.get(2), "LC", + costAdjustmentAssertLineAmount4, day3, false, true, true)); costAdjustmentAssertList2.add(costAdjustmentAssertLineList21); List<CostAdjustmentAssert> costAdjustmentAssertLineList22 = new ArrayList<CostAdjustmentAssert>(); costAdjustmentAssertLineList22.add(new CostAdjustmentAssert(transactionList1.get(0), "LC", - quantity1.multiply(price1).add(quantity1.multiply(price18).negate()), day5, true, false)); + quantity1.multiply(price1) + .add(quantity1.multiply(costAdjustmentAssertLinePrice).negate()), day5, true, false)); costAdjustmentAssertLineList22.add(new CostAdjustmentAssert(transactionList2.get(0), "LC", - quantity2.multiply(price2).add(quantity2.multiply(price19).negate()), day5, true, false)); + quantity2.multiply(price2).add( + quantity2.multiply(costAdjustmentAssertLinePrice2).negate()), day5, true, false)); costAdjustmentAssertLineList22.add(new CostAdjustmentAssert(transactionList1.get(2), "LC", - quantity5.multiply(price1).add(quantity5.multiply(price18).negate()), day5, true, false)); + quantity5.multiply(price1).add( + quantity5.multiply(costAdjustmentAssertLinePrice3).negate()), day5, true, false)); costAdjustmentAssertLineList22.add(new CostAdjustmentAssert(transactionList2.get(2), "LC", - quantity6.multiply(price2).add(quantity6.multiply(price19).negate()), day5, true, false)); + quantity6.multiply(price2).add( + quantity6.multiply(costAdjustmentAssertLinePrice4).negate()), day5, true, false)); + costAdjustmentAssertLineList22.add(new CostAdjustmentAssert(transactionList1.get(1), "LC", + costAdjustmentAssertLineAmount5, day5, false, true, true)); + costAdjustmentAssertLineList22.add(new CostAdjustmentAssert(transactionList1.get(2), "LC", + costAdjustmentAssertLineAmount6, day5, false, true, true)); + costAdjustmentAssertLineList22.add(new CostAdjustmentAssert(transactionList2.get(1), "LC", + costAdjustmentAssertLineAmount7, day5, false, true, true)); + costAdjustmentAssertLineList22.add(new CostAdjustmentAssert(transactionList2.get(2), "LC", + costAdjustmentAssertLineAmount8, day5, false, true, true)); costAdjustmentAssertList2.add(costAdjustmentAssertLineList22); List<CostAdjustmentAssert> costAdjustmentAssertLineList23 = new ArrayList<CostAdjustmentAssert>(); costAdjustmentAssertLineList23.add(new CostAdjustmentAssert(transactionList2.get(1), "MCC", amount1, day6, true)); + costAdjustmentAssertLineList23.add(new CostAdjustmentAssert(transactionList2.get(2), "MCC", + costAdjustmentAssertLineAmount9, day6, false)); costAdjustmentAssertList2.add(costAdjustmentAssertLineList23); assertCostAdjustment(costAdjustmentList2, costAdjustmentAssertList2); @@ -4957,6 +5028,10 @@ List<DocumentPostAssert> documentPostAssertList1 = new ArrayList<DocumentPostAssert>(); documentPostAssertList1.add(new DocumentPostAssert("61000", BigDecimal.ZERO, amount1, null)); documentPostAssertList1.add(new DocumentPostAssert("35000", amount1, BigDecimal.ZERO, null)); + documentPostAssertList1.add(new DocumentPostAssert("61000", BigDecimal.ZERO, + costAdjustmentAssertLineAmount9, null)); + documentPostAssertList1.add(new DocumentPostAssert("35000", costAdjustmentAssertLineAmount9, + BigDecimal.ZERO, null)); CostAdjustment costAdjustment1 = OBDal.getInstance().get(CostAdjustment.class, costAdjustmentList2.get(2).getId()); assertDocumentPost(costAdjustment1, product2.getId(), documentPostAssertList1); @@ -8844,6 +8919,306 @@ } } + /** + * Test Price Difference Adjustment with a Goods Receipt not related to a Purchase Order + * + * <ul> + * <li>Create a new product with purchase price list of 3.00</li> + * <li>Create and book a Purchase Order for 1 unit of product</li> + * <li>Create and complete a Goods Receipt based on previous Purchase Order</li> + * <li>Run Costing Background Process</li> + * <li>Create and complete a new Goods Receipt for 10 units of product</li> + * <li>Run Costing Background Process</li> ------------------------------------------------------------------------------ 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