Search in sources :

Example 6 with Product

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

the class ReceiptGeneratorOperation method makeUniqueUnit.

/**
 * Generates one UniquUnits and receipts it.
 *
 * @return the generated UniquUnits.
 */
public UniqueUnit makeUniqueUnit() {
    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 makeUniqueUnit");
    ProductSpec productSpec = makeProductSpec();
    Product product = uniqueUnitAgent.findById(Product.class, productSpec.getProductId());
    UniqueUnit unit = unitGenerator.makeUniqueUnit(contractor, product);
    unitProcessor.receipt(unit, product, shipment, transaction, ReceiptOperation.SALEABLE, "SampleGenerator", "Generator");
    stockTransactionProcessor.rollIn(Arrays.asList(transaction), "JUnit");
    return uniqueUnitAgent.findUnitByIdentifierEager(REFURBISHED_ID, unit.getRefurbishId());
}
Also used : UniqueUnit(eu.ggnet.dwoss.uniqueunit.ee.entity.UniqueUnit) Shipment(eu.ggnet.dwoss.stock.ee.entity.Shipment) Product(eu.ggnet.dwoss.uniqueunit.ee.entity.Product) ProductSpec(eu.ggnet.dwoss.spec.ee.entity.ProductSpec) Stock(eu.ggnet.dwoss.stock.ee.entity.Stock) StockTransaction(eu.ggnet.dwoss.stock.ee.entity.StockTransaction)

Example 7 with Product

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

the class ReceiptGeneratorOperationIT method testMakeProductSpecsAndUniqueUnits.

@Test
public void testMakeProductSpecsAndUniqueUnits() throws Exception {
    List<ProductSpec> specs = receiptGenerator.makeProductSpecs(20, true);
    assertThat(specs).as("Generated ProductSpecs").isNotEmpty().hasSize(20);
    for (ProductSpec spec : specs) {
        assertThat(spec.getId()).as("ProductSpec.id").isGreaterThan(0);
        assertThat(spec.getProductId()).as("ProductSpec.productId").isGreaterThan(0);
        Product product = productEao.findById(spec.getProductId());
        assertThat(product).as("uniqueunit.Product of spec.ProductSpec").isNotNull();
    }
    List<UniqueUnit> uniqueunits = receiptGenerator.makeUniqueUnits(20, true, true);
    assertThat(uniqueunits).as("Generated UniqueUnits").isNotEmpty().hasSize(20);
    for (UniqueUnit uniqueunit : uniqueunits) {
        assertThat(uniqueunit.getId()).as("UniqueUnit.id").isGreaterThan(0);
        StockUnit stockUnit = stockUnitEao.findByUniqueUnitId(uniqueunit.getId());
        assertThat(stockUnit).describedAs("StockUnit of generated UniqueUnit").isNotNull();
        assertThat(stockUnit.getStock()).describedAs("Stock of StockUnit of generated UniqueUnit").isNotNull();
    }
}
Also used : UniqueUnit(eu.ggnet.dwoss.uniqueunit.ee.entity.UniqueUnit) Product(eu.ggnet.dwoss.uniqueunit.ee.entity.Product) ProductSpec(eu.ggnet.dwoss.spec.ee.entity.ProductSpec) StockUnit(eu.ggnet.dwoss.stock.ee.entity.StockUnit) Test(org.junit.Test)

Example 8 with Product

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

the class PriceCoreOperation method store.

/**
 * Stores the supplied Prices to units and the manufacturerPartNoPriceFixeds
 *
 * @param pers     results to store
 * @param comment  a comment for the price history
 * @param arranger a arranger for the price history
 * @param monitor  an optional monitor
 */
