Search in sources :

Example 26 with Stock

use of eu.ggnet.dwoss.stock.ee.entity.Stock 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 27 with Stock

use of eu.ggnet.dwoss.stock.ee.entity.Stock in project dwoss by gg-net.

the class StockUnitEaoIT method testFindByIdentifierAndStock.

@Test
public void testFindByIdentifierAndStock() throws Exception {
    utx.begin();
    em.joinTransaction();
    Stock s = new Stock(0, "TEEEEEEEEEEEEEEEST");
    em.persist(s);
    StockLocation sl = new StockLocation("Lagerplatz");
    s.addStockLocation(sl);
    StockUnit s1 = new StockUnit("G1", 1);
    s1.setRefurbishId("23");
    StockUnit s2 = new StockUnit("G2", 2);
    s2.setRefurbishId("42");
    s.addUnit(s1, sl);
    s.addUnit(s2, sl);
    em.persist(new Stock(1, "TEEEEEEEEST"));
    utx.commit();
    int id1 = s1.getId();
    int id2 = s2.getId();
    assertFalse(id1 == id2);
    s1 = sus.findByUniqueUnitId(1);
    s2 = sus.findByUniqueUnitId(2);
    assertThat(s1).isNotNull();
    assertThat(s2).isNotNull();
    assertEquals(id1, s1.getId());
    assertEquals(id2, s2.getId());
    List<StockUnit> units = sus.findByStockId(s.getId());
    assertEquals(2, units.size());
    s1 = sus.findByRefurbishId("23");
    s2 = sus.findByRefurbishId("42");
    assertNotNull(s1);
    assertNotNull(s2);
    assertEquals(id1, s1.getId());
    assertEquals(id2, s2.getId());
    assertNull(sus.findByRefurbishId("123"));
    assertNull(sus.findByRefurbishId(null));
}
Also used : StockLocation(eu.ggnet.dwoss.stock.ee.entity.StockLocation) StockUnit(eu.ggnet.dwoss.stock.ee.entity.StockUnit) Stock(eu.ggnet.dwoss.stock.ee.entity.Stock) Test(org.junit.Test)

Example 28 with Stock

use of eu.ggnet.dwoss.stock.ee.entity.Stock in project dwoss by gg-net.

the class StockUnitEaoIT method testFindByNoTransaction.

@Test
public void testFindByNoTransaction() throws Exception {
    utx.begin();
    em.joinTransaction();
    Stock s = new Stock(0, "TEEEEEEEEEEEEEEST");
    em.persist(s);
    StockLocation sl = new StockLocation("Lagerplatz");
    s.addStockLocation(sl);
    StockUnit s1 = new StockUnit("G1", 1);
    StockUnit s2 = new StockUnit("G2", 2);
    StockUnit s3 = new StockUnit("G3", 3);
    StockUnit s4 = new StockUnit("G4", 4);
    s.addUnit(s1, sl);
    s.addUnit(s2, sl);
    s.addUnit(s3, sl);
    s.addUnit(s4, sl);
    em.persist(s);
    em.persist(new Stock(1, "TEEEEEEEEEST2"));
    LogicTransaction lt = new LogicTransaction();
    lt.setDossierId(1);
    lt.add(s4);
    em.persist(lt);
    StockTransaction st = new StockTransaction(StockTransactionType.TRANSFER);
    st.setSource(s);
    st.addStatus(new StockTransactionStatus(StockTransactionStatusType.PREPARED, new Date()));
    em.persist(st);
    st.addPosition(new StockTransactionPosition(s1));
    utx.commit();
    List<StockUnit> sts = sus.findByNoTransaction();
    assertEquals(2, sts.size());
}
Also used : StockLocation(eu.ggnet.dwoss.stock.ee.entity.StockLocation) StockTransactionStatus(eu.ggnet.dwoss.stock.ee.entity.StockTransactionStatus) LogicTransaction(eu.ggnet.dwoss.stock.ee.entity.LogicTransaction) StockTransactionPosition(eu.ggnet.dwoss.stock.ee.entity.StockTransactionPosition) StockUnit(eu.ggnet.dwoss.stock.ee.entity.StockUnit) Stock(eu.ggnet.dwoss.stock.ee.entity.Stock) Date(java.util.Date) StockTransaction(eu.ggnet.dwoss.stock.ee.entity.StockTransaction) Test(org.junit.Test)

Example 29 with Stock

use of eu.ggnet.dwoss.stock.ee.entity.Stock in project dwoss by gg-net.

the class ValidationTest method testStockUnit.

