Search in sources :

Example 1 with UniqueUnit

use of eu.ggnet.dwoss.uniqueunit.ee.entity.UniqueUnit in project dwoss by gg-net.

the class RedTapeOperationOrderInvoiceIT method testRevertCreate.

@Test
public void testRevertCreate() throws UserInfoException {
    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();
    // Generate Dossier
    Dossier dos1 = redTapeWorker.create(customerId, true, "Me");
    Document doc1 = dos1.getActiveDocuments(DocumentType.ORDER).get(0);
    assertThat(doc1).overridingErrorMessage("Expected active document Order, got null. Dossier: " + dos1.toMultiLine()).isNotNull();
    // Create Positions
    Position p1 = NaivBuilderUtil.unit(uu1);
    Position p2 = NaivBuilderUtil.unit(uu2);
    Position p4 = NaivBuilderUtil.comment();
    Position p5 = NaivBuilderUtil.service();
    Position p6 = NaivBuilderUtil.batch(uuProduct1);
    doc1.append(p1);
    doc1.append(p2);
    doc1.append(p4);
    doc1.append(p5);
    doc1.append(p6);
    // add units to LogicTransaction
    unitOverseer.lockStockUnit(dos1.getId(), uu1.getIdentifier(UniqueUnit.Identifier.REFURBISHED_ID));
    unitOverseer.lockStockUnit(dos1.getId(), uu2.getIdentifier(UniqueUnit.Identifier.REFURBISHED_ID));
    // update document
    doc1 = redTapeWorker.update(doc1, null, "Me");
    // add units to LogicTransaction without update
    unitOverseer.lockStockUnit(dos1.getId(), uu3.getIdentifier(UniqueUnit.Identifier.REFURBISHED_ID));
    unitOverseer.lockStockUnit(dos1.getId(), uu4.getIdentifier(UniqueUnit.Identifier.REFURBISHED_ID));
    assertEquals("LogicTransaction size", 4, logicTransactionEao.findByDossierId(dos1.getId()).getUnits().size());
    // test revertCreate operation
    redTapeWorker.revertCreate(doc1);
    assertEquals("LogicTransaction cleanup", 2, logicTransactionEao.findByDossierId(dos1.getId()).getUnits().size());
    assertNull(stockAgent.findStockUnitByUniqueUnitIdEager(uu3.getId()).getLogicTransaction());
    assertNull(stockAgent.findStockUnitByUniqueUnitIdEager(uu3.getId()).getLogicTransaction());
    long customerId2 = customerGenerator.makeCustomer();
    Dossier dos2 = redTapeWorker.create(customerId2, true, "Me");
    assertEquals("Dossiers in database", 2, redTapeAgent.findAll(Dossier.class).size());
    redTapeWorker.revertCreate(dos2.getActiveDocuments(DocumentType.ORDER).get(0));
    assertEquals("Dossiers in database", 1, redTapeAgent.findAll(Dossier.class).size());
}
Also used : UniqueUnit(eu.ggnet.dwoss.uniqueunit.ee.entity.UniqueUnit) Product(eu.ggnet.dwoss.uniqueunit.ee.entity.Product) Test(org.junit.Test)

Example 2 with UniqueUnit

use of eu.ggnet.dwoss.uniqueunit.ee.entity.UniqueUnit in project dwoss by gg-net.

the class RedTapeOperationOrderInvoiceIT method testUpdateDocument.

