-
Notifications
You must be signed in to change notification settings - Fork 567
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#6072 close package on shipping_package and order deletion from shipp…
…ing_package #6072
- Loading branch information
Showing
2 changed files
with
116 additions
and
0 deletions.
There are no files selected for viewing
64 changes: 64 additions & 0 deletions
64
de.metas.business/src/main/java/de/metas/shipping/MPackageId.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,64 @@ | ||
package de.metas.shipping; | ||
|
||
import javax.annotation.Nullable; | ||
|
||
import com.fasterxml.jackson.annotation.JsonCreator; | ||
import com.fasterxml.jackson.annotation.JsonValue; | ||
|
||
import de.metas.util.Check; | ||
import de.metas.util.lang.RepoIdAware; | ||
import lombok.NonNull; | ||
import lombok.Value; | ||
|
||
/* | ||
* #%L | ||
* de.metas.business | ||
* %% | ||
* Copyright (C) 2020 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% | ||
*/ | ||
|
||
@Value | ||
public class MPackageId implements RepoIdAware | ||
{ | ||
int repoId; | ||
|
||
@NonNull | ||
@JsonCreator | ||
public static MPackageId ofRepoId(final int repoId) | ||
{ | ||
return new MPackageId(repoId); | ||
} | ||
|
||
@Nullable | ||
public static MPackageId ofRepoIdOrNull(final int repoId) | ||
{ | ||
return repoId > 0 ? ofRepoId(repoId) : null; | ||
} | ||
|
||
private MPackageId(final int repoId) | ||
{ | ||
this.repoId = Check.assumeGreaterThanZero(repoId, "M_Package_ID"); | ||
} | ||
|
||
@Override | ||
@JsonValue | ||
public int getRepoId() | ||
{ | ||
return repoId; | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
de.metas.business/src/main/java/de/metas/shipping/MPackageRepository.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,52 @@ | ||
package de.metas.shipping; | ||
|
||
import static org.adempiere.model.InterfaceWrapperHelper.load; | ||
import static org.adempiere.model.InterfaceWrapperHelper.save; | ||
|
||
import org.adempiere.exceptions.AdempiereException; | ||
import org.compiere.model.I_M_Package; | ||
import org.springframework.stereotype.Repository; | ||
|
||
/* | ||
* #%L | ||
* de.metas.business | ||
* %% | ||
* Copyright (C) 2020 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% | ||
*/ | ||
@Repository | ||
public class MPackageRepository | ||
{ | ||
public I_M_Package getById(final MPackageId mPackageId) | ||
{ | ||
final I_M_Package mPackage = load(mPackageId.getRepoId(), I_M_Package.class); | ||
if (mPackage == null) | ||
{ | ||
throw new AdempiereException("@NotFound@: " + mPackageId); | ||
} | ||
return mPackage; | ||
} | ||
|
||
public void closeMPackage(MPackageId mPackageId) | ||
{ | ||
final I_M_Package mPackage = getById(mPackageId); | ||
|
||
mPackage.setIsClosed(true); | ||
|
||
save(mPackage); | ||
} | ||
} |