Search in sources :

Example 6 with StockTransactionEmo

use of eu.ggnet.dwoss.stock.ee.emo.StockTransactionEmo in project dwoss by gg-net.

the class StockTransactionEmoIT method testCompleteDestroy.

@Test
public void testCompleteDestroy() throws Exception {
    List<Stock> stocks = gen.makeStocksAndLocations(2);
    StockTransactionEmo stockTransactionEmo = new StockTransactionEmo(em);
    StockUnitEao stockUnitEao = new StockUnitEao(em);
    utx.begin();
    em.joinTransaction();
    Stock s1 = em.find(Stock.class, stocks.get(0).getId());
    for (int i = 1; i <= 10; i++) {
        StockUnit su = new StockUnit(Integer.toString(i), i);
        su.setStock(s1);
        em.persist(su);
    }
    List<StockUnit> units = stockUnitEao.findAll();
    assertNotNull(units);
    for (StockUnit stockUnit : units) {
        assertTrue(stockUnit.isInStock());
        assertFalse(stockUnit.isInTransaction());
        assertEquals(s1, stockUnit.getStock());
    }
    utx.commit();
    utx.begin();
    em.joinTransaction();
    StockTransaction st1 = stockTransactionEmo.requestDestroyPrepared(stocks.get(0).getId(), "Hugo", "Ein toller Komentar");
    for (StockUnit stockUnit : stockUnitEao.findAll()) {
        st1.addUnit(stockUnit);
    }
    assertEquals(units.size(), st1.getPositions().size());
    List<Integer> uids = stockTransactionEmo.completeDestroy("Horst", Arrays.asList(st1));
    assertNotNull(uids);
    assertEquals(units.size(), uids.size());
    utx.commit();
    utx.begin();
    em.joinTransaction();
    List<StockUnit> stockUnits = stockUnitEao.findAll();
    assertTrue(stockUnits.isEmpty());
    utx.commit();
}
Also used : StockUnitEao(eu.ggnet.dwoss.stock.ee.eao.StockUnitEao) StockUnit(eu.ggnet.dwoss.stock.ee.entity.StockUnit) Stock(eu.ggnet.dwoss.stock.ee.entity.Stock) StockTransactionEmo(eu.ggnet.dwoss.stock.ee.emo.StockTransactionEmo) StockTransaction(eu.ggnet.dwoss.stock.ee.entity.StockTransaction) Test(org.junit.Test)

Example 7 with StockTransactionEmo

use of eu.ggnet.dwoss.stock.ee.emo.StockTransactionEmo in project dwoss by gg-net.

the class StockTransactionEmoIT method testPrepare.

@Test
public void testPrepare() throws Exception {
    List<Stock> stocks = gen.makeStocksAndLocations(2);
    int transactionSize = 5;
    utx.begin();
    em.joinTransaction();
    Stock s1 = em.find(Stock.class, stocks.get(0).getId());
    for (int i = 1; i <= 15; i++) {
        StockUnit su = new StockUnit(Integer.toString(i), i);
        su.setStock(s1);
        em.persist(su);
    }
    utx.commit();
    utx.begin();
    em.joinTransaction();
    List<Integer> units = new StockUnitEao(em).findAll().stream().map(StockUnit::getId).collect(Collectors.toList());
    assertEquals("Assert 15 persisted Stockunits", 15, units.size());
    // prepare
    new StockTransactionEmo(em).prepare(Transfer.builder().destinationStockId(stocks.get(1).getId()).stockUnitIds(units).arranger("UnitTest").comment("Test prepare").maxTransactionSize(transactionSize).build(), null);
    utx.commit();
    utx.begin();
    em.joinTransaction();
    StockTransactionEao stEao = new StockTransactionEao(em);
    List<StockTransaction> findByDestination = stEao.findAll();
    assertEquals("Assert three transactions", 3, findByDestination.size());
    for (StockTransaction transaction : findByDestination) {
        List<StockTransactionPosition> positions = transaction.getPositions();
        assertEquals("Assert five posititons", 5, positions.size());
    }
    utx.commit();
}
Also used : StockTransactionEao(eu.ggnet.dwoss.stock.ee.eao.StockTransactionEao) StockUnitEao(eu.ggnet.dwoss.stock.ee.eao.StockUnitEao) StockTransactionPosition(eu.ggnet.dwoss.stock.ee.entity.StockTransactionPosition) StockUnit(eu.ggnet.dwoss.stock.ee.entity.StockUnit) Stock(eu.ggnet.dwoss.stock.ee.entity.Stock) StockTransactionEmo(eu.ggnet.dwoss.stock.ee.emo.StockTransactionEmo) StockTransaction(eu.ggnet.dwoss.stock.ee.entity.StockTransaction) Test(org.junit.Test)

