use of eu.ggnet.dwoss.stock.ee.entity.StockTransactionStatus in project dwoss by gg-net.
the class UnitProcessorOperation method transfer.
/**
* Transfers a UniqueUnits StockUnit to the supplied Stock.
* <p>
* <ul>
* <li>Validate, if a StockUnit for the UniqueUnit exists, and this StockUnit is in Stock</li>
* <li>Transfer StockUnit via {@link StockTransactionType#EXTERNAL_TRANSFER}</li>
* <li>Update the SopoUnit</li>
* </ul>
* <p/>
* @param uniqueUnit the uniqueUnit
* @param stockId the stockId
* @param arranger
* @return
*/
// TODO: Use StockTransactionEmo.resquestExternalTransfer and completeExternalTransfer
@Override
public UniqueUnit transfer(UniqueUnit uniqueUnit, int stockId, String arranger) {
StockUnit stockUnit = new StockUnitEao(stockEm).findByUniqueUnitId(uniqueUnit.getId());
if (stockUnit == null)
throw new IllegalArgumentException("No StockUnit for " + uniqueUnit);
if (stockUnit.isInTransaction())
throw new IllegalArgumentException(stockUnit + " is on Transaction");
Stock destination = new DefaultEao<>(Stock.class, stockEm).findById(stockId);
StockTransaction st = new StockTransaction(StockTransactionType.EXTERNAL_TRANSFER);
StockTransactionStatus status = new StockTransactionStatus(StockTransactionStatusType.COMPLETED, new Date());
status.addParticipation(new StockTransactionParticipation(StockTransactionParticipationType.ARRANGER, arranger));
st.addStatus(status);
st.setSource(stockUnit.getStock());
st.setDestination(destination);
st.addPosition(new StockTransactionPosition(stockUnit));
stockEm.persist(st);
stockUnit.setPosition(null);
new StockLocationDiscoverer(stockEm).discoverAndSetLocation(stockUnit, destination);
uniqueUnit = new UniqueUnitEao(uuEm).findById(uniqueUnit.getId());
uniqueUnit.addHistory("External Stock change from " + stockUnit.getStock() + " to " + destination + " by " + arranger);
uniqueUnit.fetchEager();
return uniqueUnit;
}
use of eu.ggnet.dwoss.stock.ee.entity.StockTransactionStatus in project dwoss by gg-net.
the class StockTransactionEaoIT method testfind.
@Test
public void testfind() throws Exception {
utx.begin();
em.joinTransaction();
Stock s1 = new Stock(0, "TEEEEEEEST");
Stock s2 = new Stock(1, "TEEEEEEEST");
em.persist(s1);
em.persist(s2);
StockTransaction st1 = new StockTransaction(StockTransactionType.ROLL_IN);
st1.setDestination(s1);
st1.addStatus(new StockTransactionStatus(StockTransactionStatusType.PREPARED, new Date()));
st1.addStatus(new StockTransactionStatus(StockTransactionStatusType.COMPLETED, new Date()));
StockTransaction st2 = new StockTransaction(StockTransactionType.ROLL_IN);
st2.setDestination(s1);
st2.addStatus(new StockTransactionStatus(StockTransactionStatusType.PREPARED, new Date()));
StockTransaction st3 = new StockTransaction(StockTransactionType.DESTROY);
st3.setSource(s1);
st3.addStatus(new StockTransactionStatus(StockTransactionStatusType.PREPARED, new Date()));
StockTransaction st4 = new StockTransaction(StockTransactionType.ROLL_IN);
st4.setDestination(s2);
StockTransactionStatus status = new StockTransactionStatus(StockTransactionStatusType.PREPARED, new Date());
status.addParticipation(new StockTransactionParticipation(StockTransactionParticipationType.PICKER, "Hugo"));
st4.addStatus(status);
st4.setComment("Muh");
em.persist(st1);
em.persist(st2);
em.persist(st3);
em.persist(st4);
utx.commit();
utx.begin();
em.joinTransaction();
StockTransactionEao stockTransactionEao = new StockTransactionEao(em);
List<StockTransaction> sts = stockTransactionEao.findByDestination(s1.getId(), StockTransactionType.ROLL_IN, StockTransactionStatusType.PREPARED);
assertNotNull(sts);
assertEquals(1, sts.size());
assertEquals(st2.getId(), sts.get(0).getId());
sts = stockTransactionEao.findByDestination(s2.getId(), StockTransactionType.ROLL_IN, StockTransactionStatusType.PREPARED, "Hugo", "Muh");
assertNotNull(sts);
assertEquals(1, sts.size());
assertEquals(st4.getId(), sts.get(0).getId());
utx.commit();
}
use of eu.ggnet.dwoss.stock.ee.entity.StockTransactionStatus in project dwoss by gg-net.
the class StockTransactionEmoIT method testRequestRollInPrepared.
@Test
public void testRequestRollInPrepared() throws Exception {
List<Stock> stocks = gen.makeStocksAndLocations(2);
StockTransactionEmo stockTransactionEmo = new StockTransactionEmo(em);
utx.begin();
em.joinTransaction();
StockTransaction st1 = stockTransactionEmo.requestRollInPrepared(stocks.get(0).getId(), "Hugo", "Ein toller Komentar");
assertNotNull(st1);
utx.commit();
utx.begin();
em.joinTransaction();
StockTransaction st2 = stockTransactionEmo.requestRollInPrepared(stocks.get(0).getId(), "Hugo", "Ein toller Komentar");
assertNotNull(st2);
assertEquals(st1.getId(), st2.getId());
st2.addStatus(new StockTransactionStatus(COMPLETED, new Date()));
utx.commit();
utx.begin();
em.joinTransaction();
StockTransaction st3 = stockTransactionEmo.requestRollInPrepared(stocks.get(0).getId(), "Hugo", "Ein toller Komentar");
assertNotNull(st3);
assertFalse(st1.getId() == st3.getId());
utx.commit();
}
use of eu.ggnet.dwoss.stock.ee.entity.StockTransactionStatus in project dwoss by gg-net.
the class StockUnitEaoIT method testSumByTransaction.
@Test
public void testSumByTransaction() throws Exception {
utx.begin();
em.joinTransaction();
Stock s0 = new Stock(0, "1111111111111111111111111111");
Stock s1 = new Stock(1, "2222222222222222222222222222");
em.persist(s0);
em.persist(s1);
StockLocation s0l0 = new StockLocation("Lagerplatz");
s0.addStockLocation(s0l0);
StockUnit su0 = new StockUnit("g1", 1);
su0.setRefurbishId("23");
su0.setName("Name");
StockUnit su1 = new StockUnit("g2", 2);
su1.setRefurbishId("42");
su1.setName("Name");
StockUnit su2 = new StockUnit("g3", 3);
su2.setRefurbishId("42");
su2.setName("Name");
s0.addUnit(su0, s0l0);
s0.addUnit(su1, s0l0);
s0.addUnit(su2, s0l0);
em.persist(su0);
em.persist(su1);
em.persist(su2);
StockTransaction st = new StockTransaction(StockTransactionType.TRANSFER);
st.setDestination(s1);
st.setSource(s0);
st.addStatus(new StockTransactionStatus(StockTransactionStatusType.PREPARED, new Date()));
em.persist(st);
st.addPosition(new StockTransactionPosition(su0));
st.addPosition(new StockTransactionPosition(su1));
utx.commit();
assertThat(sus.countByTransaction(s0.getId(), StockTransactionType.TRANSFER, StockTransactionStatusType.PREPARED)).isEqualTo(2);
}
use of eu.ggnet.dwoss.stock.ee.entity.StockTransactionStatus in project dwoss by gg-net.
the class ValidationTest method testValidTransaction.
@Test
public void testValidTransaction() {
StockTransaction t1 = new StockTransaction();
t1.setType(StockTransactionType.TRANSFER);
t1.addStatus(new StockTransactionStatus(PREPARED, new Date()));
t1.addStatus(new StockTransactionStatus(COMMISSIONED, new Date()));
t1.addStatus(new StockTransactionStatus(IN_TRANSFER, new Date()));
t1.addStatus(new StockTransactionStatus(RECEIVED, new Date()));
assertNull("Asserted null but it was:" + t1.getValidationViolations(), t1.getValidationViolations());
t1.addStatus(new StockTransactionStatus(RECEIVED, new Date()));
assertNotNull(t1.getValidationViolations());
}
Aggregations