Search in sources :

Example 6 with ProductSpec

use of eu.ggnet.dwoss.spec.ee.entity.ProductSpec in project dwoss by gg-net.

the class UiProductSupport method createOrEditPart.

// DesktopBundleView and internal.
/**
 * Creates or edits Product with partNo.
 * <p/>
 * @param manufacturer     the manufacturer.
 * @param partNo           the partNo
 * @param allowedEditGroup if not null and there exist a Product with the partNo, the ProductGroup of that product must be like the parameter.
 * @param selectedBrand    if not null the brand is assumed as selected and may not be changed.
 * @param parent           the parent window for localisation
 * @return the created or edited ProductSpec
 * @throws UserInfoException if not ok
 */
public static ProductSpec createOrEditPart(TradeName manufacturer, String partNo, TradeName selectedBrand, ProductGroup allowedEditGroup, Window parent) throws UserInfoException {
    validatePartNo(manufacturer, partNo);
    ProductSpec productSpec = Dl.remote().lookup(SpecAgent.class).findProductSpecByPartNoEager(partNo);
    boolean edit = false;
    if (productSpec != null) {
        edit = true;
        if (allowedEditGroup != null && selectedBrand != null) {
            if (productSpec.getModel().getFamily().getSeries().getGroup() != allowedEditGroup) {
                throw new UserInfoException("Erlaubte Warengruppe ist " + allowedEditGroup + ", Artikel ist aber " + SpecFormater.toDetailedName(productSpec));
            } else if (productSpec.getModel().getFamily().getSeries().getBrand() != selectedBrand) {
                throw new UserInfoException("Ausgewählte Marke ist " + selectedBrand + ", Artikel ist aber " + SpecFormater.toDetailedName(productSpec));
            }
        }
    }
    SimpleView simpleView;
    if (edit)
        simpleView = new SimpleView(productSpec);
    else if (allowedEditGroup != null && selectedBrand != null)
        simpleView = new SimpleView(partNo, selectedBrand, allowedEditGroup);
    else
        simpleView = new SimpleView(manufacturer, partNo);
    OkCancelDialog<SimpleView> simpleDialog = new OkCancelDialog<>(parent, "Artikelkonfiguration", simpleView);
    simpleDialog.setVisible(true);
    if (simpleDialog.isCancel())
        return null;
    ProductSpec spec = simpleView.getProductSpec();
    if (edit)
        spec = Dl.remote().lookup(ProductProcessor.class).refresh(spec, simpleView.getSelectedModel().get());
    AbstractView productView = AbstractView.newView(spec, simpleView.getSelectedModel().get().getFamily().getSeries().getBrand());
    if (edit)
        productView.setGtin(Dl.remote().lookup(UniqueUnitAgent.class).findById(Product.class, spec.getProductId()).getGtin());
    OkCancelDialog productDialog = new OkCancelDialog(parent, "Artikeldetailkonfiguration", productView);
    productDialog.setVisible(true);
    if (productDialog.isCancel())
        return null;
    validate(simpleView.getSelectedModel().get());
    validate(productView.getSpec());
    if (edit)
        return Dl.remote().lookup(ProductProcessor.class).update(productView.getSpec(), productView.getGtin());
    else
        // TODO: In Case of a Bundle autoupdate the name of the model.
        return Dl.remote().lookup(ProductProcessor.class).create(productView.getSpec(), simpleView.getSelectedModel().get(), productView.getGtin());
}
Also used : AbstractView(eu.ggnet.dwoss.receipt.product.AbstractView) SpecAgent(eu.ggnet.dwoss.spec.ee.SpecAgent) SimpleView(eu.ggnet.dwoss.receipt.product.SimpleView) OkCancelDialog(eu.ggnet.dwoss.util.OkCancelDialog) Product(eu.ggnet.dwoss.uniqueunit.ee.entity.Product) ProductSpec(eu.ggnet.dwoss.spec.ee.entity.ProductSpec) UserInfoException(eu.ggnet.dwoss.util.UserInfoException) ProductProcessor(eu.ggnet.dwoss.receipt.ee.ProductProcessor)

Example 7 with ProductSpec

use of eu.ggnet.dwoss.spec.ee.entity.ProductSpec 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 8 with ProductSpec

use of eu.ggnet.dwoss.spec.ee.entity.ProductSpec in project dwoss by gg-net.

the class ReceiptGeneratorOperation method makeProductSpecs.

