Skip to content

Commit

Permalink
#6072 close package on shipping_package and order deletion from shipp…
Browse files Browse the repository at this point in the history
…ing_package

#6072
  • Loading branch information
metas-rc committed Feb 6, 2020
1 parent 4565445 commit e03c50c
Show file tree
Hide file tree
Showing 2 changed files with 116 additions and 0 deletions.
64 changes: 64 additions & 0 deletions de.metas.business/src/main/java/de/metas/shipping/MPackageId.java
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;
}
}
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);
}
}

0 comments on commit e03c50c

Please sign in to comment.