Search in sources :

Example 56 with UniqueUnit

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

the class PriceCoreOperationIT method testStore.

@Test
public void testStore() {
    stockGenerator.makeStocksAndLocations(2);
    receiptGenerator.makeUniqueUnits(20, true, false);
    // Estimate all Units
    List<PriceEngineResult> pers = priceCore.loadAndCalculate(null);
    final double fixedUnitPrice = 100;
    final double fixedProductPrice = 50;
    String fixedPriceRefurbishId = pers.get(0).getRefurbishedId();
    pers.get(0).setCustomerPrice(100);
    pers.get(0).setRetailerPrice(100);
    pers.get(0).setUnitPriceFixed(PriceEngineResult.Change.SET);
    String fixedPartNo = pers.get(3).getManufacturerPartNo();
    pers.get(3).setCustomerPrice(50);
    pers.get(3).setRetailerPrice(50);
    pers.get(3).setManufacturerPartPriceFixed(PriceEngineResult.Change.SET);
    priceCore.store(pers, "via test", "testuser", null);
    UniqueUnit uniqueUnit = uniqueUnitAgent.findUnitByIdentifierEager(Identifier.REFURBISHED_ID, fixedPriceRefurbishId);
    assertEquals(fixedUnitPrice, uniqueUnit.getPrice(PriceType.CUSTOMER), 0.001);
    assertEquals(fixedUnitPrice, uniqueUnit.getPrice(PriceType.RETAILER), 0.001);
    assertTrue("Unit should contain Flage PriceFixed" + uniqueUnit.getFlags(), uniqueUnit.getFlags().contains(UniqueUnit.Flag.PRICE_FIXED));
    for (PriceHistory priceHistory : uniqueUnit.getPriceHistory()) {
        assertTrue(priceHistory.getComment().contains("unitfix"));
        assertEquals(fixedUnitPrice, priceHistory.getPrice(), 0.001);
        assertTrue(priceHistory.getType() == PriceType.CUSTOMER || priceHistory.getType() == PriceType.RETAILER);
    }
    Product product = uniqueUnitAgent.findProductByPartNoEager(fixedPartNo);
    assertEquals(fixedProductPrice, product.getPrice(PriceType.CUSTOMER), 0.001);
    assertEquals(fixedProductPrice, product.getPrice(PriceType.RETAILER), 0.001);
    assertTrue(product.getFlags().contains(Product.Flag.PRICE_FIXED));
    for (PriceHistory priceHistory : product.getPriceHistory()) {
        assertTrue(priceHistory.getComment().contains("productfix"));
        assertEquals(fixedProductPrice, priceHistory.getPrice(), 0.001);
        assertTrue(priceHistory.getType() == PriceType.CUSTOMER || priceHistory.getType() == PriceType.RETAILER);
    }
}
Also used : UniqueUnit(eu.ggnet.dwoss.uniqueunit.ee.entity.UniqueUnit) PriceEngineResult(eu.ggnet.dwoss.price.engine.PriceEngineResult) Product(eu.ggnet.dwoss.uniqueunit.ee.entity.Product) PriceHistory(eu.ggnet.dwoss.uniqueunit.ee.entity.PriceHistory) Test(org.junit.Test)

Example 57 with UniqueUnit

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

the class UnitProcessorOperation method validateReceipt.

private void validateReceipt(UniqueUnit receiptUnit) throws IllegalArgumentException {
    if (receiptUnit.getId() > 0)
        throw new IllegalArgumentException("UniqueUnit has already been persisted " + receiptUnit);
    UniqueUnitEao uniqueUnitEao = new UniqueUnitEao(uuEm);
    UniqueUnit uniqueUnit = uniqueUnitEao.findByIdentifier(Identifier.REFURBISHED_ID, receiptUnit.getIdentifier(Identifier.REFURBISHED_ID));
    if (uniqueUnit != null)
        throw new IllegalArgumentException("Unit with refurbishedId=" + receiptUnit.getRefurbishId() + " exists.\n- Supplied Unit:" + receiptUnit + "\n- Database Unit:" + uniqueUnit);
    StockUnit stockUnit = new StockUnitEao(stockEm).findByRefurbishId(receiptUnit.getRefurbishId());
    if (stockUnit != null)
        throw new IllegalArgumentException(stockUnit + " exists");
}
Also used : UniqueUnit(eu.ggnet.dwoss.uniqueunit.ee.entity.UniqueUnit) StockUnitEao(eu.ggnet.dwoss.stock.ee.eao.StockUnitEao) StockUnit(eu.ggnet.dwoss.stock.ee.entity.StockUnit) UniqueUnitEao(eu.ggnet.dwoss.uniqueunit.ee.eao.UniqueUnitEao)

Example 58 with UniqueUnit

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

the class UnitSupporterOperation method findRefurbishIdBySerial.