@Test
public void testUpdateDocument() throws UserInfoException {
    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();
    customerGenerator.scrambleAddress(customerId, AddressType.SHIPPING);
    // Generate Dossier
    Dossier dos1 = redTapeWorker.create(customerId, false, "Me");
    Document doc1 = dos1.getActiveDocuments(DocumentType.ORDER).get(0);
    assertThat(doc1).overridingErrorMessage("Expected active document Order, got null. Dossier: " + dos1.toMultiLine()).isNotNull();
    // Commit explicit date to document for assertion
    doc1 = manipulator.changeActual(doc1, new GregorianCalendar(2012, 3, 15).getTime());
    // Create Positions
    Position p1 = NaivBuilderUtil.unit(uu1);
    Position p2 = NaivBuilderUtil.unit(uu2);
    Position p3 = NaivBuilderUtil.unit(uu3);
    Position p4 = NaivBuilderUtil.comment();
    Position p5 = NaivBuilderUtil.service();
    Position p6 = NaivBuilderUtil.batch(uuProduct1);
    Position p7 = NaivBuilderUtil.shippingcost();
    doc1.append(p1);
    doc1.append(p2);
    doc1.append(p3);
    doc1.append(p4);
    doc1.append(p5);
    doc1.append(p6);
    doc1.append(p7);
    // add units to LogicTransaction
    unitOverseer.lockStockUnit(dos1.getId(), uu1.getIdentifier(UniqueUnit.Identifier.REFURBISHED_ID));
    unitOverseer.lockStockUnit(dos1.getId(), uu2.getIdentifier(UniqueUnit.Identifier.REFURBISHED_ID));
    unitOverseer.lockStockUnit(dos1.getId(), uu3.getIdentifier(UniqueUnit.Identifier.REFURBISHED_ID));
    unitOverseer.lockStockUnit(dos1.getId(), uu4.getIdentifier(UniqueUnit.Identifier.REFURBISHED_ID));
    // check if LogicTransaction is created correctly
    assertEquals("Amount of LogicTransactions", 1, logicTransactionEao.findAll().size());
    assertEquals("The LogicTransaction should have only 4 units", 4, logicTransactionEao.findAll().get(0).getUnits().size());
    // update document
    Date date = doc1.getActual();
    doc1 = redTapeWorker.update(doc1, null, "Me");
    assertEquals("Same actual dates expected", date, doc1.getActual());
    assertEquals("Only one Active Document expected", 1, doc1.getDossier().getActiveDocuments().size());
    assertTrue(logicTransactionEao.findAll().get(0).getUnits().size() == 3);
    assertEquals("Ammount of Documents", 2, redTapeAgent.findAll(Document.class).size());
    dos1 = redTapeAgent.findByIdEager(Dossier.class, dos1.getId());
    assertEquals("Ammount of Posistions", 7, doc1.getPositions().size());
    // address setting test
    assertFalse(doc1.getInvoiceAddress().equals(doc1.getShippingAddress()));
    // Test update with document changes
    Position p8 = Position.builder().amount(1).type(PositionType.SERVICE).price(50.).tax(1.).name("Position 8").description("Position from update2").build();
    doc1.append(p8);
    doc1.removeAt(6);
    Document doc2 = redTapeWorker.update(doc1, null, "Me");
    assertEquals("Only one Active Document expected", 1, doc2.getDossier().getActiveDocuments().size());
    assertEquals("Ammount of Documents", 3, redTapeAgent.findAll(Document.class).size());
    dos1 = redTapeAgent.findByIdEager(Dossier.class, dos1.getId());
    assertEquals("Id of Predecessor Document", doc1.getId(), dos1.getActiveDocuments(DocumentType.ORDER).get(0).getPredecessor().getId());
    assertEquals("Ammount of Posistions", 7, dos1.getActiveDocuments(DocumentType.ORDER).get(0).getPositions().size());
    // Test date changes when updating document type
    doc2.setType(DocumentType.INVOICE);
    Document doc3 = redTapeWorker.update(doc2, null, "JUnit");
    assertFalse(doc3.getActual().equals(doc2.getActual()));
}
Also used : UniqueUnit(eu.ggnet.dwoss.uniqueunit.ee.entity.UniqueUnit) Product(eu.ggnet.dwoss.uniqueunit.ee.entity.Product) Test(org.junit.Test)

Example 3 with UniqueUnit

