use of eu.ggnet.dwoss.stock.ee.entity.StockUnit in project dwoss by gg-net.
the class RedTapeCloserOperation method filterOpenStockTransactions.
/**
* Filters out all {@link Document}'s with associated {@link StockUnit}'s on an open {@link StockTransaction}.
* See {@link StockTransactionStatusType} and {@link StockTransaction#POSSIBLE_STATUS_TYPES} for details about open {@link StockTransaction}.
* <p>
* <p/>
* @param documents the documents as reference
* @param monitor a optional monitor
* @return all documents which are not on open transactions.
*/
private Set<Document> filterOpenStockTransactions(Set<Document> documents, IMonitor monitor) {
SubMonitor m = SubMonitor.convert(monitor, documents.size());
m.start();
m.message(" filtere");
for (Iterator<Document> it = documents.iterator(); it.hasNext(); ) {
Document document = it.next();
m.worked(1, " filtere " + document.getIdentifier());
LogicTransaction lt = ltEao.findByDossierId(document.getDossier().getId());
if (lt == null)
continue;
for (StockUnit stockUnit : lt.getUnits()) {
if (!validator.validate(stockUnit).isEmpty() || stockUnit.isInTransaction() || stockUnit.getStock() == null) {
it.remove();
L.warn("Closing: The Dossier(id={},customerId={}) has the Unit(refurbhisId={})" + " which is in an invalid state (validation error,open StockTransaction), excluding Dossier from closing.", document.getDossier().getId(), document.getDossier().getCustomerId(), stockUnit.getRefurbishId());
break;
}
}
}
m.finish();
return documents;
}
use of eu.ggnet.dwoss.stock.ee.entity.StockUnit in project dwoss by gg-net.
the class RedTapeUpdateRepaymentWorkflow method optionalTransferToDestination.
/**
* Validate if all StockUnits are on the destination Stock, and if not transfer them.
*
* @param stockUnits the stockUnits to validate
*/
void optionalTransferToDestination(List<StockUnit> stockUnits, int destinationId) {
List<StockUnit> onWrongStock = new ArrayList<>();
for (StockUnit stockUnit : stockUnits) {
// We are ignoring everything on a transaction.
if (stockUnit.isInTransaction())
continue;
if (stockUnit.getStock().getId() != destinationId)
onWrongStock.add(stockUnit);
}
if (onWrongStock.isEmpty())
return;
StockTransactionEmo transactionEmo = new StockTransactionEmo(stockEm);
StockTransaction transfer = transactionEmo.requestExternalTransferPrepare(onWrongStock.get(0).getStock().getId(), destinationId, arranger, "Transfer durch Gutschrift");
for (StockUnit stockUnit : onWrongStock) transfer.addUnit(stockUnit);
List<StockUnit> transferdUnits = transactionEmo.completeExternalTransfer(arranger, Arrays.asList(transfer));
L.info("Destination {} for units on wrong stock used: {}", transferdUnits);
}
use of eu.ggnet.dwoss.stock.ee.entity.StockUnit in project dwoss by gg-net.
the class CreditMemoReportIT method testCreditMemoReportOperation.
@Test
public void testCreditMemoReportOperation() throws IOException, InterruptedException {
long customerId = customerGenerator.makeCustomer();
List<UniqueUnit> uus = receiptGenerator.makeUniqueUnits(4, true, true);
UniqueUnit uu1 = uus.get(0);
UniqueUnit uu2 = uus.get(1);
UniqueUnit uu3 = uus.get(2);
UniqueUnit uu4 = uus.get(3);
Product uuProduct1 = uu1.getProduct();
assertThat(uu1).describedAs("First generated UniqueUnit").isNotNull();
StockUnit su1 = stockAgent.findStockUnitByUniqueUnitIdEager(uu1.getId());
assertThat(su1).describedAs("StockUnit of generated UniqueUnit").isNotNull();
assertThat(su1.getStock()).describedAs("Stock of StockUnit of generated UniqueUnit").isNotNull();
int stockIdOfUU1 = su1.getStock().getId();
Dossier dos = redTapeWorker.create(customerId, true, "Me");
Document doc = dos.getActiveDocuments(DocumentType.ORDER).get(0);
assertThat(doc).overridingErrorMessage("Expected active document Order, got null. Dossier: " + dos.toMultiLine()).isNotNull();
doc.append(unit(uu1));
doc.append(unit(uu2));
doc.append(unit(uu3));
doc.append(comment());
doc.append(service());
doc.append(batch(uuProduct1));
doc.append(shippingcost());
// add units to LogicTransaction
unitOverseer.lockStockUnit(dos.getId(), uu1.getIdentifier(UniqueUnit.Identifier.REFURBISHED_ID));
unitOverseer.lockStockUnit(dos.getId(), uu2.getIdentifier(UniqueUnit.Identifier.REFURBISHED_ID));
unitOverseer.lockStockUnit(dos.getId(), uu3.getIdentifier(UniqueUnit.Identifier.REFURBISHED_ID));
unitOverseer.lockStockUnit(dos.getId(), uu4.getIdentifier(UniqueUnit.Identifier.REFURBISHED_ID));
doc = redTapeWorker.update(doc, null, "JUnit");
doc.add(Document.Condition.PAID);
doc.add(Document.Condition.PICKED_UP);
doc.setType(DocumentType.INVOICE);
doc = redTapeWorker.update(doc, null, "JUnit");
LogicTransaction lt = support.findByDossierId(doc.getDossier().getId());
assertNotNull("A LogicTrasaction must exists", lt);
assertEquals("The Size of the LogicTransaction", 3, lt.getUnits().size());
// A CreditMemo for Unit1, negate prices on Annulation Invoice.
for (Position pos : new ArrayList<>(doc.getPositions().values())) {
if (pos.getUniqueUnitId() == uu1.getId() || pos.getType() == PRODUCT_BATCH || pos.getType() == SHIPPING_COST) {
pos.setPrice(pos.getPrice() * -1);
} else {
doc.remove(pos);
}
}
assertEquals("Document should have exactly one possition", 3, doc.getPositions().size());
doc.setType(DocumentType.ANNULATION_INVOICE);
doc = redTapeWorker.update(doc, stockIdOfUU1, "JUnit Test");
Collection<Position> positions = doc.getPositions().values();
// Report somethere in the past till now.
FileJacket jacket = reportOperation.toXls(new Date(1352115909), new Date());
assertNotNull(jacket);
assertEquals(".xls", jacket.getSuffix());
assertTrue(jacket.getContent().length > 0);
List<LoadContainer> read = new JExcelLucidCalcReader().addColumn(0, String.class).addColumn(1, String.class).addColumn(2, String.class).addColumn(3, String.class).addColumn(4, String.class).addColumn(5, Double.class).addColumn(6, Double.class).read(jacket.toTemporaryFile(), LoadContainer.class);
// HINT: Not a complete test, but some fileds at least.
assertThat(positions.stream().map(Position::getPrice).collect(toSet())).containsOnly(read.stream().map(l -> l.netto).toArray((v) -> new Double[v]));
assertThat(positions.stream().map(Position::toAfterTaxPrice).collect(toSet())).containsOnly(read.stream().map(l -> l.brutto).toArray((v) -> new Double[v]));
assertThat(positions.stream().map(Position::getName).collect(toSet())).containsOnly(read.stream().map(l -> l.name).toArray((v) -> new String[v]));
}
use of eu.ggnet.dwoss.stock.ee.entity.StockUnit in project dwoss by gg-net.
the class UnitSupporterOperation method isSerialAvailable.
@Override
public boolean isSerialAvailable(String serial) {
UniqueUnitEao uniqueUnitEao = new UniqueUnitEao(uuEm);
StockUnitEao stockUnitEao = new StockUnitEao(stockEm);
UniqueUnit uu = uniqueUnitEao.findByIdentifier(UniqueUnit.Identifier.SERIAL, serial);
if (uu != null) {
StockUnit stockUnit = stockUnitEao.findByUniqueUnitId(uu.getId());
if (stockUnit != null) {
return false;
}
}
return true;
}
use of eu.ggnet.dwoss.stock.ee.entity.StockUnit 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();
}
}
Aggregations