@Test
public void testStockUnit() {
    StockUnit su = new StockUnit("Bla", 0);
    Set<? extends ConstraintViolation> violations = validator.validate(su);
    if (violations.isEmpty())
        fail("No violation, but StockUnit has neither Stock nor Position");
    Stock s = new Stock(1, "Teststock");
    su.setStock(s);
    violations = validator.validate(su);
    if (!violations.isEmpty())
        fail("Violation, but StockUnit has Stock. msg: " + buildMessage(violations));
    su.setStock(null);
    violations = validator.validate(su);
    if (violations.isEmpty())
        fail("No violation, but StockUnit has neither Stock nor Position");
    StockTransactionPosition stp = new StockTransactionPosition(su);
    if (validator.validate(su).isEmpty())
        fail("No violation, but StockUnit has invalid Position");
    StockTransaction t = new StockTransaction();
    t.addPosition(stp);
    if (validator.validate(su).isEmpty())
        fail("No violation, but StockTransaction is still invalid (no status, no type)");
    t.addStatus(new StockTransactionStatus(StockTransactionStatusType.PREPARED, new Date()));
    if (validator.validate(su).isEmpty())
        fail("No violation, but StockTransaction is still invalid (no type)");
    t.setType(StockTransactionType.TRANSFER);
    violations = validator.validate(su);
    if (!violations.isEmpty())
        fail("Violation, but StockUnit has valid Position and Transaction. msg: " + buildMessage(violations));
    su.setStock(s);
    violations = validator.validate(su);
    if (!violations.isEmpty())
        fail("Violation, Special Case: StockUnit has Stock and Transaction(Prepared) which is ok. msg: " + buildMessage(violations));
    t.addStatus(new StockTransactionStatus(StockTransactionStatusType.COMMISSIONED, new Date()));
    if (validator.validate(su).isEmpty())
        fail("No violation, but now StockUnit has Stock and StockTransaction( not prepared), which is not ok.");
}
Also used : StockTransactionStatus(eu.ggnet.dwoss.stock.ee.entity.StockTransactionStatus) StockTransactionPosition(eu.ggnet.dwoss.stock.ee.entity.StockTransactionPosition) StockUnit(eu.ggnet.dwoss.stock.ee.entity.StockUnit) Stock(eu.ggnet.dwoss.stock.ee.entity.Stock) Date(java.util.Date) StockTransaction(eu.ggnet.dwoss.stock.ee.entity.StockTransaction) Test(org.junit.Test)

Example 30 with Stock

use of eu.ggnet.dwoss.stock.ee.entity.Stock in project dwoss by gg-net.

the class RedTapeOperationAnnulationInvoiceIT method testCreditMemo.

