Search in sources :

Example 56 with StockUnit

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

the class RedTapeCloserOperationIT method testDayClosing.

/**
 * Tests if something gets closed and if the appropriated stock units are gone.
 * <p>
 * @throws UserInfoException
 */
@Test
public void testDayClosing() throws UserInfoException {
    assertFalse(customerGenerator.makeCustomers(10).isEmpty());
    receiptCustomers = customerGenerator.makeReceiptCustomers(ACER);
    systemCustomers = customerGenerator.makeSpecialCustomers(BLOCK);
    assertFalse(systemCustomers == null);
    assertFalse(receiptCustomers == null);
    assertFalse(receiptGenerator.makeUniqueUnits(200, true, true).isEmpty());
    assertFalse(redTapeGenerator.makeSalesDossiers(30).isEmpty());
    // dossier ids from created blockers
    List<Long> blockerIds = buildBlocker().stream().mapToLong(d -> d.getId()).boxed().collect(Collectors.toList());
    assertThat(stockAgent.findAllEager(StockTransaction.class).stream().map(StockTransaction::getPositions).flatMap(Collection::stream).anyMatch(t -> t.getStockUnit() != null)).overridingErrorMessage("Their exist a StockTransaction, which is not complete (blocking a stockUnit), impossible!").isFalse();
    long stockUnits = stockAgent.count(StockUnit.class);
    assertThat(stockUnits).isPositive();
    List<LogicTransaction> allLts = stockAgent.findAllEager(LogicTransaction.class);
    assertThat(allLts.size()).overridingErrorMessage("No LogicTransactions exist, impossible!").isPositive();
    redTapeCloser.executeManual("Junit");
    List<Dossier> blockerDossiers = new ArrayList<>();
    for (Long blockerId : blockerIds) {
        blockerDossiers.add(redTapeAgent.findByIdEager(Dossier.class, blockerId));
    }
    assertEquals("More/Less Blockers than expected passed closing", 3, blockerDossiers.stream().filter(d -> d.isClosed()).collect(Collectors.toList()).size());
    warnIfStockSizeDidNotChange(stockUnits);
    List<Dossier> allDossiers = redTapeAgent.findAllEager(Dossier.class);
    for (Dossier dos : allDossiers) {
        if (dos.isClosed()) {
            for (Document doc : dos.getActiveDocuments()) {
                // These are just ignored.
                if (doc.containsAny(CANCELED))
                    continue;
                for (Integer uuId : doc.getPositionsUniqueUnitIds()) {
                    StockUnit su = stockAgent.findStockUnitByUniqueUnitIdEager(uuId);
                    assertNull("There is a StockUnit for a closed Dossier (doc.id= " + doc.getId() + "):\n" + dos.toMultiLine() + "\n\n" + su + "\n\n" + "Original LTS: " + allLts.stream().filter(x -> x.getUnits().contains(su)).findAny().orElse(null), su);
                }
            }
        } else {
            for (Integer uuId : dos.getRelevantUniqueUnitIds()) {
                StockUnit su = stockAgent.findStockUnitByUniqueUnitIdEager(uuId);
                assertNotNull("There is no StockUnit for an open Dossier\n" + dos, su);
            }
        }
    }
    long reportSize = reportAgent.count(ReportLine.class);
    assertFalse(reportSize == 0);
    redTapeCloser.executeManual("Junit");
    assertEquals("Second call should not add anything new", reportSize, reportAgent.count(ReportLine.class));
}
Also used : UnitPositionHook(eu.ggnet.dwoss.redtape.ee.api.UnitPositionHook) java.util(java.util) CustomerServiceBean(eu.ggnet.dwoss.customer.ee.CustomerServiceBean) Arquillian(org.jboss.arquillian.junit.Arquillian) StockTransaction(eu.ggnet.dwoss.stock.ee.entity.StockTransaction) CustomerGeneratorOperation(eu.ggnet.dwoss.customer.ee.assist.gen.CustomerGeneratorOperation) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) RunWith(org.junit.runner.RunWith) BLOCK(eu.ggnet.dwoss.rules.DocumentType.BLOCK) RedTapeWorker(eu.ggnet.dwoss.redtapext.ee.RedTapeWorker) eu.ggnet.dwoss.rules(eu.ggnet.dwoss.rules) UserInfoException(eu.ggnet.dwoss.util.UserInfoException) UniqueUnit(eu.ggnet.dwoss.uniqueunit.ee.entity.UniqueUnit) RedTapeCloser(eu.ggnet.dwoss.redtapext.ee.reporting.RedTapeCloser) Inject(javax.inject.Inject) StockAgent(eu.ggnet.dwoss.stock.ee.StockAgent) ProductEao(eu.ggnet.dwoss.uniqueunit.ee.eao.ProductEao) After(org.junit.After) Result(eu.ggnet.dwoss.util.interactiveresult.Result) RedTapeGeneratorOperation(eu.ggnet.dwoss.redtapext.ee.gen.RedTapeGeneratorOperation) EJB(javax.ejb.EJB) UniqueUnitFormater(eu.ggnet.dwoss.uniqueunit.ee.format.UniqueUnitFormater) PriceType(eu.ggnet.dwoss.uniqueunit.ee.entity.PriceType) CustomerMetaData(eu.ggnet.dwoss.customer.opi.CustomerMetaData) StockUnit(eu.ggnet.dwoss.stock.ee.entity.StockUnit) Test(org.junit.Test) CANCELED(eu.ggnet.dwoss.redtape.ee.entity.Document.Condition.CANCELED) Collectors(java.util.stream.Collectors) eu.ggnet.dwoss.mandator.api.value(eu.ggnet.dwoss.mandator.api.value) eu.ggnet.dwoss.redtapext.op.itest.support(eu.ggnet.dwoss.redtapext.op.itest.support) REFURBISHED_ID(eu.ggnet.dwoss.uniqueunit.ee.entity.UniqueUnit.Identifier.REFURBISHED_ID) ReportAgent(eu.ggnet.dwoss.report.ee.ReportAgent) ReportLine(eu.ggnet.dwoss.report.ee.entity.ReportLine) PRODUCT_BATCH(eu.ggnet.dwoss.rules.PositionType.PRODUCT_BATCH) eu.ggnet.dwoss.redtape.ee.entity(eu.ggnet.dwoss.redtape.ee.entity) ACER(eu.ggnet.dwoss.rules.TradeName.ACER) Product(eu.ggnet.dwoss.uniqueunit.ee.entity.Product) LogicTransaction(eu.ggnet.dwoss.stock.ee.entity.LogicTransaction) Assert(org.junit.Assert) RedTapeAgent(eu.ggnet.dwoss.redtape.ee.RedTapeAgent) ReceiptGeneratorOperation(eu.ggnet.dwoss.receipt.ee.gen.ReceiptGeneratorOperation) ReportLine(eu.ggnet.dwoss.report.ee.entity.ReportLine) LogicTransaction(eu.ggnet.dwoss.stock.ee.entity.LogicTransaction) StockUnit(eu.ggnet.dwoss.stock.ee.entity.StockUnit) StockTransaction(eu.ggnet.dwoss.stock.ee.entity.StockTransaction) Test(org.junit.Test)

