Search in sources :

Example 61 with EntityList

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;
}
Also used : InvocationOnMock(org.mockito.invocation.InvocationOnMock) EntityList(com.qcadoo.model.api.EntityList) Iterator(java.util.Iterator)

Example 62 with EntityList

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);
        }
    }
}
Also used : Entity(com.qcadoo.model.api.Entity) EntityList(com.qcadoo.model.api.EntityList)

Example 63 with EntityList

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;
}
Also used : Entity(com.qcadoo.model.api.Entity) EntityList(com.qcadoo.model.api.EntityList) BigDecimal(java.math.BigDecimal)

Example 64 with EntityList

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));
        }
    }
}
Also used : DataDefinitionService(com.qcadoo.model.api.DataDefinitionService) SearchRestrictions(com.qcadoo.model.api.search.SearchRestrictions) QcadooSecurityConstants(com.qcadoo.security.constants.QcadooSecurityConstants) Set(java.util.Set) Autowired(org.springframework.beans.factory.annotation.Autowired) Collectors(java.util.stream.Collectors) DataDefinition(com.qcadoo.model.api.DataDefinition) EntityList(com.qcadoo.model.api.EntityList) Objects(java.util.Objects) DeliveriesService(com.qcadoo.mes.deliveries.DeliveriesService) UserFieldsMF(com.qcadoo.mes.materialFlow.constants.UserFieldsMF) UserLocationFields(com.qcadoo.mes.materialFlow.constants.UserLocationFields) Service(org.springframework.stereotype.Service) SearchCriteriaBuilder(com.qcadoo.model.api.search.SearchCriteriaBuilder) SecurityService(com.qcadoo.security.api.SecurityService) EntityList(com.qcadoo.model.api.EntityList)

Example 65 with EntityList

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);
}
Also used : EntityList(com.qcadoo.model.api.EntityList)

Aggregations

EntityList (com.qcadoo.model.api.EntityList)103 Entity (com.qcadoo.model.api.Entity)52 Test (org.junit.Test)27 DataDefinition (com.qcadoo.model.api.DataDefinition)16 SearchCriteriaBuilder (com.qcadoo.model.api.search.SearchCriteriaBuilder)16 Before (org.junit.Before)11 UserFieldsMF (com.qcadoo.mes.materialFlow.constants.UserFieldsMF)10 UserLocationFields (com.qcadoo.mes.materialFlow.constants.UserLocationFields)10 DataDefinitionService (com.qcadoo.model.api.DataDefinitionService)10 SearchRestrictions (com.qcadoo.model.api.search.SearchRestrictions)10 SecurityService (com.qcadoo.security.api.SecurityService)10 QcadooSecurityConstants (com.qcadoo.security.constants.QcadooSecurityConstants)10 Objects (java.util.Objects)10 Set (java.util.Set)10 Collectors (java.util.stream.Collectors)10 Autowired (org.springframework.beans.factory.annotation.Autowired)10 Service (org.springframework.stereotype.Service)10 FilterValueHolder (com.qcadoo.view.api.components.lookup.FilterValueHolder)9 BigDecimal (java.math.BigDecimal)9 StateChangeTest (com.qcadoo.mes.states.StateChangeTest)5