@Test
public void testCreditMemo() throws UserInfoException {
    // We need two stocks at least.
    List<Stock> allStocks = stockGenerator.makeStocksAndLocations(2);
    long customerId = customerGenerator.makeCustomer();
    List<UniqueUnit> uus = receiptGenerator.makeUniqueUnits(4, true, true);
    UniqueUnit uu1 = uus.get(0);
    UniqueUnit uu2 = uus.get(1);
    UniqueUnit uu3 = uus.get(2);
    UniqueUnit uu4 = uus.get(3);
    Product uuProduct1 = uu1.getProduct();
    int stockIdOfUU1 = stockAgent.findStockUnitByUniqueUnitIdEager(uu1.getId()).getStock().getId();
    int alternateStockId = allStocks.stream().map(Stock::getId).filter(id -> id != stockIdOfUU1).findFirst().orElseThrow(() -> new RuntimeException("No alternate StockId found, impossible"));
    Dossier dos = redTapeWorker.create(customerId, true, "Me");
    Document doc = dos.getActiveDocuments(DocumentType.ORDER).get(0);
    assertThat(doc).overridingErrorMessage("Expected active document Order, got null. Dossier: " + dos.toMultiLine()).isNotNull();
    Position batch = batch(uuProduct1);
    Position shipping = shippingcost();
    doc.append(unit(uu1));
    doc.append(unit(uu2));
    doc.append(unit(uu3));
    doc.append(comment());
    doc.append(service());
    doc.append(batch);
    doc.append(shipping);
    // add units to LogicTransaction
    unitOverseer.lockStockUnit(dos.getId(), uu1.getIdentifier(UniqueUnit.Identifier.REFURBISHED_ID));
    unitOverseer.lockStockUnit(dos.getId(), uu2.getIdentifier(UniqueUnit.Identifier.REFURBISHED_ID));
    unitOverseer.lockStockUnit(dos.getId(), uu3.getIdentifier(UniqueUnit.Identifier.REFURBISHED_ID));
    unitOverseer.lockStockUnit(dos.getId(), uu4.getIdentifier(UniqueUnit.Identifier.REFURBISHED_ID));
    doc = redTapeWorker.update(doc, null, "JUnit");
    doc.add(Document.Condition.PAID);
    doc.add(Document.Condition.PICKED_UP);
    doc.setType(DocumentType.INVOICE);
    doc = redTapeWorker.update(doc, null, "JUnit");
    LogicTransaction lt = support.findByDossierId(doc.getDossier().getId());
    assertNotNull("A LogicTrasaction must exists", lt);
    assertEquals("The Size of the LogicTransaction", 3, lt.getUnits().size());
    // A CreditMemo for Unit1, negate prices on Annulation Invoice.
    for (Position pos : new ArrayList<>(doc.getPositions().values())) {
        if (pos.getUniqueUnitId() == uu1.getId()) {
            pos.setPrice(pos.getPrice() * -1);
        } else {
            doc.remove(pos);
        }
    }
    assertEquals("Document should have exactly one possition", 1, doc.getPositions().size());
    assertEquals("Position is exactly the same UniqueUnitId", uu1.getId(), doc.getPositions().get(1).getUniqueUnitId());
    doc.setType(DocumentType.ANNULATION_INVOICE);
    // Setting the Stock by force, cause we want to see if on update, the unit is moved to the original stock.
    support.changeStock(uu1.getId(), alternateStockId);
    doc = redTapeWorker.update(doc, stockIdOfUU1, "JUnit Test");
    // Asserting Everything
    assertEquals("The Identifier of CreditMemo", "SR" + YY + "_00001", doc.getIdentifier());
    lt = support.findByDossierId(doc.getDossier().getId());
    assertNotNull("A LogicTrasaction must still exists", lt);
    assertEquals("The Size of the LogicTransaction", 2, lt.getUnits().size());
    for (StockUnit stockUnit : lt.getUnits()) {
        if (stockUnit.getUniqueUnitId() == uu1.getId()) {
            fail("The StockUnit of the CreditMemo should not be on the LogicTransaction of the Dossier");
        }
    }
    List<StockTransaction> sto = stockAgent.findStockTransactionEager(StockTransactionType.EXTERNAL_TRANSFER, StockTransactionStatusType.COMPLETED);
    assertEquals("One External Transfer Transaction", 1, sto.size());
    assertEquals("Only One Position on the Transaction should exist", 1, sto.get(0).getPositions().size());
    assertEquals("The One Position should reference to the UniqueUnit of the CreditMemo", uu1.getId(), sto.get(0).getPositions().get(0).getUniqueUnitId().intValue());
    assertEquals("The Transaction should contain exactlly one shadow of the UniqueUnit", 1, sto.size());
    StockUnit stockUnit1 = stockAgent.findStockUnitByUniqueUnitIdEager(uu1.getId());
    assertEquals("The Stock of the StockUnit", stockIdOfUU1, stockUnit1.getStock().getId());
    assertNotNull("StockUnit should be on a LogicTransaction", stockUnit1.getLogicTransaction());
    Dossier dossier = redTapeAgent.findByIdEager(Dossier.class, stockUnit1.getLogicTransaction().getDossierId());
    assertNotNull("A Dossier on the SystemCustomer must exist", dossier);
    assertFalse(dossier.getActiveDocuments().isEmpty());
    assertFalse(dossier.getActiveDocuments().get(0).getPositions().isEmpty());
    assertEquals(2, dossier.getActiveDocuments().get(0).getPositions().size());
    boolean unit1Found = false;
    boolean commentFound = false;
    for (Position pos : dossier.getActiveDocuments().get(0).getPositions().values()) {
        if (pos.getType() == PositionType.UNIT) {
            assertEquals(uu1.getId(), pos.getUniqueUnitId());
            unit1Found = true;
        } else if (pos.getType() == PositionType.COMMENT) {
            commentFound = true;
        }
    }
    assertTrue(unit1Found);
    assertTrue(commentFound);
    Document invoice = doc.getDossier().getActiveDocuments(DocumentType.INVOICE).get(0);
    // A CreditMemo for a Unit, which is Rolled Out before.
    for (Position pos : new ArrayList<>(invoice.getPositions().values())) {
        if (pos.getType() != PositionType.UNIT)
            invoice.remove(pos);
        else if (pos.getUniqueUnitId() != uu2.getId())
            invoice.remove(pos);
        else {
            pos.setPrice(pos.getPrice() * -1);
        }
    }
    assertEquals("Document should have exactly one possition", 1, invoice.getPositions().size());
    assertEquals("Position is exactly the same UniqueUnitId", uu2.getId(), invoice.getPositions().get(1).getUniqueUnitId());
    invoice.setType(DocumentType.ANNULATION_INVOICE);
    // Lets roll Out the Unit
    support.rollOut(uu2.getId());
    // Verify it is not in stock
    StockUnit stockUnit2 = stockAgent.findStockUnitByUniqueUnitIdEager(uu2.getId());
    assertNull("StockUnit should not exist: " + stockUnit2, stockUnit2);
    // Do the second credit Memo and check if the Unit is back in the stock.
    doc = redTapeWorker.update(invoice, stockIdOfUU1, "JUnit");
    // Assert Everything
    // TODO: this is Mandatorspecific, pickup there.
    assertEquals("The Identifier of CreditMemo", "SR" + YY + "_00002", doc.getIdentifier());
    stockUnit2 = stockAgent.findStockUnitByUniqueUnitIdEager(uu2.getId());
    assertNotNull("StockUnit exists", stockUnit2);
    assertNotNull("StockUnit should have LogicTransaction", stockUnit2.getLogicTransaction());
    assertEquals("StockUnit is not the correct one", uu2.getId(), stockUnit2.getUniqueUnitId().intValue());
    dossier = redTapeAgent.findByIdEager(Dossier.class, stockUnit2.getLogicTransaction().getDossierId());
    assertNotNull("A Dossier on the SystemCustomer must exist", dossier);
    assertFalse(dossier.getActiveDocuments().isEmpty());
    assertFalse(dossier.getActiveDocuments().get(0).getPositions().isEmpty());
    assertEquals(2, dossier.getActiveDocuments().get(0).getPositions().size());
    unit1Found = false;
    commentFound = false;
    for (Position pos : dossier.getActiveDocuments().get(0).getPositions().values()) {
        if (pos.getType() == PositionType.UNIT) {
            assertEquals(uu2.getId(), pos.getUniqueUnitId());
            unit1Found = true;
        } else if (pos.getType() == PositionType.COMMENT) {
            commentFound = true;
        }
    }
    assertTrue(unit1Found);
    assertTrue(commentFound);
    Date now = new Date();
    Date start = DateUtils.addDays(now, -1);
    Date end = DateUtils.addDays(now, 1);
    FileJacket fj = sageExporter.toXml(start, end);
    String result = Strings.fromByteArray(fj.getContent());
    assertThat(result).as("SageXml spot Test").isNotBlank().contains(dos.getIdentifier()).contains(Double.toString(TwoDigits.round(batch.getPrice() * batch.getAmount())).replace(".", ",")).contains(Double.toString(TwoDigits.round(shipping.getPrice() * shipping.getAmount())).replace(".", ","));
    System.out.println(result);
}
Also used : LogicTransaction(eu.ggnet.dwoss.stock.ee.entity.LogicTransaction) Product(eu.ggnet.dwoss.uniqueunit.ee.entity.Product) UniqueUnit(eu.ggnet.dwoss.uniqueunit.ee.entity.UniqueUnit) StockUnit(eu.ggnet.dwoss.stock.ee.entity.StockUnit) Stock(eu.ggnet.dwoss.stock.ee.entity.Stock) StockTransaction(eu.ggnet.dwoss.stock.ee.entity.StockTransaction) Test(org.junit.Test)