Example 8 with StockTransactionEmo

use of eu.ggnet.dwoss.stock.ee.emo.StockTransactionEmo in project dwoss by gg-net.

the class StockTransactionEmoIT method testCompleteRollInRollOut.

@Test
public void testCompleteRollInRollOut() 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");
    st1.addUnit(new StockUnit("1", 1));
    st1.addUnit(new StockUnit("2", 2));
    st1.addUnit(new StockUnit("3", 3));
    st1.addUnit(new StockUnit("4", 4));
    st1.addUnit(new StockUnit("5", 5));
    st1.addUnit(new StockUnit("6", 6));
    st1.addUnit(new StockUnit("7", 7));
    st1.addUnit(new StockUnit("8", 8));
    st1.addUnit(new StockUnit("9", 9));
    List<StockUnit> units = stockTransactionEmo.completeRollIn("Hans", Arrays.asList(st1));
    assertEquals(COMPLETED, st1.getStatus().getType());
    assertNotNull(units);
    assertEquals(st1.getPositions().size(), units.size());
    for (StockUnit stockUnit : units) {
        assertTrue(stockUnit.isInStock());
        assertFalse(stockUnit.isInTransaction());
        assertEquals(stocks.get(0), stockUnit.getStock());
    }
    utx.commit();
    StockUnitEao stockUnitEao = new StockUnitEao(em);
    utx.begin();
    em.joinTransaction();
    st1 = stockTransactionEmo.requestRollOutPrepared(stocks.get(0).getId(), "Hugo", "Ein toller Komentar");
    for (StockUnit stockUnit : stockUnitEao.findAll()) {
        st1.addUnit(stockUnit);
    }
    assertEquals(units.size(), st1.getPositions().size());
    utx.commit();
    utx.begin();
    em.joinTransaction();
    st1 = em.merge(st1);
    List<Integer> uids = stockTransactionEmo.completeRollOut("Horst", Arrays.asList(st1));
    assertNotNull(uids);
    assertEquals(units.size(), uids.size());
    utx.commit();
    utx.begin();
    em.joinTransaction();
    List<StockUnit> stockUnits = stockUnitEao.findAll();
    assertTrue(stockUnits.isEmpty());
    utx.commit();
}
Also used : StockUnitEao(eu.ggnet.dwoss.stock.ee.eao.StockUnitEao) StockUnit(eu.ggnet.dwoss.stock.ee.entity.StockUnit) Stock(eu.ggnet.dwoss.stock.ee.entity.Stock) StockTransactionEmo(eu.ggnet.dwoss.stock.ee.emo.StockTransactionEmo) StockTransaction(eu.ggnet.dwoss.stock.ee.entity.StockTransaction) Test(org.junit.Test)

Example 9 with StockTransactionEmo

use of eu.ggnet.dwoss.stock.ee.emo.StockTransactionEmo in project dwoss by gg-net.

the class RedTapeUpdateRepaymentWorkflow method rollInMissingStockUnits.

/**
 * If referenced Units are not in Stock, roll them in and append them to the instance variable (stockUnits).
 *
 * @return the list of rolled in StockUnits
 */
