Skip to content

Commit

Permalink
make M_Locator.Value unique + div small fixes wrt inventory importing
Browse files Browse the repository at this point in the history
  • Loading branch information
metas-ts committed Jan 5, 2021
1 parent 231d1be commit 521c419
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -624,6 +624,7 @@ public final Map<String, Object> getParameters()
* Ask the exception to also include the parameters in it's message.
*/
@OverridingMethodsMustInvokeSuper
@NonNull
public AdempiereException appendParametersToMessage()
{
if (!appendParametersToMessage)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@

-- change and rename this index to be useful in finding locators via their coordinates
drop index if exists m_location_where;
drop index if exists m_locator_where;
CREATE INDEX m_locator_where
ON m_locator (x, y, z, x1, m_warehouse_id);

-- creating this index to make sure that M_Location.Value is unique.
-- we need this because the inventory import feature depends on it.
-- if this fails on a given DB, then rename and/or deactivate the double locator(s)
drop index if exists m_locator_value;
CREATE UNIQUE INDEX m_locator_value ON m_locator (value, m_warehouse_id) where isactive='Y';
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,12 @@
* it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 2 of the
* License, or (at your option) any later version.
*
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*
* You should have received a copy of the GNU General Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/gpl-2.0.html>.
Expand Down Expand Up @@ -103,9 +103,22 @@ public void execute()
continue;
}

executeForInventoryLine(inventoryLine);
}
}

private void executeForInventoryLine(final InventoryLine inventoryLine)
{
try
{
final InventoryLine resultingInventoryLine = syncQtyFromInventoryLineToHUs(inventoryLine);
transferAttributesToHUs(resultingInventoryLine);
}
catch (final RuntimeException e)
{
throw AdempiereException.wrapIfNeeded(e).appendParametersToMessage()
.setParameter("inventoryLine", inventoryLine);
}
}

private void transferAttributesToHUs(final InventoryLine inventoryLine)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,26 +144,26 @@ public IHUStorage getParentStorage()
}

@Override
public void addQty(final ProductId productId, final BigDecimal qty, final I_C_UOM uom)
public void addQty(@NonNull final ProductId productId, @NonNull final BigDecimal qtyToAdd, @NonNull final I_C_UOM uom)
{
// NOTE: we allow to add/remove qty even if HU Item is not of type Material
// because rollupIncremental is updating the storage on all levels

if (qty.signum() == 0)
if (qtyToAdd.signum() == 0)
{
return;
}

final I_M_HU_Item_Storage storageLine = getCreateStorageLine(productId, uom);

final I_C_UOM uomStorage = extractUOM(storageLine);
final BigDecimal qtyConv = uomConversionBL.convertQty(productId, qty, uom, uomStorage);
final BigDecimal qtyConv = uomConversionBL.convertQty(productId, qtyToAdd, uom, uomStorage);
//
// Update storage line
final BigDecimal qtyOld = storageLine.getQty();
final BigDecimal qtyNew = qtyOld.add(qtyConv);

Check.errorIf(qtyNew.signum() < 0, "Attempt to set negative qty on storageLine; qty={}; qtyNew={}; qtyOld={}; this={}; storageLine={}", qty, qtyNew, qtyOld, this, storageLine);
Check.errorIf(qtyNew.signum() < 0, "Attempt to set negative qty on storageLine; qtyOld={}; qtyToAdd={}; qtyNew={}; this={}; storageLine={}", qtyOld, qtyToAdd, qtyNew, this, storageLine);

storageLine.setQty(qtyNew);
dao.save(storageLine);
Expand Down

0 comments on commit 521c419

Please sign in to comment.