details: https://code.openbravo.com/erp/devel/pi/rev/de2414ba5379 changeset: 33429:de2414ba5379 user: Víctor Martínez Romanos <victor.martinez <at> openbravo.com> date: Mon Feb 12 15:19:05 2018 +0100 summary: Fixed issue 37827: [ri] Reservation Management Refactor
Removed new reservation management initially implemented for Referenced Inventory, and adapted the Core's engine to work with RI. M_Movement_Post: 1. The new storage detail passed to the M_RESERVE_STOCK_MANUAL takes into account the new m_attributesetinstanceto_id 2. The check for unique bin in referenced inventory is only executed for RI movement, thus improving performance M_RESERVE_STOCK_MANUAL: 1. The code that gets the storage detail is able to work with reference inventory ReferencedInventoryProcessor: 1. Removed ReservationManager stuff as it is now directly executed in the existing Core's code 2. The movement lines are created in 2 steps: first without reservation and, if necessary, moving reservations. 3. Some util methods are moved to ReferencedInventoryUtil class. Automatic tests modifications to adapt to new logic: 1. Now we always work in just one reservation, and we don't create a new one releasing from the existing one anymore. 2. The goods movement might create several lines (depending on reservation quantities) 3. Split some tests to make them more readable details: https://code.openbravo.com/erp/devel/pi/rev/e9356b180aac changeset: 33430:e9356b180aac user: Víctor Martínez Romanos <victor.martinez <at> openbravo.com> date: Mon Feb 12 19:29:47 2018 +0100 summary: Fixed issue 37827: [ri] declare method as public to be used by AWO diffstat: src-db/database/model/functions/M_MOVEMENT_POST.xml | 52 +- src-db/database/model/functions/M_RESERVE_STOCK_MANUAL.xml | 4 +- src-test/src/org/openbravo/test/referencedinventory/ReferencedInventoryBoxForcedReservation.java | 24 +- src-test/src/org/openbravo/test/referencedinventory/ReferencedInventoryBoxOverReservation1MovementLineTest.java | 59 ++ src-test/src/org/openbravo/test/referencedinventory/ReferencedInventoryBoxOverReservation2MovementLinesTest.java | 67 ++ src-test/src/org/openbravo/test/referencedinventory/ReferencedInventoryBoxOverReservationTest.java | 60 -- src-test/src/org/openbravo/test/referencedinventory/ReferencedInventoryBoxPartialReservation1MovementLineTest.java | 56 ++ src-test/src/org/openbravo/test/referencedinventory/ReferencedInventoryBoxPartialReservation2MovementLinesTest.java | 67 ++ src-test/src/org/openbravo/test/referencedinventory/ReferencedInventoryBoxPartialReservationTest.java | 55 -- src-test/src/org/openbravo/test/referencedinventory/ReferencedInventoryBoxTest.java | 24 +- src-test/src/org/openbravo/test/referencedinventory/ReferencedInventoryFullUnboxPartialReservation.java | 16 +- src-test/src/org/openbravo/test/referencedinventory/ReferencedInventoryPartialUnboxPartialReservation.java | 66 -- src-test/src/org/openbravo/test/referencedinventory/ReferencedInventoryPartialUnboxPartialReservation1MovementLineUnboxTest.java | 80 +++ src-test/src/org/openbravo/test/referencedinventory/ReferencedInventoryPartialUnboxPartialReservation2MovementLinesUnboxTest.java | 73 ++ src-test/src/org/openbravo/test/referencedinventory/ReferencedInventoryTestSuite.java | 9 +- src/org/openbravo/materialmgmt/refinventory/ReferencedInventoryProcessor.java | 154 +++-- src/org/openbravo/materialmgmt/refinventory/ReferencedInventoryUtil.java | 77 +++ src/org/openbravo/materialmgmt/refinventory/ReservationManager.java | 253 ---------- 18 files changed, 642 insertions(+), 554 deletions(-) diffs (truncated from 1489 to 300 lines): diff -r 2ae5f4a8e8da -r e9356b180aac src-db/database/model/functions/M_MOVEMENT_POST.xml --- a/src-db/database/model/functions/M_MOVEMENT_POST.xml Wed Feb 14 09:40:23 2018 +0100 +++ b/src-db/database/model/functions/M_MOVEMENT_POST.xml Mon Feb 12 19:29:47 2018 +0100 @@ -19,7 +19,7 @@ * parts created by ComPiere are Copyright (C) ComPiere, Inc.; * All Rights Reserved. * Contributor(s): Openbravo SLU - * Contributions are Copyright (C) 2001-2017 Openbravo, S.L.U. + * Contributions are Copyright (C) 2001-2018 Openbravo, S.L.U. * * Specifically, this derivative work is based upon the following Compiere * file and version. @@ -60,6 +60,7 @@ v_refInventoryId M_AttributeSetInstance.M_REFINVENTORY_ID%TYPE; v_refInvValue M_REFINVENTORY.VALUE%TYPE; v_locatorValue M_LOCATOR.VALUE%TYPE; + v_isRefInventoryMovement CHAR(1); BEGIN -- Update AD_PInstance DBMS_OUTPUT.PUT_LINE('Updating PInstance - Processing ' || PInstance_ID) ; @@ -235,7 +236,7 @@ FROM m_storage_detail WHERE m_product_id = cur_moveline.m_product_id AND m_locator_id = cur_moveline.m_locatorto_id - AND m_attributesetinstance_id = COALESCE(cur_moveline.m_attributesetinstance_id, '0') + AND m_attributesetinstance_id = COALESCE(cur_moveline.m_attributesetinstanceto_id, cur_moveline.m_attributesetinstance_id, '0') AND m_product_uom_id IS NULL; v_reservedqty := cur_moveline.movementqty; FOR cur_res_stock IN ( @@ -312,28 +313,31 @@ --It has been validated before that the quantity to be moved is positive or that the locator to allows negative stock --If the Locator to has already negative stock before this transaction, the goods movement should not be stopped - -- Linked Referenced Inventory must be in just one locator - SELECT M_REFINVENTORY_ID INTO v_refInventoryId - FROM M_AttributeSetInstance - WHERE M_AttributeSetInstance_ID = COALESCE(Cur_MoveLine.M_AttributeSetInstanceTo_ID, Cur_MoveLine.M_AttributeSetInstance_ID, '0'); - IF (v_refInventoryId IS NOT NULL) THEN - BEGIN - SELECT M_REFINVENTORY.VALUE, M_LOCATOR.VALUE - INTO v_refInvValue, v_locatorValue - FROM M_STORAGE_DETAIL - JOIN M_LOCATOR on (M_STORAGE_DETAIL.M_LOCATOR_ID = M_LOCATOR.M_LOCATOR_ID) - JOIN M_REFINVENTORY on (M_STORAGE_DETAIL.M_REFINVENTORY_ID = M_REFINVENTORY.M_REFINVENTORY_ID) - WHERE M_STORAGE_DETAIL.M_REFINVENTORY_ID = v_refInventoryId - AND M_STORAGE_DETAIL.QTYONHAND > 0 - AND M_STORAGE_DETAIL.M_LOCATOR_ID <> Cur_MoveLine.M_LocatorTo_ID; - IF (v_locatorValue IS NOT NULL) THEN - RAISE_APPLICATION_ERROR(-20000, v_refInvValue || '@ReferencedInventoryInOtherBin@' || v_locatorValue) ; - END IF; - EXCEPTION - WHEN NO_DATA_FOUND THEN - v_locatorValue:=null; -- Hack for Oracle to control exception - END; - END IF; + v_isRefInventoryMovement:=CASE WHEN Cur_MoveLine.M_AttributeSetInstanceTo_ID IS NOT NULL AND COALESCE(cur_moveline.m_attributesetinstance_id, '0') <> Cur_MoveLine.M_AttributeSetInstanceTo_ID THEN 'Y' ELSE 'N' END; + IF (v_isRefInventoryMovement='Y') THEN -- Referenced Inventory + -- Linked Referenced Inventory must be in just one locator + SELECT M_REFINVENTORY_ID INTO v_refInventoryId + FROM M_AttributeSetInstance + WHERE M_AttributeSetInstance_ID = COALESCE(Cur_MoveLine.M_AttributeSetInstanceTo_ID, Cur_MoveLine.M_AttributeSetInstance_ID, '0'); + IF (v_refInventoryId IS NOT NULL) THEN + BEGIN + SELECT M_REFINVENTORY.VALUE, M_LOCATOR.VALUE + INTO v_refInvValue, v_locatorValue + FROM M_STORAGE_DETAIL + JOIN M_LOCATOR on (M_STORAGE_DETAIL.M_LOCATOR_ID = M_LOCATOR.M_LOCATOR_ID) + JOIN M_REFINVENTORY on (M_STORAGE_DETAIL.M_REFINVENTORY_ID = M_REFINVENTORY.M_REFINVENTORY_ID) + WHERE M_STORAGE_DETAIL.M_REFINVENTORY_ID = v_refInventoryId + AND M_STORAGE_DETAIL.QTYONHAND > 0 + AND M_STORAGE_DETAIL.M_LOCATOR_ID <> Cur_MoveLine.M_LocatorTo_ID; + IF (v_locatorValue IS NOT NULL) THEN + RAISE_APPLICATION_ERROR(-20000, v_refInvValue || '@ReferencedInventoryInOtherBin@' || v_locatorValue) ; + END IF; + EXCEPTION + WHEN NO_DATA_FOUND THEN + v_locatorValue:=null; -- Hack for Oracle to control exception + END; + END IF; + END IF; -- Referenced Inventory END LOOP; END; -- FOR COMMIT END IF;--END_PROCESS diff -r 2ae5f4a8e8da -r e9356b180aac src-db/database/model/functions/M_RESERVE_STOCK_MANUAL.xml --- a/src-db/database/model/functions/M_RESERVE_STOCK_MANUAL.xml Wed Feb 14 09:40:23 2018 +0100 +++ b/src-db/database/model/functions/M_RESERVE_STOCK_MANUAL.xml Mon Feb 12 19:29:47 2018 +0100 @@ -34,7 +34,7 @@ * under the License. * The Original Code is Openbravo ERP. * The Initial Developer of the Original Code is Openbravo SLU -* All portions are Copyright (C) 2012-2016 Openbravo SLU +* All portions are Copyright (C) 2012-2018 Openbravo SLU * All Rights Reserved. * Contributor(s): ______________________________________. ************************************************************************/ @@ -72,7 +72,7 @@ JOIN m_reservation res ON res.m_reservation_id = p_reservation_id WHERE sd.m_storage_detail_id = p_stock_id AND sd.m_product_id = res.m_product_id - AND sd.m_attributesetinstance_id = COALESCE(res.m_attributesetinstance_id, sd.m_attributesetinstance_id) + AND sd.m_attributesetinstance_id = CASE WHEN sd.M_REFINVENTORY_ID IS NULL THEN COALESCE(res.m_attributesetinstance_id, sd.m_attributesetinstance_id) ELSE COALESCE(sd.m_attributesetinstance_id, res.m_attributesetinstance_id) END AND sd.m_locator_id = COALESCE(res.m_locator_id, sd.m_locator_id) AND loc.m_warehouse_id = COALESCE(res.m_warehouse_id, loc.m_warehouse_id); IF (v_count = 0) THEN diff -r 2ae5f4a8e8da -r e9356b180aac src-test/src/org/openbravo/test/referencedinventory/ReferencedInventoryBoxForcedReservation.java --- a/src-test/src/org/openbravo/test/referencedinventory/ReferencedInventoryBoxForcedReservation.java Wed Feb 14 09:40:23 2018 +0100 +++ b/src-test/src/org/openbravo/test/referencedinventory/ReferencedInventoryBoxForcedReservation.java Mon Feb 12 19:29:47 2018 +0100 @@ -71,7 +71,7 @@ } final ReferencedInventory refInv = testBox(BINS[0], product[0], product[1], params.qtyToBox, params.reservationQty, isAllocated, isForceBin, isForceAttribute); - assertsReservations(refInv, isForceBin, isForceAttribute); + assertsReservation(refInv, isForceBin, isForceAttribute); OBDal.getInstance().getSession().clear(); } } @@ -103,7 +103,7 @@ true, true); } - private void assertsReservations(final ReferencedInventory refInv, boolean isForceBin, + private void assertsReservation(final ReferencedInventory refInv, boolean isForceBin, boolean isForceAttribute) { final OBCriteria<Reservation> crit = OBDao.getFilteredCriteria( Reservation.class, @@ -117,19 +117,13 @@ } crit.addOrderBy(Reservation.PROPERTY_RESSTATUS, true); final List<Reservation> reservations = crit.list(); - assertThat("Two reservations must be found", reservations.size(), equalTo(2)); + assertThat("One reservation must be found", reservations.size(), equalTo(1)); - int i = 0; - for (Reservation reservation : reservations) { - if (i == 0) { - assertThat("First reservation must be closed", reservation.getRESStatus(), equalTo("CL")); - } else { - assertThat("Second reservation must be completed", reservation.getRESStatus(), - equalTo("CO")); - } - ReferencedInventoryTestUtils.assertsReservationHeader(isForceBin, isForceAttribute, - reservation); - i++; - } + final Reservation reservation = reservations.get(0); + assertThat("Reservation must be completed", reservation.getRESStatus(), equalTo("CO")); + ReferencedInventoryTestUtils + .assertsReservationHeader(isForceBin, isForceAttribute, reservation); + assertThat("Reservation must have 1 line", reservation.getMaterialMgmtReservationStockList() + .size(), equalTo(1)); } } diff -r 2ae5f4a8e8da -r e9356b180aac src-test/src/org/openbravo/test/referencedinventory/ReferencedInventoryBoxOverReservation1MovementLineTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src-test/src/org/openbravo/test/referencedinventory/ReferencedInventoryBoxOverReservation1MovementLineTest.java Mon Feb 12 19:29:47 2018 +0100 @@ -0,0 +1,59 @@ +/* + ************************************************************************* + * The contents of this file are subject to the Openbravo Public License + * Version 1.1 (the "License"), being the Mozilla Public License + * Version 1.1 with a permitted attribution clause; you may not use this + * file except in compliance with the License. You may obtain a copy of + * the License at http://www.openbravo.com/legal/license.html + * Software distributed under the License is distributed on an "AS IS" + * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the + * License for the specific language governing rights and limitations + * under the License. + * The Original Code is Openbravo ERP. + * The Initial Developer of the Original Code is Openbravo SLU + * All portions are Copyright (C) 2018 Openbravo SLU + * All Rights Reserved. + * Contributor(s): ______________________________________. + ************************************************************************ + */ + +package org.openbravo.test.referencedinventory; + +import java.util.Arrays; + +import org.junit.Rule; +import org.junit.Test; +import org.openbravo.base.weld.test.ParameterCdiTest; +import org.openbravo.base.weld.test.ParameterCdiTestRule; +import org.openbravo.dal.service.OBDal; + +/** + * Box storage details that are over reserved (allocated and non-allocated reservation). The box + * movement will only have 1 line. + */ +public class ReferencedInventoryBoxOverReservation1MovementLineTest extends + ReferencedInventoryBoxTest { + + @Rule + public ParameterCdiTestRule<ParamsBoxReservationTest> parameterValuesRule = new ParameterCdiTestRule<ParamsBoxReservationTest>( + Arrays.asList(new ParamsBoxReservationTest[] { + new ParamsBoxReservationTest("Box 3 units where 5 where reserved (over reservation)", + "3", "5"), + new ParamsBoxReservationTest("Box 4 units where 10 where reserved (over reservation)", + "4", "10") })); + + private @ParameterCdiTest ParamsBoxReservationTest params; + + @Test + public void allTests() throws Exception { + for (boolean isAllocated : ISALLOCATED) { + for (String[] product : PRODUCTS) { + for (String toBinId : BINS) { + testBox(toBinId, product[0], product[1], params.qtyToBox, params.reservationQty, + isAllocated); + OBDal.getInstance().getSession().clear(); + } + } + } + } +} diff -r 2ae5f4a8e8da -r e9356b180aac src-test/src/org/openbravo/test/referencedinventory/ReferencedInventoryBoxOverReservation2MovementLinesTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src-test/src/org/openbravo/test/referencedinventory/ReferencedInventoryBoxOverReservation2MovementLinesTest.java Mon Feb 12 19:29:47 2018 +0100 @@ -0,0 +1,67 @@ +/* + ************************************************************************* + * The contents of this file are subject to the Openbravo Public License + * Version 1.1 (the "License"), being the Mozilla Public License + * Version 1.1 with a permitted attribution clause; you may not use this + * file except in compliance with the License. You may obtain a copy of + * the License at http://www.openbravo.com/legal/license.html + * Software distributed under the License is distributed on an "AS IS" + * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the + * License for the specific language governing rights and limitations + * under the License. + * The Original Code is Openbravo ERP. + * The Initial Developer of the Original Code is Openbravo SLU + * All portions are Copyright (C) 2018 Openbravo SLU + * All Rights Reserved. + * Contributor(s): ______________________________________. + ************************************************************************ + */ + +package org.openbravo.test.referencedinventory; + +import static org.hamcrest.Matchers.equalTo; +import static org.junit.Assert.assertThat; + +import java.util.Arrays; + +import org.junit.Rule; +import org.junit.Test; +import org.openbravo.base.weld.test.ParameterCdiTest; +import org.openbravo.base.weld.test.ParameterCdiTestRule; +import org.openbravo.dal.service.OBDal; +import org.openbravo.model.materialmgmt.transaction.InternalMovement; + +/** + * Box storage details that are over reserved (allocated and non-allocated reservation). The box + * movement will only have 2 lines. + */ +public class ReferencedInventoryBoxOverReservation2MovementLinesTest extends + ReferencedInventoryBoxTest { + + @Rule + public ParameterCdiTestRule<ParamsBoxReservationTest> parameterValuesRule = new ParameterCdiTestRule<ParamsBoxReservationTest>( + Arrays.asList(new ParamsBoxReservationTest[] { new ParamsBoxReservationTest( + "Box 4 units where 9 where reserved (over reservation)", "4", "9") })); + + private @ParameterCdiTest ParamsBoxReservationTest params; + + @Test + public void allTests() throws Exception { + for (boolean isAllocated : ISALLOCATED) { + for (String[] product : PRODUCTS) { + for (String toBinId : BINS) { + testBox(toBinId, product[0], product[1], params.qtyToBox, params.reservationQty, + isAllocated); + OBDal.getInstance().getSession().clear(); + } + } + } + } + + @Override + void assertsGoodsMovementNumberOfLines(final InternalMovement boxMovement, + final int expectedNumberOfLines) { + assertThat("Box Movement has two line", boxMovement.getMaterialMgmtInternalMovementLineList() + .size(), equalTo(2)); + } +} diff -r 2ae5f4a8e8da -r e9356b180aac src-test/src/org/openbravo/test/referencedinventory/ReferencedInventoryBoxOverReservationTest.java --- a/src-test/src/org/openbravo/test/referencedinventory/ReferencedInventoryBoxOverReservationTest.java Wed Feb 14 09:40:23 2018 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,60 +0,0 @@ -/* - ************************************************************************* - * The contents of this file are subject to the Openbravo Public License - * Version 1.1 (the "License"), being the Mozilla Public License - * Version 1.1 with a permitted attribution clause; you may not use this - * file except in compliance with the License. You may obtain a copy of - * the License at http://www.openbravo.com/legal/license.html - * Software distributed under the License is distributed on an "AS IS" - * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the - * License for the specific language governing rights and limitations ------------------------------------------------------------------------------ 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