List<StockUnit> rollInMissingStockUnits(String dossierIdentifier, Collection<Position> positions, int destinationId) {
    List<UniqueUnit> uniqueUnits = new ArrayList<>();
    StockUnitEao stockUnitEao = new StockUnitEao(stockEm);
    UniqueUnitEao uniqueUnitEao = new UniqueUnitEao(uniqueUnitEm);
    for (Position position : positions) {
        if (stockUnitEao.findByUniqueUnitId(position.getUniqueUnitId()) == null) {
            uniqueUnits.add(uniqueUnitEao.findById(position.getUniqueUnitId()));
        }
    }
    if (uniqueUnits.isEmpty())
        return Collections.EMPTY_LIST;
    StockTransactionEmo transactionEmo = new StockTransactionEmo(stockEm);
    StockTransaction rollInTransaction = transactionEmo.requestRollInPrepared(destinationId, arranger, "RollIn durch Gutschrift " + dossierIdentifier);
    for (UniqueUnit uu : uniqueUnits) {
        StockUnit stockUnit = new StockUnit(uu.getIdentifier(UniqueUnit.Identifier.REFURBISHED_ID), uu.getProduct().getName(), uu.getId());
        rollInTransaction.addUnit(stockUnit);
        stockEm.persist(stockUnit);
    }
    List<StockUnit> rolledInUnits = transactionEmo.completeRollIn(arranger, Arrays.asList(rollInTransaction));
    L.info("Missing Units rolled In: {}", toIds(rolledInUnits));
    return rolledInUnits;
}
Also used : UniqueUnit(eu.ggnet.dwoss.uniqueunit.ee.entity.UniqueUnit) StockUnitEao(eu.ggnet.dwoss.stock.ee.eao.StockUnitEao) Position(eu.ggnet.dwoss.redtape.ee.entity.Position) StockUnit(eu.ggnet.dwoss.stock.ee.entity.StockUnit) UniqueUnitEao(eu.ggnet.dwoss.uniqueunit.ee.eao.UniqueUnitEao) StockTransactionEmo(eu.ggnet.dwoss.stock.ee.emo.StockTransactionEmo) StockTransaction(eu.ggnet.dwoss.stock.ee.entity.StockTransaction)

Aggregations

StockTransactionEmo (eu.ggnet.dwoss.stock.ee.emo.StockTransactionEmo)9 StockTransaction (eu.ggnet.dwoss.stock.ee.entity.StockTransaction)8 Stock (eu.ggnet.dwoss.stock.ee.entity.Stock)6 StockUnit (eu.ggnet.dwoss.stock.ee.entity.StockUnit)6 StockUnitEao (eu.ggnet.dwoss.stock.ee.eao.StockUnitEao)5 Test (org.junit.Test)5 UniqueUnitEao (eu.ggnet.dwoss.uniqueunit.ee.eao.UniqueUnitEao)3 UniqueUnit (eu.ggnet.dwoss.uniqueunit.ee.entity.UniqueUnit)3 StockTransactionStatus (eu.ggnet.dwoss.stock.ee.entity.StockTransactionStatus)2 SubMonitor (eu.ggnet.dwoss.progress.SubMonitor)1 DossierEmo (eu.ggnet.dwoss.redtape.ee.emo.DossierEmo)1 Document (eu.ggnet.dwoss.redtape.ee.entity.Document)1 Dossier (eu.ggnet.dwoss.redtape.ee.entity.Dossier)1 Position (eu.ggnet.dwoss.redtape.ee.entity.Position)1 StockTransactionEao (eu.ggnet.dwoss.stock.ee.eao.StockTransactionEao)1 LogicTransactionEmo (eu.ggnet.dwoss.stock.ee.emo.LogicTransactionEmo)1 LogicTransaction (eu.ggnet.dwoss.stock.ee.entity.LogicTransaction)1 StockTransactionPosition (eu.ggnet.dwoss.stock.ee.entity.StockTransactionPosition)1 SalesChannelLine (eu.ggnet.dwoss.stock.ee.model.SalesChannelLine)1