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());
}
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());
}
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;
}
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();
}
}
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);
}
Aggregations