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