Example 57 with StockUnit

use of eu.ggnet.dwoss.stock.ee.entity.StockUnit 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)

Example 58 with StockUnit

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

the class RedTapeOperationCreditMemoIT 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();
    // Create Positions
    doc.append(unit(uu1));
    doc.append(unit(uu2));
    doc.append(unit(uu3));
    doc.append(comment());
    doc.append(service());
    doc.append(batch(uuProduct1));
    doc.append(shippingcost());
    // 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 = supportBean.findByDossierId(doc.getDossier().getId());
    assertNotNull("A LogicTrasaction must exists", lt);
    assertEquals("The Size of the LogicTransaction", 3, lt.getUnits().size());
    // A CreditMemo for a Unit, which is on the wrong Stock
    for (Position pos : new ArrayList<>(doc.getPositions().values())) {
        if (pos.getType() != PositionType.UNIT)
            doc.remove(pos);
        else if (pos.getUniqueUnitId() != uu1.getId())
            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.CREDIT_MEMO);
    // Setting the Stock by force.
    supportBean.changeStock(uu1.getId(), alternateStockId);
    doc = redTapeWorker.update(doc, stockIdOfUU1, "JUnit Test");
    // Asserting Everything
    assertEquals("The Identifier of CreditMemo", "GS" + YY + "_00001", doc.getIdentifier());
    lt = supportBean.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());
    assertThat(uu1.getId()).as("The One Position should reference to the UniqueUnit of the CreditMemo").isEqualTo(sto.get(0).getPositions().get(0).getUniqueUnitId());
    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);
    }
    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.CREDIT_MEMO);
    // Lets roll Out the Unit
    supportBean.rollOut(uu2.getId());
    // Do the second credit Memo and check if the Unit is back in the stock.
    StockUnit stockUnit2 = stockAgent.findStockUnitByUniqueUnitIdEager(uu2.getId());
    assertNull("StockUnit should not exist: " + stockUnit2, stockUnit2);
    doc = redTapeWorker.update(invoice, stockIdOfUU1, "JUnit");
    // Assert Everything
    assertEquals("The Identifier of CreditMemo", "GS" + YY + "_00002", doc.getIdentifier());
    stockUnit2 = stockAgent.findStockUnitByUniqueUnitIdEager(uu2.getId());
    assertNotNull("StockUnit exists", stockUnit2);
    assertNotNull("StockUnit should have LogicTransaction", stockUnit2.getLogicTransaction());
    assertThat(uu2.getId()).as("StockUnit is not the correct one").isEqualTo(stockUnit2.getUniqueUnitId());
    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);
}
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)

Example 59 with StockUnit