use of eu.ggnet.dwoss.uniqueunit.ee.entity.UniqueUnit in project dwoss by gg-net.

the class RedTapeOperationOrderInvoiceIT method testCancelDocument.

@Test
public void testCancelDocument() throws UserInfoException {
    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();
    // Generate Dossier
    Dossier dos = redTapeWorker.create(customerId, true, "Me");
    Document doc1 = dos.getActiveDocuments(DocumentType.ORDER).get(0);
    assertThat(doc1).overridingErrorMessage("Expected active document Order, got null. Dossier: " + dos.toMultiLine()).isNotNull();
    // Create Positions
    Position p1 = NaivBuilderUtil.unit(uu1);
    Position p2 = NaivBuilderUtil.unit(uu2);
    Position p4 = NaivBuilderUtil.comment();
    Position p5 = NaivBuilderUtil.service();
    Position p6 = NaivBuilderUtil.batch(uuProduct1);
    Position p7 = NaivBuilderUtil.shippingcost();
    doc1.append(p1);
    doc1.append(p2);
    doc1.append(p4);
    doc1.append(p5);
    doc1.append(p6);
    doc1.append(p7);
    Position p3 = NaivBuilderUtil.unit(uu3);
    Position p8 = NaivBuilderUtil.unit(uu4);
    Dossier dos2 = redTapeWorker.create(customerId, false, "Me2");
    Document doc2 = dos2.getActiveDocuments(DocumentType.ORDER).get(0);
    assertThat(doc2).overridingErrorMessage("Expected active document Order, got null. Dossier: " + dos2.toMultiLine()).isNotNull();
    doc2.add(Document.Condition.CONFIRMED);
    doc2.add(Document.Condition.PAID);
    doc2.append(p3);
    doc2.append(p8);
    // 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));
    doc1.add(Document.Condition.CONFIRMED);
    doc1.setType(DocumentType.ORDER);
    doc1 = redTapeWorker.update(doc1, null, "Junit Test");
    doc1.add(Document.Condition.CANCELED);
    doc1 = redTapeWorker.update(doc1, null, "tester");
    assertTrue("Document doesent contain the Condition Canceled", doc1.getConditions().contains(Document.Condition.CANCELED));
    for (Position position : doc1.getPositions(PositionType.UNIT).values()) {
        StockUnit su = stockAgent.findStockUnitByUniqueUnitIdEager(position.getUniqueUnitId());
        assertNull(su + " should not have LogicTransaction", su.getLogicTransaction());
    }
}
Also used : UniqueUnit(eu.ggnet.dwoss.uniqueunit.ee.entity.UniqueUnit) Product(eu.ggnet.dwoss.uniqueunit.ee.entity.Product) StockUnit(eu.ggnet.dwoss.stock.ee.entity.StockUnit) Test(org.junit.Test)

Example 4 with UniqueUnit

use of eu.ggnet.dwoss.uniqueunit.ee.entity.UniqueUnit in project dwoss by gg-net.

the class RedTapeCloserOperationIT method buildBlocker.

/**
 * builds 4 blocker dossiers in the following manner:
 * - 1 comment only blocker
 * - 1 comment plus non unit/comment blocker
 * - 1 unit with stockunit blocker
 * - 1 unit without stockunit blocker
 */
