use of eu.ggnet.dwoss.redtape.ee.entity.Position in project dwoss by gg-net.
the class RedTapeOperationCapitalAssetUpdateIT method testUpdate.
@Test
public void testUpdate() throws UserInfoException {
UniqueUnit uu = receiptGenerator.makeUniqueUnit();
uu.setPrice(CUSTOMER, 50., "JunitTestPrice");
// Generate Dossier
Dossier dos = redTapeWorker.create(capitalAssestCustomer, false, "Me");
assertThat(dos.getActiveDocuments()).isNotEmpty();
assertThat(dos.getActiveDocuments(CAPITAL_ASSET)).overridingErrorMessage("Expected a capital Asset Document but has " + dos.getActiveDocuments()).isNotEmpty();
Document doc = dos.getActiveDocuments(DocumentType.CAPITAL_ASSET).get(0);
assertTrue(doc.equalsContent(dos.getActiveDocuments(DocumentType.CAPITAL_ASSET).get(0)));
// Commit explicit date to document for assertion
doc = supportBean.changeActual(doc, new GregorianCalendar(2012, 3, 15).getTime());
Position pos = NaivBuilderUtil.unit(uu);
// Create Positions
doc.append(pos);
doc.append(NaivBuilderUtil.comment("Comment", "A nice comment"));
// add units to LogicTransaction
unitOverseer.lockStockUnit(dos.getId(), uu.getIdentifier(UniqueUnit.Identifier.REFURBISHED_ID));
// update document
Date date = doc.getActual();
doc = redTapeWorker.update(doc, null, "Me");
assertEquals("Same actual dates expected", date, doc.getActual());
assertEquals("Only one Active Document expected", 1, doc.getDossier().getActiveDocuments().size());
assertTrue(stockAgent.findAllEager(LogicTransaction.class).get(0).getUnits().size() == 1);
assertEquals("Ammount of Documents", 2, redTapeAgent.findAll(Document.class).size());
}
use of eu.ggnet.dwoss.redtape.ee.entity.Position in project dwoss by gg-net.
the class RedTapeUpdateRepaymentWorkflow method rollInMissingStockUnits.
/**
* If referenced Units are not in Stock, roll them in and append them to the instance variable (stockUnits).
*
* @return the list of rolled in StockUnits
*/
List<StockUnit> rollInMissingStockUnits(String dossierIdentifier, Collection<Position> positions, int destinationId) {
List<UniqueUnit> uniqueUnits = new ArrayList<>();
StockUnitEao stockUnitEao = new StockUnitEao(stockEm);
UniqueUnitEao uniqueUnitEao = new UniqueUnitEao(uniqueUnitEm);
for (Position position : positions) {
if (stockUnitEao.findByUniqueUnitId(position.getUniqueUnitId()) == null) {
uniqueUnits.add(uniqueUnitEao.findById(position.getUniqueUnitId()));
}
}
if (uniqueUnits.isEmpty())
return Collections.EMPTY_LIST;
StockTransactionEmo transactionEmo = new StockTransactionEmo(stockEm);
StockTransaction rollInTransaction = transactionEmo.requestRollInPrepared(destinationId, arranger, "RollIn durch Gutschrift " + dossierIdentifier);
for (UniqueUnit uu : uniqueUnits) {
StockUnit stockUnit = new StockUnit(uu.getIdentifier(UniqueUnit.Identifier.REFURBISHED_ID), uu.getProduct().getName(), uu.getId());
rollInTransaction.addUnit(stockUnit);
stockEm.persist(stockUnit);
}
List<StockUnit> rolledInUnits = transactionEmo.completeRollIn(arranger, Arrays.asList(rollInTransaction));
L.info("Missing Units rolled In: {}", toIds(rolledInUnits));
return rolledInUnits;
}
Aggregations