use of eu.ggnet.dwoss.stock.ee.entity.StockUnit 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)

Example 60 with StockUnit

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

the class RedTapeUpdateRepaymentWorkflow method execute.

/**
 * Executes the Workflow.
 *
 * @param alteredDocument
 * @param destinationId
 * @param aranger
 * @return the updated Document.
 */
public Document execute(Document alteredDocument, Integer destinationId, String aranger) {
    // TODO: don't do this in stateless, works for now.
    this.arranger = aranger;
    Document previousDoc = new DocumentEao(redTapeEm).findById(alteredDocument.getId(), LockModeType.PESSIMISTIC_WRITE);
    validate(alteredDocument, previousDoc, destinationId);
    if (alteredDocument.equalsContent(previousDoc))
        return alteredDocument;
    L.info("Workflow on {} by {}", DocumentFormater.toSimpleLine(alteredDocument), arranger);
    Document newDocument = refreshAndPrepare(alteredDocument, previousDoc);
    if (alteredDocument.getType() != previousDoc.getType()) {
        // A Complaint is now complete.
        if (previousDoc.getType() == DocumentType.COMPLAINT)
            previousDoc.setDirective(Document.Directive.NONE);
        generateIdentifier(newDocument);
    }
    if (!alteredDocument.isStillExactlyBriefed(previousDoc))
        newDocument.remove(Document.Flag.CUSTOMER_EXACTLY_BRIEFED);
    newDocument.setHistory(new DocumentHistory(arranger, "Update durch " + getClass().getSimpleName()));
    redTapeEm.persist(newDocument);
    // Writing new document an gennerating the id;
    redTapeEm.flush();
    L.debug("Returning {} with {}", newDocument, newDocument.getDossier());
    validateAfter(newDocument.getDossier());
    // Is this a first time change
    if (alteredDocument.getType() == previousDoc.getType())
        return newDocument;
    // Is it a full CreditMemo on a Unit
    if (!alteredDocument.containsPositionType(PositionType.UNIT))
        return newDocument;
    List<StockUnit> stockUnits = optionalRemoveFromLogicTransaction(newDocument);
    List<StockUnit> stockUnits2 = rollInMissingStockUnits(newDocument.getDossier().getIdentifier(), newDocument.getPositions(PositionType.UNIT).values(), destinationId);
    optionalTransferToDestination(stockUnits, destinationId);
    Map<TradeName, List<Position>> contractorPositions = mapPositionsToContrator(newDocument.getPositions(PositionType.UNIT).values());
    for (TradeName contractor : contractorPositions.keySet()) {
        Document mirror = createMirrorDossier(repaymentCustomers.get(contractor).get()).getActiveDocuments().get(0);
        updateMirrorPositions(newDocument.getDossier().getIdentifier(), mirror, contractorPositions.get(contractor));
        equilibrateLogicTransaction(mirror);
    }
    return newDocument;
}
Also used : DocumentEao(eu.ggnet.dwoss.redtape.ee.eao.DocumentEao) DocumentHistory(eu.ggnet.dwoss.redtape.ee.entity.DocumentHistory) Document(eu.ggnet.dwoss.redtape.ee.entity.Document) StockUnit(eu.ggnet.dwoss.stock.ee.entity.StockUnit)

Aggregations

StockUnit (eu.ggnet.dwoss.stock.ee.entity.StockUnit)63 UniqueUnit (eu.ggnet.dwoss.uniqueunit.ee.entity.UniqueUnit)29 StockUnitEao (eu.ggnet.dwoss.stock.ee.eao.StockUnitEao)27 LogicTransaction (eu.ggnet.dwoss.stock.ee.entity.LogicTransaction)22 Stock (eu.ggnet.dwoss.stock.ee.entity.Stock)20 StockTransaction (eu.ggnet.dwoss.stock.ee.entity.StockTransaction)20 Test (org.junit.Test)19 UniqueUnitEao (eu.ggnet.dwoss.uniqueunit.ee.eao.UniqueUnitEao)18 Product (eu.ggnet.dwoss.uniqueunit.ee.entity.Product)13 SubMonitor (eu.ggnet.dwoss.progress.SubMonitor)11 StockAgent (eu.ggnet.dwoss.stock.ee.StockAgent)9 Document (eu.ggnet.dwoss.redtape.ee.entity.Document)8 StockTransactionEmo (eu.ggnet.dwoss.stock.ee.emo.StockTransactionEmo)8 UserInfoException (eu.ggnet.dwoss.util.UserInfoException)7 Dossier (eu.ggnet.dwoss.redtape.ee.entity.Dossier)6 LogicTransactionEao (eu.ggnet.dwoss.stock.ee.eao.LogicTransactionEao)6 StockTransactionPosition (eu.ggnet.dwoss.stock.ee.entity.StockTransactionPosition)6 java.util (java.util)6 Inject (javax.inject.Inject)6 StockTransactionStatus (eu.ggnet.dwoss.stock.ee.entity.StockTransactionStatus)5