private List<Dossier> buildBlocker() {
    Long customerId = (Long) systemCustomers.getSpecialCustomers().keySet().toArray()[0];
    Long receiptId = (Long) receiptCustomers.getReceiptCustomers().values().toArray()[0];
    Dossier d1 = redTapeWorker.create(customerId, R.nextBoolean(), "JUNIT");
    d1.getActiveDocuments(BLOCK).get(0).append(Position.builder().amount(1).type(PositionType.COMMENT).name("Comment").description("Comment").build());
    Dossier d2 = redTapeWorker.create(customerId, R.nextBoolean(), "JUNIT");
    Document doc2 = d2.getActiveDocuments(BLOCK).get(0);
    doc2.append(Position.builder().amount(1).type(PositionType.COMMENT).name("Comment").description("Comment").build());
    doc2.append(Position.builder().type(PositionType.SERVICE).price(100).tax(doc2.getSingleTax()).name("Service").description("Service").amount(1).bookingAccount(postLedger.get(PositionType.SERVICE, doc2.getTaxType()).orElse(null)).build());
    UniqueUnit unit1 = receiptGenerator.makeUniqueUnits(1, true, true).get(0);
    UniqueUnit unit2 = receiptGenerator.makeUniqueUnits(1, true, true).get(0);
    Dossier d3 = redTapeWorker.create(customerId, R.nextBoolean(), "JUNIT");
    d3.getActiveDocuments(BLOCK).get(0).append(Position.builder().amount(1).type(PositionType.UNIT).uniqueUnitId(unit1.getId()).uniqueUnitProductId(unit1.getProduct().getId()).price(unit1.getPrice(PriceType.SALE)).tax(d3.getActiveDocuments(BLOCK).get(0).getSingleTax()).description(UniqueUnitFormater.toDetailedDiscriptionLine(unit1)).name(UniqueUnitFormater.toPositionName(unit1)).refurbishedId(unit1.getIdentifier(REFURBISHED_ID)).build());
    Dossier d4 = redTapeWorker.create(customerId, R.nextBoolean(), "JUNIT");
    d4.getActiveDocuments(BLOCK).get(0).append(Position.builder().amount(1).type(PositionType.UNIT).uniqueUnitId(unit2.getId()).uniqueUnitProductId(unit2.getProduct().getId()).price(unit2.getPrice(PriceType.SALE)).tax(d4.getActiveDocuments(BLOCK).get(0).getSingleTax()).description(UniqueUnitFormater.toDetailedDiscriptionLine(unit2)).name(UniqueUnitFormater.toPositionName(unit2)).refurbishedId(unit2.getIdentifier(REFURBISHED_ID)).build());
    Dossier d5 = redTapeWorker.create(receiptId, R.nextBoolean(), "JUNIT");
    d5.getActiveDocuments(BLOCK).get(0).append(Position.builder().amount(1).type(PositionType.COMMENT).name("Comment").description("Comment").build());
    redTapeWorker.update(d1.getActiveDocuments(BLOCK).get(0), null, "JUNIT");
    redTapeWorker.update(d2.getActiveDocuments(BLOCK).get(0), null, "JUNIT");
    redTapeWorker.update(d3.getActiveDocuments(BLOCK).get(0), null, "JUNIT");
    redTapeWorker.update(d4.getActiveDocuments(BLOCK).get(0), null, "JUNIT");
    redTapeWorker.update(d5.getActiveDocuments(BLOCK).get(0), null, "JUNIT");
    redTapeCloserOpertaionItBean.deleteStockUnit(stockAgent.findStockUnitByRefurbishIdEager(unit2.getIdentifier(REFURBISHED_ID)).getId());
    return Arrays.asList(d1, d2, d3, d4, d5);
}
Also used : UniqueUnit(eu.ggnet.dwoss.uniqueunit.ee.entity.UniqueUnit)

Example 5 with UniqueUnit

use of eu.ggnet.dwoss.uniqueunit.ee.entity.UniqueUnit in project dwoss by gg-net.

the class RedTapeCloserOperationIT method testDayClosingWarrenty.