@Override
public String findRefurbishIdBySerial(String serial) {
    UniqueUnitEao uniqueUnitEao = new UniqueUnitEao(uuEm);
    UniqueUnit uu = uniqueUnitEao.findByIdentifier(UniqueUnit.Identifier.SERIAL, serial);
    if (uu != null)
        return uu.getIdentifier(UniqueUnit.Identifier.REFURBISHED_ID);
    return null;
}
Also used : UniqueUnit(eu.ggnet.dwoss.uniqueunit.ee.entity.UniqueUnit) UniqueUnitEao(eu.ggnet.dwoss.uniqueunit.ee.eao.UniqueUnitEao)

Example 59 with UniqueUnit

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

the class UnitSupporterOperation method isRefurbishIdAvailable.

/**
 * Returns true if supplied refurbishId is available, meaning not jet in the database.
 *
 * @param refurbishId the refubishedId
 * @return true if available.
 */
@Override
public boolean isRefurbishIdAvailable(String refurbishId) {
    UniqueUnit uniqueUnit = new UniqueUnitEao(uuEm).findByIdentifier(UniqueUnit.Identifier.REFURBISHED_ID, refurbishId);
    if (uniqueUnit != null)
        return false;
    if (bridgeInstance.isUnsatisfied())
        return true;
    LegacyLocalBridge bridge = bridgeInstance.get();
    L.info("Using LegacyBridge ({})", bridge.localName());
    return bridge.isUnitIdentifierAvailable(refurbishId);
}
Also used : UniqueUnit(eu.ggnet.dwoss.uniqueunit.ee.entity.UniqueUnit) LegacyLocalBridge(eu.ggnet.dwoss.redtape.ee.api.LegacyLocalBridge) UniqueUnitEao(eu.ggnet.dwoss.uniqueunit.ee.eao.UniqueUnitEao)

Example 60 with UniqueUnit

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

the class ReceiptGeneratorOperation method makeUniqueUnits.

/**
 * Generates an amount of UniquUnits and receipts them.
 *
 * @param amount               the amount to generate.
 * @param generateSalesChannel
 * @param generatePrice        if true a random customer and retailer price is set
 * @return the generated and receipted UniquUnits.
 */
// TODO: Create more Shipments on multiple contractors.
public List<UniqueUnit> makeUniqueUnits(int amount, boolean generateSalesChannel, boolean generatePrice) {
    final int minProducts = 5;
    final int maxProducts = 450;
    int amountProducts = (amount / 25);
    if (amountProducts <= minProducts)
        amountProducts = minProducts;
    if (amountProducts >= maxProducts)
        amountProducts = maxProducts;
    L.info("Generating {} Units", amount);
    SubMonitor m = monitorFactory.newSubMonitor("Generating " + amount + " Units", amount);
    m.start();
    List<ProductSpec> productSpecs = makeProductSpecs(amountProducts, generatePrice);
    List<UniqueUnit> units = new ArrayList<>();
    Stock stock = findOrMakeStock();
    TradeName contractor = new ArrayList<>(contractors.all()).get(R.nextInt(contractors.all().size()));
    Shipment shipment = new Shipment("TEST-SHIPMENT-" + R.nextInt(10), contractor, TradeName.ACER, Shipment.Status.OPENED);
    stockEm.persist(shipment);
    StockTransaction transaction = stockTransactionEmo.requestRollInPrepared(stock.getId(), "SampleGenerator", "Rollin via make UniqueUnits");
    L.debug("Transaction prepared {}", transaction);
    for (int i = 0; i < amount; i++) {
        ProductSpec productSpec = productSpecs.get(R.nextInt(productSpecs.size()));
        Product product = uniqueUnitAgent.findById(Product.class, productSpec.getProductId());
        UniqueUnit unit = unitGenerator.makeUniqueUnit(contractor, product);
        m.worked(1, "created SopoNr " + unit.getRefurbishId());
        if (generatePrice) {
            int price = R.nextInt(1000) + 1;
            unit.setPrice(PriceType.CUSTOMER, price, "Generated by ReceiptGeneratorOperation.makeUniqueUnits()");
            unit.setPrice(PriceType.RETAILER, price * 1.08, "Generated by ReceiptGeneratorOperation.makeUniqueUnits()");
        }
        if (generateSalesChannel)
            unit.setSalesChannel(R.nextBoolean() ? SalesChannel.CUSTOMER : SalesChannel.RETAILER);
        unitProcessor.receipt(unit, product, shipment, transaction, ReceiptOperation.SALEABLE, "SampleGenerator", "Generator");
        // Ad the now persisted instance.
        units.add(uniqueUnitAgent.findUnitByIdentifierEager(REFURBISHED_ID, unit.getRefurbishId()));
    }
    stockTransactionProcessor.rollIn(Arrays.asList(transaction), "JUnit");
    m.finish();
    return units;
}
Also used : SubMonitor(eu.ggnet.dwoss.progress.SubMonitor) Shipment(eu.ggnet.dwoss.stock.ee.entity.Shipment) Product(eu.ggnet.dwoss.uniqueunit.ee.entity.Product) ProductSpec(eu.ggnet.dwoss.spec.ee.entity.ProductSpec) UniqueUnit(eu.ggnet.dwoss.uniqueunit.ee.entity.UniqueUnit) Stock(eu.ggnet.dwoss.stock.ee.entity.Stock) StockTransaction(eu.ggnet.dwoss.stock.ee.entity.StockTransaction)

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