public void store(final List<PriceEngineResult> pers, String comment, String arranger, IMonitor monitor) {
    final SubMonitor m = SubMonitor.convert(monitor, pers.size() + 27);
    UniqueUnitEao uniqueUnitEao = new UniqueUnitEao(uuEm);
    ProductEao productEao = new ProductEao(uuEm);
    // preload sopo and unique units
    m.message("Preloading UniqueUnits");
    NavigableMap<String, UniqueUnit> uniqueUnits = UniqueUnit.asMapByRefurbishId(uniqueUnitEao.findByIdentifiers(REFURBISHED_ID, PriceEngineResult.toRefurbishIds(pers)));
    m.worked(5);
    for (PriceEngineResult per : pers) {
        String msg = "Storing Unit " + per.getRefurbishedId() + " HP:" + per.getRetailerPrice() + " EP:" + per.getCustomerPrice() + " UnitFix:" + per.getUnitPriceFixed() + " ProductFix:" + per.getManufacturerPartPriceFixed();
        L.info(msg);
        m.worked(1, msg);
        update(uniqueUnits.get(per.getRefurbishedId()), per, arranger, comment);
    }
    // Inferenced filtering for fixprices
    Map<String, PriceEngineResult> fixPriceImports = new HashMap<>();
    for (PriceEngineResult per : pers) {
        if (per.getManufacturerPartPriceFixed() == NO_CHANGE)
            continue;
        fixPriceImports.put(per.getManufacturerPartNo(), per);
    }
    m.worked(1, "Perloading Products");
    NavigableMap<String, Product> products = Product.asMapByPartNos(productEao.findByPartNos(PriceEngineResult.toPartNos(pers)));
    m.worked(3);
    m.setWorkRemaining(fixPriceImports.size());
    for (PriceEngineResult per : fixPriceImports.values()) {
        update(products.get(per.getManufacturerPartNo()), per, arranger, comment);
        String msg = "Storing ProductDescription Fixed Price " + per.getProductName() + " Retailer:" + per.getRetailerPrice() + " Customer:" + per.getCustomerPrice() + " Manual:" + per.getManufacturerPartPriceFixed();
        L.info(msg);
        m.worked(1, msg);
    }
    m.finish();
}
Also used : UniqueUnit(eu.ggnet.dwoss.uniqueunit.ee.entity.UniqueUnit) PriceEngineResult(eu.ggnet.dwoss.price.engine.PriceEngineResult) SubMonitor(eu.ggnet.dwoss.progress.SubMonitor) Product(eu.ggnet.dwoss.uniqueunit.ee.entity.Product) ProductEao(eu.ggnet.dwoss.uniqueunit.ee.eao.ProductEao) UniqueUnitEao(eu.ggnet.dwoss.uniqueunit.ee.eao.UniqueUnitEao)

Example 9 with Product

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

the class PriceCoreOperation method loadAndCalculate.

/**
 * Loads all AVAILABLE SopoUnits from the Sopodb an puts them trough the PriceEngine
 *
 * @param monitor
 * @return
 */
public List<PriceEngineResult> loadAndCalculate(IMonitor monitor) {
    L.info("Starting loadAndCalculate()");
    final SubMonitor m = SubMonitor.convert(monitor, 100);
    m.start();
    final StockUnitEao stockUnitEao = new StockUnitEao(stockEm);
    final UniqueUnitEao uniqueUnitEao = new UniqueUnitEao(uuEm);
    final ProductSpecEao productSpecEao = new ProductSpecEao(specEm);
    m.message("loading Units");
    List<Integer> uuids = stockUnitEao.findByNoLogicTransactionAsUniqueUnitId();
    List<UniqueUnit> uus = uniqueUnitEao.findByIds(uuids);
    m.worked(10, "updating Eols");
    updateEols(uus);
    m.worked(5, "loading ProductSpecs");
    Set<Product> products = toProducts(uus);
    List<ProductSpec> productSpecs = productSpecEao.findByProductIds(toProductIds(products));
    Map<Product, ProductSpec> productToSpecs = toProductProductSpec(products, productSpecs);
    m.worked(10);
    final List<PriceEngineResult> pers = new ArrayList<>();
    m.setWorkRemaining(uus.size() + 5);
    for (UniqueUnit uu : uus) {
        m.worked(1, "Calculating RefurbishId(" + uu.getRefurbishId() + ")");
        StockUnit su = stockUnitEao.findByUniqueUnitId(uu.getId());
        pers.add(priceEngine.estimate(uu, productToSpecs.get(uu.getProduct()), su.getStock() != null ? su.getStock().getName() : "kein Lager"));
    }
    m.finish();
    L.info("Finished loadAndCalculate(), estimated {} Units", pers.size());
    return pers;
}
Also used : PriceEngineResult(eu.ggnet.dwoss.price.engine.PriceEngineResult) SubMonitor(eu.ggnet.dwoss.progress.SubMonitor) Product(eu.ggnet.dwoss.uniqueunit.ee.entity.Product) ProductSpec(eu.ggnet.dwoss.spec.ee.entity.ProductSpec) UniqueUnitEao(eu.ggnet.dwoss.uniqueunit.ee.eao.UniqueUnitEao) UniqueUnit(eu.ggnet.dwoss.uniqueunit.ee.entity.UniqueUnit) StockUnitEao(eu.ggnet.dwoss.stock.ee.eao.StockUnitEao) ProductSpecEao(eu.ggnet.dwoss.spec.ee.eao.ProductSpecEao) StockUnit(eu.ggnet.dwoss.stock.ee.entity.StockUnit)

Example 10 with Product

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

the class PriceEngine method estimate.

/**
 * Executes the Estimation for one SopoUnit.
 * This Method never fails an always returns a usable not null PriceEngineResult
 *
 * @param uu   the UniqueUnit
 * @param spec the ProductSpec
 * @param stock the Stock
 * @return a estimated PriceEngineResult.
 */
public PriceEngineResult estimate(UniqueUnit uu, ProductSpec spec, String stock) {
    Objects.requireNonNull(uu, "UniqueUnit is null");
    Product p = Objects.requireNonNull(uu.getProduct(), "Product of " + uu + " is null");
    Objects.requireNonNull(spec, "ProductSpec is null");
    PriceEngineResult per = new PriceEngineResult(uu, stock);
    TraceCollector log = new TraceCollector();
    per.setTax(GlobalConfig.DEFAULT_TAX.getTax());
    per.setWarrantyId(uu.getWarranty().ordinal());
    if (uu.getWarranty().equals(Warranty.WARRANTY_TILL_DATE)) {
        per.setWarrentyValid(uu.getWarrentyValid());
    }
    L.debug("Starting estimation for refuribisId:{}", uu.getRefurbishId());
    if (uu.getFlags().contains(UniqueUnit.Flag.PRICE_FIXED) || p.getFlags().contains(Product.Flag.PRICE_FIXED)) {
        EngineTracer et = new EngineTracer(PriceEngine.class.getSimpleName(), "estimate");
        if (uu.getFlags().contains(UniqueUnit.Flag.PRICE_FIXED)) {
            L.debug("refurbishId:{} has UnitPriceFixed", uu.getRefurbishId());
            per.setCustomerPrice(uu.getPrice(PriceType.CUSTOMER));
            per.setRetailerPrice(uu.getPrice(PriceType.RETAILER));
            per.setUnitPriceFixed(SET);
            per.setSpecial("FIX UNIT");
            et.info("UnitFixPrice");
        } else {
            L.debug("refurbishId:{} has PartPriceFixed", uu.getRefurbishId());
            per.setCustomerPrice(p.getPrice(PriceType.CUSTOMER));
            per.setRetailerPrice(p.getPrice(PriceType.RETAILER));
            per.setManufacturerPartPriceFixed(SET);
            per.setSpecial("FIX PRODUCT");
            et.info("ProductFixPrice");
        }
        log.add(et);
    } else if (!estimator.isUnsatisfied()) {
        Result result = estimator.get().estimate(spec, uu);
        L.debug("{}", result);
        log.add(result.getTracer());
        per.setSpecial(result.getTag());
        per.setRetailerPrice(result.getRetailerPrice());
        per.setCustomerPrice(result.getCustomerPrice());
        per.setRetailerToCustomerPricePercentage(result.getRetailerToCustomerPricePercentage());
    } else {
        L.debug("No Estimator found for {},{}", uu, spec);
        per.setSpecial("NO ESTIMATION");
    }
    per.consumeLog(log);
    return per;
}
Also used : TraceCollector(eu.ggnet.dwoss.price.engine.support.TraceCollector) Product(eu.ggnet.dwoss.uniqueunit.ee.entity.Product) EngineTracer(eu.ggnet.dwoss.price.api.EngineTracer) Result(eu.ggnet.dwoss.price.api.Estimator.Result)

Aggregations

Product (eu.ggnet.dwoss.uniqueunit.ee.entity.Product)50 UniqueUnit (eu.ggnet.dwoss.uniqueunit.ee.entity.UniqueUnit)29 Test (org.junit.Test)16 SubMonitor (eu.ggnet.dwoss.progress.SubMonitor)13 StockUnit (eu.ggnet.dwoss.stock.ee.entity.StockUnit)11 ProductEao (eu.ggnet.dwoss.uniqueunit.ee.eao.ProductEao)11 UniqueUnitEao (eu.ggnet.dwoss.uniqueunit.ee.eao.UniqueUnitEao)9 ProductSpec (eu.ggnet.dwoss.spec.ee.entity.ProductSpec)8 StockUnitEao (eu.ggnet.dwoss.stock.ee.eao.StockUnitEao)5 LogicTransaction (eu.ggnet.dwoss.stock.ee.entity.LogicTransaction)5 PriceType (eu.ggnet.dwoss.uniqueunit.ee.entity.PriceType)5 java.util (java.util)5 Stock (eu.ggnet.dwoss.stock.ee.entity.Stock)4 StockTransaction (eu.ggnet.dwoss.stock.ee.entity.StockTransaction)4 CategoryProduct (eu.ggnet.dwoss.uniqueunit.ee.entity.CategoryProduct)4 UnitCollection (eu.ggnet.dwoss.uniqueunit.ee.entity.UnitCollection)4 JExcelLucidCalcReader (eu.ggnet.lucidcalc.jexcel.JExcelLucidCalcReader)4 PriceEngineResult (eu.ggnet.dwoss.price.engine.PriceEngineResult)3 TradeName (eu.ggnet.dwoss.rules.TradeName)3 CustomerMetaData (eu.ggnet.dwoss.customer.opi.CustomerMetaData)2