@Test
public void testDayClosingWarrenty() throws UserInfoException {
    long customerId = customerGenerator.makeCustomer();
    UniqueUnit uu = receiptGenerator.makeUniqueUnits(1, true, true).get(0);
    Product p = redTapeCloserOpertaionItBean.makeWarrantyProduct();
    CustomerMetaData metaCustomer = customerService.asCustomerMetaData(customerId);
    assertFalse("no customer in database", customerId == 0);
    assertFalse("bo unique unit in database", uu == null);
    assertFalse("no customer meta data found", metaCustomer == null);
    assertFalse("no warranty product in database", p == null);
    // Create a dossier on a random customer.
    Dossier dos = redTapeWorker.create(customerId, false, "Generated by RedTapeGeneratorOperation.makeSalesDossiers()");
    Document doc = dos.getActiveDocuments(DocumentType.ORDER).get(0);
    assertThat(doc).overridingErrorMessage("Expected active document Order, got null. Dossier: " + dos.toMultiLine()).isNotNull();
    double price = uu.getPrice(PriceType.CUSTOMER);
    if (price < 0.001)
        price = uu.getPrice(PriceType.RETAILER);
    if (price < 0.001)
        price = 1111.11;
    Position pos = Position.builder().amount(1).type(PositionType.UNIT).uniqueUnitId(uu.getId()).uniqueUnitProductId(uu.getProduct().getId()).price(price).tax(doc.getSingleTax()).description(UniqueUnitFormater.toDetailedDiscriptionLine(uu)).name(UniqueUnitFormater.toPositionName(uu)).build();
    pos.setRefurbishedId(uu.getRefurbishId());
    doc.appendAll(new RedTapeHookStup().elaborateUnitPosition(pos, doc.getId()).getPayload());
    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");
    redTapeCloser.executeManual("Junit");
    doc = redTapeAgent.findByIdEager(Document.class, doc.getId());
    doc.setType(DocumentType.COMPLAINT);
    doc.setDirective(Document.Directive.WAIT_FOR_COMPLAINT_COMPLETION);
    doc = redTapeWorker.update(doc, null, "JUnit");
    redTapeCloser.executeManual("Junit");
    redTapeCloserOpertaionItBean.checkReferences(dos.getId());
}
Also used : UniqueUnit(eu.ggnet.dwoss.uniqueunit.ee.entity.UniqueUnit) CustomerMetaData(eu.ggnet.dwoss.customer.opi.CustomerMetaData) Product(eu.ggnet.dwoss.uniqueunit.ee.entity.Product) Test(org.junit.Test)

Aggregations

UniqueUnit (eu.ggnet.dwoss.uniqueunit.ee.entity.UniqueUnit)88 UniqueUnitEao (eu.ggnet.dwoss.uniqueunit.ee.eao.UniqueUnitEao)38 Product (eu.ggnet.dwoss.uniqueunit.ee.entity.Product)31 StockUnit (eu.ggnet.dwoss.stock.ee.entity.StockUnit)27 Test (org.junit.Test)21 SubMonitor (eu.ggnet.dwoss.progress.SubMonitor)20 StockUnitEao (eu.ggnet.dwoss.stock.ee.eao.StockUnitEao)16 LogicTransaction (eu.ggnet.dwoss.stock.ee.entity.LogicTransaction)13 Document (eu.ggnet.dwoss.redtape.ee.entity.Document)8 StockTransaction (eu.ggnet.dwoss.stock.ee.entity.StockTransaction)8 UnitCollection (eu.ggnet.dwoss.uniqueunit.ee.entity.UnitCollection)7 java.util (java.util)7 Dossier (eu.ggnet.dwoss.redtape.ee.entity.Dossier)6 Position (eu.ggnet.dwoss.redtape.ee.entity.Position)6 ProductSpec (eu.ggnet.dwoss.spec.ee.entity.ProductSpec)6 Stock (eu.ggnet.dwoss.stock.ee.entity.Stock)6 UniqueUnitAgent (eu.ggnet.dwoss.uniqueunit.ee.UniqueUnitAgent)6 FileJacket (eu.ggnet.dwoss.util.FileJacket)6 DocumentType (eu.ggnet.dwoss.rules.DocumentType)5 Collectors (java.util.stream.Collectors)5