Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
2 changed files
with
122 additions
and
76 deletions.
There are no files selected for viewing
116 changes: 116 additions & 0 deletions
116
de.metas.business/src/main/java/de/metas/replenishment/impexp/ReplenishImportHelper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
/** | ||
* | ||
*/ | ||
package de.metas.replenishment.impexp; | ||
|
||
import org.adempiere.model.InterfaceWrapperHelper; | ||
import org.compiere.model.I_I_Replenish; | ||
import org.compiere.model.I_M_Replenish; | ||
|
||
import de.metas.util.Check; | ||
import lombok.NonNull; | ||
import lombok.experimental.UtilityClass; | ||
|
||
/* | ||
* #%L | ||
* de.metas.business | ||
* %% | ||
* Copyright (C) 2019 metas GmbH | ||
* %% | ||
* This program is free software: you can redistribute it and/or modify | ||
* 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>. | ||
* #L% | ||
*/ | ||
|
||
/** | ||
* @author metas-dev <dev@metasfresh.com> | ||
* | ||
*/ | ||
@UtilityClass | ||
/* package */ class ReplenishImportHelper | ||
{ | ||
final public boolean isValidRecordForImport(@NonNull final I_I_Replenish importRecord) | ||
{ | ||
if (importRecord.getM_Product_ID() <= 0) | ||
{ | ||
return false; | ||
} | ||
|
||
if (importRecord.getM_Warehouse_ID() <= 0) | ||
{ | ||
return false; | ||
} | ||
|
||
if (importRecord.getLevel_Max() == null) | ||
{ | ||
return false; | ||
} | ||
|
||
if (importRecord.getLevel_Min() == null) | ||
{ | ||
return false; | ||
} | ||
|
||
if (Check.isEmpty(importRecord.getReplenishType(), true)) | ||
{ | ||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
|
||
final public I_M_Replenish createNewReplenish(@NonNull final I_I_Replenish importRecord) | ||
{ | ||
final I_M_Replenish replenish = InterfaceWrapperHelper.newInstance(I_M_Replenish.class, importRecord); | ||
setReplenishmenttValueFields(importRecord, replenish); | ||
return replenish; | ||
} | ||
|
||
final public I_M_Replenish uppdateReplenish(@NonNull final I_I_Replenish importRecord) | ||
{ | ||
final I_M_Replenish replenish = InterfaceWrapperHelper.newInstance(I_M_Replenish.class, importRecord); | ||
setReplenishmenttValueFields(importRecord, replenish); | ||
return replenish; | ||
} | ||
|
||
private void setReplenishmenttValueFields(@NonNull final I_I_Replenish importRecord, @NonNull final I_M_Replenish replenish) | ||
{ | ||
// mandatory fields | ||
replenish.setM_Product_ID(importRecord.getM_Product_ID()); | ||
replenish.setM_Warehouse_ID(importRecord.getM_Warehouse_ID()); | ||
replenish.setLevel_Max(importRecord.getLevel_Max()); | ||
replenish.setLevel_Min(importRecord.getLevel_Min()); | ||
replenish.setReplenishType(importRecord.getReplenishType()); | ||
replenish.setTimeToMarket(importRecord.getTimeToMarket()); | ||
|
||
// optional fields | ||
if (importRecord.getM_WarehouseSource_ID() > 0) | ||
{ | ||
replenish.setM_WarehouseSource_ID(importRecord.getM_WarehouseSource_ID()); | ||
} | ||
if (importRecord.getM_Locator_ID() > 0) | ||
{ | ||
replenish.setM_Locator_ID(importRecord.getM_Locator_ID()); | ||
} | ||
if (importRecord.getC_Calendar_ID() > 0) | ||
{ | ||
replenish.setC_Calendar_ID(importRecord.getC_Calendar_ID()); | ||
} | ||
if (importRecord.getC_Period_ID() > 0) | ||
{ | ||
replenish.setC_Period_ID(importRecord.getC_Period_ID()); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters