use of com.qcadoo.model.api.EntityList in project mes by qcadoo.
the class RequestForQuotationHooksCNINTest method mockEntityList.
private static EntityList mockEntityList(final List<Entity> entities) {
final EntityList entitiesList = mock(EntityList.class);
given(entitiesList.iterator()).willAnswer(new Answer<Iterator<Entity>>() {
@Override
public Iterator<Entity> answer(final InvocationOnMock invocation) throws Throwable {
return ImmutableList.copyOf(entities).iterator();
}
});
given(entitiesList.isEmpty()).willReturn(entities.isEmpty());
return entitiesList;
}
use of com.qcadoo.model.api.EntityList in project mes by qcadoo.
the class DeliveryHooks method clearStorageLocations.
private void clearStorageLocations(Entity delivery) {
EntityList deliveredProducts = delivery.getHasManyField(DeliveryFields.DELIVERED_PRODUCTS);
if (deliveredProducts != null) {
for (Entity deliveryProduct : deliveredProducts) {
deliveryProduct.setField(DeliveredProductFields.STORAGE_LOCATION, null);
deliveryProduct.getDataDefinition().save(deliveryProduct);
}
}
}
use of com.qcadoo.model.api.EntityList in project mes by qcadoo.
the class ReservationService method createDefaultReservationsForDeliveredProduct.
public Entity createDefaultReservationsForDeliveredProduct(final Entity deliveredProduct) {
Entity product = deliveredProduct.getBelongsToField(DeliveredProductFields.PRODUCT);
if (Objects.nonNull(product) && !deliveredProduct.getBooleanField(DeliveredProductFields.IS_WASTE)) {
List<Entity> deliveredProductReservations = Lists.newArrayList();
Entity orderedProductForProduct = findOrderedProductForProduct(deliveredProduct);
List<Entity> presentDeliveredProductForProductReservations = findPresentDeliveredProductForProductReservations(deliveredProduct);
if (Objects.nonNull(orderedProductForProduct)) {
EntityList reservationsFromOrderedProduct = orderedProductForProduct.getHasManyField(OrderedProductFields.RESERVATIONS);
BigDecimal damagedQuantity = deliveredProduct.getDecimalField(DeliveredProductFields.DAMAGED_QUANTITY);
damagedQuantity = Objects.isNull(damagedQuantity) ? BigDecimal.ZERO : damagedQuantity;
BigDecimal availableQuantity = deliveredProduct.getDecimalField(DeliveredProductFields.DELIVERED_QUANTITY);
availableQuantity = Objects.isNull(availableQuantity) ? BigDecimal.ZERO : availableQuantity;
availableQuantity = availableQuantity.subtract(damagedQuantity);
for (Entity reservationFromOrderedProduct : reservationsFromOrderedProduct) {
Optional<Entity> maybeDeliveredProductReservation = createDeliveredProductReservation(availableQuantity, deliveredProduct, reservationFromOrderedProduct, presentDeliveredProductForProductReservations);
if (maybeDeliveredProductReservation.isPresent()) {
Entity deliveredProductReservation = maybeDeliveredProductReservation.get();
deliveredProductReservations.add(deliveredProductReservation);
presentDeliveredProductForProductReservations.add(deliveredProductReservation);
availableQuantity = availableQuantity.subtract(deliveredProductReservation.getDecimalField(DeliveredProductReservationFields.DELIVERED_QUANTITY));
}
}
}
deliveredProduct.setField(DeliveredProductFields.RESERVATIONS, deliveredProductReservations);
}
return deliveredProduct;
}
use of com.qcadoo.model.api.EntityList in project mes by qcadoo.
the class DeliveryCriteriaModifiers method restrictToUserLocations.
private void restrictToUserLocations(SearchCriteriaBuilder scb) {
Long currentUserId = securityService.getCurrentUserId();
if (Objects.nonNull(currentUserId)) {
EntityList userLocations = userDataDefinition().get(currentUserId).getHasManyField(UserFieldsMF.USER_LOCATIONS);
if (!userLocations.isEmpty()) {
Set<Integer> locationIds = userLocations.stream().map(ul -> ul.getBelongsToField(UserLocationFields.LOCATION)).mapToInt(e -> e.getId().intValue()).boxed().collect(Collectors.toSet());
scb.add(SearchRestrictions.in(LOCATION_ID, locationIds));
}
}
}
use of com.qcadoo.model.api.EntityList in project mes by qcadoo.
the class OrderValidatorsMOTest method stubMasterOrderProducts.
private void stubMasterOrderProducts(final Collection<Entity> elements) {
EntityList entityList = EntityListMock.create(elements);
EntityTestUtils.stubHasManyField(masterOrder, MasterOrderFields.MASTER_ORDER_PRODUCTS, entityList);
}
Aggregations