Aggregations

Stock (eu.ggnet.dwoss.stock.ee.entity.Stock)32 Test (org.junit.Test)22 StockTransaction (eu.ggnet.dwoss.stock.ee.entity.StockTransaction)21 StockUnit (eu.ggnet.dwoss.stock.ee.entity.StockUnit)19 StockTransactionStatus (eu.ggnet.dwoss.stock.ee.entity.StockTransactionStatus)9 UniqueUnit (eu.ggnet.dwoss.uniqueunit.ee.entity.UniqueUnit)8 StockTransactionEmo (eu.ggnet.dwoss.stock.ee.emo.StockTransactionEmo)7 LogicTransaction (eu.ggnet.dwoss.stock.ee.entity.LogicTransaction)7 Date (java.util.Date)7 StockAgent (eu.ggnet.dwoss.stock.ee.StockAgent)6 StockLocation (eu.ggnet.dwoss.stock.ee.entity.StockLocation)6 Product (eu.ggnet.dwoss.uniqueunit.ee.entity.Product)6 StockUnitEao (eu.ggnet.dwoss.stock.ee.eao.StockUnitEao)5 StockTransactionPosition (eu.ggnet.dwoss.stock.ee.entity.StockTransactionPosition)5 SubMonitor (eu.ggnet.dwoss.progress.SubMonitor)3 ProductSpec (eu.ggnet.dwoss.spec.ee.entity.ProductSpec)3 Shipment (eu.ggnet.dwoss.stock.ee.entity.Shipment)3 StockTransactionStatusType (eu.ggnet.dwoss.stock.ee.entity.StockTransactionStatusType)3 StockTransactionType (eu.ggnet.dwoss.stock.ee.entity.StockTransactionType)3 UniqueUnitEao (eu.ggnet.dwoss.uniqueunit.ee.eao.UniqueUnitEao)3