/**
 * Generates an amount of ProductSpecs and receipts them.
 * Persists entities in spec and uniqueunit.
 *
 * @param amount            the amount to generate.
 * @param generateCostPrice
 * @return the generated and receipted specs.
 */
public List<ProductSpec> makeProductSpecs(int amount, boolean generateCostPrice) {
    L.info("Generating {} Products", amount);
    SubMonitor m = monitorFactory.newSubMonitor("Generating " + amount + " Products", amount);
    m.start();
    List<ProductSpec> specs = new ArrayList<>();
    for (int i = 0; i < amount; i++) {
        ProductSpec spec = makeProductSpec(generateCostPrice);
        specs.add(spec);
        m.worked(1, spec.getPartNo());
    }
    m.finish();
    return specs;
}
Also used : SubMonitor(eu.ggnet.dwoss.progress.SubMonitor) ProductSpec(eu.ggnet.dwoss.spec.ee.entity.ProductSpec)

Example 9 with ProductSpec

use of eu.ggnet.dwoss.spec.ee.entity.ProductSpec 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 10 with ProductSpec

use of eu.ggnet.dwoss.spec.ee.entity.ProductSpec in project dwoss by gg-net.

the class ExporterOperation method onePrice.

/**
 * Calculates a Price for on Unit.
 *
 * @param refurbishId the refurbishId
 * @return The PriceEngineResult or Null if Id not found
 */
@Override
public PriceEngineResult onePrice(String refurbishId) {
    final UniqueUnitEao uniqueUnitEao = new UniqueUnitEao(uuEm);
    final ProductSpecEao productSpecEao = new ProductSpecEao(specEm);
    final StockUnitEao suEao = new StockUnitEao(stockEm);
    L.info("Loading s.getUnit({})", refurbishId);
    UniqueUnit uu = uniqueUnitEao.findByIdentifier(UniqueUnit.Identifier.REFURBISHED_ID, refurbishId);
    if (uu == null)
        return null;
    ProductSpec spec = productSpecEao.findByProductId(uu.getProduct().getId());
    String stock = suEao.findByUniqueUnitId(uu.getId()).getStock().getName();
    return priceEngine.estimate(uu, spec, stock);
}
Also used : StockUnitEao(eu.ggnet.dwoss.stock.ee.eao.StockUnitEao) ProductSpec(eu.ggnet.dwoss.spec.ee.entity.ProductSpec) ProductSpecEao(eu.ggnet.dwoss.spec.ee.eao.ProductSpecEao) UniqueUnitEao(eu.ggnet.dwoss.uniqueunit.ee.eao.UniqueUnitEao)

Aggregations

ProductSpec (eu.ggnet.dwoss.spec.ee.entity.ProductSpec)26 Test (org.junit.Test)10 ProductModel (eu.ggnet.dwoss.spec.ee.entity.ProductModel)8 Product (eu.ggnet.dwoss.uniqueunit.ee.entity.Product)8 ProductFamily (eu.ggnet.dwoss.spec.ee.entity.ProductFamily)7 ProductSeries (eu.ggnet.dwoss.spec.ee.entity.ProductSeries)7 Cpu (eu.ggnet.dwoss.spec.ee.entity.piece.Cpu)6 Gpu (eu.ggnet.dwoss.spec.ee.entity.piece.Gpu)6 UniqueUnit (eu.ggnet.dwoss.uniqueunit.ee.entity.UniqueUnit)6 SubMonitor (eu.ggnet.dwoss.progress.SubMonitor)4 ProductSpecEao (eu.ggnet.dwoss.spec.ee.eao.ProductSpecEao)4 Notebook (eu.ggnet.dwoss.spec.ee.entity.Notebook)4 Display (eu.ggnet.dwoss.spec.ee.entity.piece.Display)4 SpecAgent (eu.ggnet.dwoss.spec.ee.SpecAgent)3 SpecGenerator (eu.ggnet.dwoss.spec.ee.assist.gen.SpecGenerator)3 Desktop (eu.ggnet.dwoss.spec.ee.entity.Desktop)3 DesktopBundle (eu.ggnet.dwoss.spec.ee.entity.DesktopBundle)3 Shipment (eu.ggnet.dwoss.stock.ee.entity.Shipment)3 Stock (eu.ggnet.dwoss.stock.ee.entity.Stock)3 StockTransaction (eu.ggnet.dwoss.stock.ee.entity.StockTransaction)3