Ejemplo n.º 1
0
  private boolean technologyWasChanged(final Entity order) {
    Entity existingOrder = getExistingOrder(order);

    if (existingOrder == null) {
      return false;
    }

    Entity technology = order.getBelongsToField(OrderFields.TECHNOLOGY_PROTOTYPE);
    Entity existingOrderTechnology =
        existingOrder.getBelongsToField(OrderFields.TECHNOLOGY_PROTOTYPE);

    if (existingOrderTechnology == null) {
      return true;
    }

    if (!existingOrderTechnology.equals(technology)) {
      if (order.getBelongsToField(OrderFields.TECHNOLOGY) != null
          && existingOrder.getBelongsToField(OrderFields.TECHNOLOGY) == null) {
        return false;
      }
      return true;
    } else {
      return false;
    }
  }
  @Test
  public void
      shouldReturnFalseAndAddErrorWhenCheckMaterialFlowComponentUniquenessAndMaterialFlowComponentIsntUnique() {
    // given
    given(materialsInLocationComponent.getBelongsToField(LOCATION)).willReturn(location);
    given(materialsInLocationComponent.getBelongsToField(MATERIALS_IN_LOCATION))
        .willReturn(materialsInLocation);

    given(materialsInLocationComponentDD.find()).willReturn(searchCriteriaBuilder);
    given(searchCriteriaBuilder.add(Mockito.any(SearchCriterion.class)))
        .willReturn(searchCriteriaBuilder);
    given(searchCriteriaBuilder.list()).willReturn(searchResult);

    given(searchResult.getTotalNumberOfEntities()).willReturn(1);
    given(searchResult.getEntities()).willReturn(entities);
    given(entities.get(0)).willReturn(materialsInLocationComponentOther);

    given(materialsInLocationComponent.getId()).willReturn(L_ID);
    given(materialsInLocationComponentOther.getId()).willReturn(L_ID_OTHER);

    // when
    boolean result =
        materialsInLocationComponentModelValidators.checkMaterialFlowComponentUniqueness(
            materialsInLocationComponentDD, materialsInLocationComponent);

    // then
    assertFalse(result);

    Mockito.verify(materialsInLocationComponent)
        .addError(
            Mockito.eq(materialsInLocationComponentDD.getField(LOCATION)), Mockito.anyString());
  }
Ejemplo n.º 3
0
  public Entity createResource(
      final Entity position,
      final Entity warehouse,
      final Entity resource,
      final BigDecimal quantity,
      Object date) {
    DataDefinition resourceDD =
        dataDefinitionService.get(
            MaterialFlowResourcesConstants.PLUGIN_IDENTIFIER,
            MaterialFlowResourcesConstants.MODEL_RESOURCE);

    Entity newResource = resourceDD.create();

    if (position != null) {
      Entity document = position.getBelongsToField(PositionFields.DOCUMENT);

      if (document != null) {
        Entity user = document.getBelongsToField(DocumentFields.USER);

        newResource.setField(
            ResourceFields.USER_NAME,
            user.getStringField(_FIRST_NAME) + " " + user.getStringField(L_LAST_NAME));
      }
    }

    newResource.setField(ResourceFields.TIME, date);
    newResource.setField(ResourceFields.LOCATION, warehouse);
    newResource.setField(
        ResourceFields.PRODUCT, resource.getBelongsToField(PositionFields.PRODUCT));
    newResource.setField(ResourceFields.QUANTITY, quantity);
    newResource.setField(ResourceFields.AVAILABLE_QUANTITY, quantity);
    newResource.setField(ResourceFields.RESERVED_QUANTITY, BigDecimal.ZERO);
    newResource.setField(ResourceFields.PRICE, resource.getField(PositionFields.PRICE));
    newResource.setField(ResourceFields.BATCH, resource.getField(PositionFields.BATCH));
    newResource.setField(
        ResourceFields.EXPIRATION_DATE, resource.getField(PositionFields.EXPIRATION_DATE));
    newResource.setField(
        ResourceFields.PRODUCTION_DATE, resource.getField(PositionFields.PRODUCTION_DATE));
    newResource.setField(
        ResourceFields.STORAGE_LOCATION, resource.getField(ResourceFields.STORAGE_LOCATION));
    newResource.setField(
        ResourceFields.ADDITIONAL_CODE, resource.getField(ResourceFields.ADDITIONAL_CODE));
    newResource.setField(ResourceFields.CONVERSION, resource.getField(ResourceFields.CONVERSION));
    newResource.setField(
        ResourceFields.PALLET_NUMBER, resource.getField(ResourceFields.PALLET_NUMBER));
    newResource.setField(
        ResourceFields.TYPE_OF_PALLET, resource.getField(ResourceFields.TYPE_OF_PALLET));
    newResource.setField(ResourceFields.GIVEN_UNIT, resource.getField(ResourceFields.GIVEN_UNIT));

    BigDecimal quantityInAdditionalUnit =
        numberService.setScale(
            quantity.multiply(resource.getDecimalField(ResourceFields.CONVERSION)));

    newResource.setField(ResourceFields.QUANTITY_IN_ADDITIONAL_UNIT, quantityInAdditionalUnit);

    setResourceAttributesFromResource(newResource, resource);

    resourceStockService.addResourceStock(newResource);
    return resourceDD.save(newResource);
  }
  public void checkIfExistsFinalRecord(final StateChangeContext stateChangeContext) {
    final Entity productionTracking = stateChangeContext.getOwner();
    final Entity order = productionTracking.getBelongsToField(ProductionTrackingFields.ORDER);
    final String typeOfProductionRecording =
        order.getStringField(OrderFieldsPC.TYPE_OF_PRODUCTION_RECORDING);

    final SearchCriteriaBuilder searchBuilder = productionTracking.getDataDefinition().find();
    searchBuilder.add(
        SearchRestrictions.eq(
            ProductionTrackingFields.STATE, ProductionTrackingStateStringValues.ACCEPTED));
    searchBuilder.add(SearchRestrictions.belongsTo(ProductionTrackingFields.ORDER, order));
    searchBuilder.add(SearchRestrictions.eq(ProductionTrackingFields.LAST_TRACKING, true));

    if (productionCountingService.isTypeOfProductionRecordingForEach(typeOfProductionRecording)) {
      searchBuilder.add(
          SearchRestrictions.belongsTo(
              ProductionTrackingFields.TECHNOLOGY_OPERATION_COMPONENT,
              productionTracking.getBelongsToField(
                  ProductionTrackingFields.TECHNOLOGY_OPERATION_COMPONENT)));
    }

    if (searchBuilder.list().getTotalNumberOfEntities() != 0) {
      stateChangeContext.addValidationError(
          "productionCounting.productionTracking.messages.error.finalExists");
    }
  }
  public void showCopyOfTechnology(
      final ViewDefinitionState view, final ComponentState state, final String[] args) {
    Long orderId = (Long) state.getFieldValue();

    if (orderId != null) {
      Entity order =
          dataDefinitionService
              .get(OrdersConstants.PLUGIN_IDENTIFIER, OrdersConstants.MODEL_ORDER)
              .get(orderId);

      if (OrderType.WITH_PATTERN_TECHNOLOGY
              .getStringValue()
              .equals(order.getField(OrderFields.ORDER_TYPE))
          && (order.getBelongsToField(OrderFields.TECHNOLOGY_PROTOTYPE) == null)) {
        state.addMessage("order.technology.patternTechnology.not.set", MessageType.INFO);

        return;
      }

      Long technologyId = order.getBelongsToField(OrderFields.TECHNOLOGY).getId();
      Map<String, Object> parameters = Maps.newHashMap();
      parameters.put("form.id", technologyId);

      String url = "../page/orders/copyOfTechnologyDetails.html";
      view.redirectTo(url, false, true, parameters);
    }
  }
Ejemplo n.º 6
0
  private void createOrUpdateTechnologyForWithPatternTechnology(
      final Entity order, final Entity technologyPrototype) {
    Entity existingOrder = getExistingOrder(order);

    if (isTechnologyCopied(order)) {
      if (isOrderTypeChangedToWithPatternTechnology(order)) {
        Entity technology = order.getBelongsToField(OrderFields.TECHNOLOGY);

        deleteTechnology(technology);

        order.setField(OrderFields.TECHNOLOGY, copyTechnology(order, technologyPrototype));
      } else if (technologyWasChanged(order)) {
        Entity technology = order.getBelongsToField(OrderFields.TECHNOLOGY);

        deleteTechnology(technology);

        order.setField(OrderFields.TECHNOLOGY, copyTechnology(order, technologyPrototype));
      }
    } else {
      if (existingOrder == null) {
        order.setField(OrderFields.TECHNOLOGY, copyTechnology(order, technologyPrototype));
      } else if (!isTechnologySet(order)) {
        order.setField(OrderFields.TECHNOLOGY, copyTechnology(order, technologyPrototype));
      }
    }
  }
Ejemplo n.º 7
0
  @Override
  @Transactional
  public void updateResourcesForReleaseDocuments(final Entity document) {
    Entity warehouse = document.getBelongsToField(DocumentFields.LOCATION_FROM);
    WarehouseAlgorithm warehouseAlgorithm;

    boolean enoughResources = true;

    StringBuilder errorMessage = new StringBuilder();

    Multimap<Long, BigDecimal> quantitiesForWarehouse =
        getQuantitiesInWarehouse(warehouse, getProductsAndPositionsFromDocument(document));

    List<Entity> generatedPositions = Lists.newArrayList();

    for (Entity position : document.getHasManyField(DocumentFields.POSITIONS)) {
      Entity product = position.getBelongsToField(PositionFields.PRODUCT);
      Entity resource = position.getBelongsToField(PositionFields.RESOURCE);

      BigDecimal quantityInWarehouse;

      if (resource != null) {
        warehouse = resource.getBelongsToField(ResourceFields.LOCATION);
        warehouseAlgorithm = WarehouseAlgorithm.MANUAL;
      } else {
        warehouse = document.getBelongsToField(DocumentFields.LOCATION_FROM);
        warehouseAlgorithm =
            WarehouseAlgorithm.parseString(warehouse.getStringField(LocationFieldsMFR.ALGORITHM));
      }

      if (warehouseAlgorithm.equals(WarehouseAlgorithm.MANUAL)) {
        quantityInWarehouse = getQuantityOfProductInWarehouse(warehouse, product, position);
      } else {
        quantityInWarehouse = getQuantityOfProductFromMultimap(quantitiesForWarehouse, product);
      }

      generatedPositions.addAll(updateResources(warehouse, position, warehouseAlgorithm));

      enoughResources = enoughResources && position.isValid();

      if (!position.isValid()) {
        BigDecimal quantity = position.getDecimalField(QUANTITY);

        errorMessage.append(product.getStringField(ProductFields.NAME));
        errorMessage.append(" - ");
        errorMessage.append(numberService.format(quantity.subtract(quantityInWarehouse)));
        errorMessage.append(" ");
        errorMessage.append(product.getStringField(ProductFields.UNIT));
        errorMessage.append(", ");
      }
    }

    if (!enoughResources) {
      addDocumentError(document, warehouse, errorMessage);
    } else {
      deleteReservations(document);
      document.setField(DocumentFields.POSITIONS, generatedPositions);
    }
  }
Ejemplo n.º 8
0
  public Entity createResource(
      final Entity document, final Entity warehouse, final Entity position, final Object date) {
    DataDefinition resourceDD =
        dataDefinitionService.get(
            MaterialFlowResourcesConstants.PLUGIN_IDENTIFIER,
            MaterialFlowResourcesConstants.MODEL_RESOURCE);

    Entity product = position.getBelongsToField(PositionFields.PRODUCT);
    Entity resource = resourceDD.create();
    Entity user = document.getBelongsToField(DocumentFields.USER);

    resource.setField(
        ResourceFields.USER_NAME,
        user.getStringField(_FIRST_NAME) + " " + user.getStringField(L_LAST_NAME));
    resource.setField(ResourceFields.TIME, date);
    resource.setField(ResourceFields.LOCATION, warehouse);
    resource.setField(ResourceFields.PRODUCT, position.getBelongsToField(PositionFields.PRODUCT));
    resource.setField(ResourceFields.QUANTITY, position.getField(PositionFields.QUANTITY));
    resource.setField(ResourceFields.RESERVED_QUANTITY, BigDecimal.ZERO);
    resource.setField(
        ResourceFields.AVAILABLE_QUANTITY, position.getDecimalField(PositionFields.QUANTITY));
    resource.setField(ResourceFields.PRICE, position.getField(PositionFields.PRICE));
    resource.setField(ResourceFields.BATCH, position.getField(PositionFields.BATCH));
    resource.setField(
        ResourceFields.EXPIRATION_DATE, position.getField(PositionFields.EXPIRATION_DATE));
    resource.setField(
        ResourceFields.PRODUCTION_DATE, position.getField(PositionFields.PRODUCTION_DATE));
    resource.setField(
        ResourceFields.STORAGE_LOCATION, position.getField(PositionFields.STORAGE_LOCATION));
    resource.setField(
        ResourceFields.ADDITIONAL_CODE, position.getField(PositionFields.ADDITIONAL_CODE));
    resource.setField(
        ResourceFields.PALLET_NUMBER, position.getField(PositionFields.PALLET_NUMBER));
    resource.setField(
        ResourceFields.TYPE_OF_PALLET, position.getField(PositionFields.TYPE_OF_PALLET));
    resource.setField(ResourceFields.WASTE, position.getField(PositionFields.WASTE));

    if (StringUtils.isEmpty(product.getStringField(ProductFields.ADDITIONAL_UNIT))) {
      resource.setField(ResourceFields.GIVEN_UNIT, product.getField(ProductFields.UNIT));
      resource.setField(
          ResourceFields.QUANTITY_IN_ADDITIONAL_UNIT, position.getField(PositionFields.QUANTITY));
      resource.setField(ResourceFields.CONVERSION, BigDecimal.ONE);
    } else {
      resource.setField(ResourceFields.GIVEN_UNIT, position.getField(PositionFields.GIVEN_UNIT));
      resource.setField(
          ResourceFields.QUANTITY_IN_ADDITIONAL_UNIT,
          position.getField(PositionFields.GIVEN_QUANTITY));
      resource.setField(ResourceFields.CONVERSION, position.getField(PositionFields.CONVERSION));
    }

    setResourceAttributesFromPosition(resource, position);

    resourceStockService.addResourceStock(resource);
    return resourceDD.save(resource);
  }
  private void setStaffFilter(ViewDefinitionState view) {
    FormComponent form = (FormComponent) view.getComponentByReference(L_FORM);
    Entity multiAssignment = form.getPersistedEntityWithIncludedFormValues();
    Entity assignment = multiAssignment.getBelongsToField("assignmentToShift");
    if (assignment != null) {
      Entity crew = assignment.getBelongsToField(AssignmentToShiftFields.CREW);

      LookupComponent staffLookup = (LookupComponent) view.getComponentByReference("staffLookup");

      staffCriteriaModifier.putCrewNumber(staffLookup, crew);
    }
  }
Ejemplo n.º 10
0
  @Test
  public void shouldReturnWhenProductionLineIsThisSame() throws Exception {
    // given
    Long orderId = 1L;
    when(entity.getId()).thenReturn(orderId);
    when(dataDefinition.get(orderId)).thenReturn(order);
    when(order.getBelongsToField(OrderFields.PRODUCTION_LINE)).thenReturn(orderProdLine);
    when(entity.getBelongsToField(OrderFields.PRODUCTION_LINE)).thenReturn(orderProdLine);

    // when
    hooksOTFO.changedProductionLine(dataDefinition, entity);
    // then
  }
  private Entity getBasicProductionCounting(
      final Entity trackingOperationProductComponent, final List<Entity> basicProductionCountings) {
    Entity product = trackingOperationProductComponent.getBelongsToField(L_PRODUCT);

    for (Entity basicProductionCounting : basicProductionCountings) {
      if (basicProductionCounting
          .getBelongsToField(BasicProductionCountingFields.PRODUCT)
          .getId()
          .equals(product.getId())) {
        return basicProductionCounting;
      }
    }

    throw new IllegalStateException("No basic production counting found for product");
  }
  @Test
  public void
      shouldReturnFalseWhenCheckMaterialFlowComponentUniquenessAndMaterialsInLocationOrLocationIsNull() {
    // given
    given(materialsInLocationComponent.getBelongsToField(LOCATION)).willReturn(null);
    given(materialsInLocationComponent.getBelongsToField(MATERIALS_IN_LOCATION)).willReturn(null);

    // when
    boolean result =
        materialsInLocationComponentModelValidators.checkMaterialFlowComponentUniqueness(
            materialsInLocationComponentDD, materialsInLocationComponent);

    // then
    assertFalse(result);
  }
Ejemplo n.º 13
0
  @Override
  @Transactional
  public void moveResourcesForTransferDocument(Entity document) {
    Entity warehouseFrom = document.getBelongsToField(DocumentFields.LOCATION_FROM);
    Entity warehouseTo = document.getBelongsToField(DocumentFields.LOCATION_TO);
    Object date = document.getField(DocumentFields.TIME);

    WarehouseAlgorithm warehouseAlgorithm =
        WarehouseAlgorithm.parseString(warehouseFrom.getStringField(LocationFieldsMFR.ALGORITHM));

    boolean enoughResources = true;

    StringBuilder errorMessage = new StringBuilder();

    Multimap<Long, BigDecimal> quantitiesForWarehouse =
        getQuantitiesInWarehouse(warehouseFrom, getProductsAndPositionsFromDocument(document));

    for (Entity position : document.getHasManyField(DocumentFields.POSITIONS)) {
      Entity product = position.getBelongsToField(PositionFields.PRODUCT);
      BigDecimal quantityInWarehouse;

      if (warehouseAlgorithm.equals(WarehouseAlgorithm.MANUAL)) {
        quantityInWarehouse = getQuantityOfProductInWarehouse(warehouseFrom, product, position);
      } else {
        quantityInWarehouse = getQuantityOfProductFromMultimap(quantitiesForWarehouse, product);
      }

      moveResources(warehouseFrom, warehouseTo, position, date, warehouseAlgorithm);
      enoughResources = enoughResources && position.isValid();

      if (!position.isValid()) {
        BigDecimal quantity = position.getDecimalField(QUANTITY);

        errorMessage.append(product.getStringField(ProductFields.NAME));
        errorMessage.append(" - ");
        errorMessage.append(numberService.format(quantity.subtract(quantityInWarehouse)));
        errorMessage.append(" ");
        errorMessage.append(product.getStringField(ProductFields.UNIT));
        errorMessage.append(", ");
      }
    }

    if (!enoughResources) {
      addDocumentError(document, warehouseFrom, errorMessage);
    } else {
      deleteReservations(document);
    }
  }
Ejemplo n.º 14
0
  public BigDecimal getQuantityOfProductInWarehouse(
      final Entity warehouse, final Entity product, Entity position) {
    BigDecimal quantity = BigDecimal.ZERO;

    Entity resource = position.getBelongsToField(PositionFields.RESOURCE);
    Entity reservation = reservationsService.getReservationForPosition(position);
    if (resource != null) {
      quantity = resource.getDecimalField(ResourceFields.AVAILABLE_QUANTITY);
    } else {
      List<Entity> resources =
          dataDefinitionService
              .get(
                  MaterialFlowResourcesConstants.PLUGIN_IDENTIFIER,
                  MaterialFlowResourcesConstants.MODEL_RESOURCE)
              .find()
              .add(SearchRestrictions.belongsTo(ResourceFields.LOCATION, warehouse))
              .add(SearchRestrictions.belongsTo(ResourceFields.PRODUCT, product))
              .list()
              .getEntities();

      for (Entity res : resources) {
        quantity = quantity.add(res.getDecimalField(ResourceFields.AVAILABLE_QUANTITY));
      }
    }

    if (reservation != null) {
      quantity = quantity.add(reservation.getDecimalField(ReservationFields.QUANTITY));
    }
    return quantity;
  }
  @Override
  public Set<ImportedOrder> getImportedOrders(final Set<Long> orderIds) {
    Set<ImportedOrder> result = new HashSet<ImportedOrder>();
    for (Long importedOrderId : orderIds) {
      Entity orderEntity =
          dataDefinitionService
              .get(SfcSimpleConstants.PLUGIN_IDENTIFIER, SfcSimpleConstants.MODEL_IMPORTED_ORDER)
              .get(importedOrderId);

      ImportedOrder order = new ImportedOrder(importedOrderId);

      order.setNumber(orderEntity.getStringField(FIELD_NUMBER));
      order.setDrawDate((Date) orderEntity.getField(FIELD_DRAW_DATE));
      order.setRealizationDate((Date) orderEntity.getField(FIELD_REALIZATION_DATE));

      for (Entity orderProductEntity : orderEntity.getHasManyField("orderProducts")) {

        ImportedProduct orderItemProduct =
            createImportedProduct(orderProductEntity.getBelongsToField("product"), true);
        if (orderItemProduct != null) {
          ImportedOrderItem orderItem = new ImportedOrderItem();
          orderItem.setProduct(orderItemProduct);
          orderItem.setQuantity((BigDecimal) orderProductEntity.getField(FIELD_QUANTITY));
          order.addItem(orderItem);
        }
      }

      result.add(order);
    }

    return result;
  }
Ejemplo n.º 16
0
  private void updateTechnology(final Entity technology) {
    String number = technology.getStringField(TechnologyFields.NUMBER);
    Entity product = technology.getBelongsToField(TechnologyFields.PRODUCT);

    technology.setField(TechnologyFields.NAME, makeTechnologyName(number, product));
    technology.setField(TechnologyFields.TECHNOLOGY_PROTOTYPE, null);
    technology.setField(
        TechnologyFields.TECHNOLOGY_TYPE, TechnologyType.WITH_OWN_TECHNOLOGY.getStringValue());

    EntityTree operationComponents = technology.getTreeField(TechnologyFields.OPERATION_COMPONENTS);

    if ((operationComponents != null) && !operationComponents.isEmpty()) {
      EntityTreeNode root = operationComponents.getRoot();

      root.getDataDefinition().delete(root.getId());
    }

    technology.setField(TechnologyFields.OPERATION_COMPONENTS, Lists.newArrayList());

    technology.getDataDefinition().save(technology);

    if (TechnologyStateStringValues.CHECKED.equals(
        technology.getStringField(TechnologyFields.STATE))) {
      changeTechnologyState(technology, TechnologyStateStringValues.DRAFT);
    }
  }
  @Test
  public void shouldReturnFalseWhenEntityWithGivenProductAndCompanyDoesExistsInDB()
      throws Exception {
    // given
    SearchCriterion criterion1 =
        SearchRestrictions.eq(CATALOG_NUMBER, entity.getStringField(CATALOG_NUMBER));
    SearchCriterion criterion2 =
        SearchRestrictions.belongsTo(PRODUCT, entity.getBelongsToField(PRODUCT));

    given(entity.getId()).willReturn(null);
    given(criteria.add(criterion1)).willReturn(criteria);
    given(criteria.add(criterion2)).willReturn(criteria);
    given(criteria.list()).willReturn(searchResult);
    given(searchResult.getEntities()).willReturn(productCatalogNumbers);
    given(productCatalogNumbers.isEmpty()).willReturn(false);
    // when
    boolean result =
        productCatalogNumbersHooks.checkIfExistsCatalogNumberWithProductAndCompany(
            dataDefinition, entity);
    // then
    Assert.assertFalse(result);
    Mockito.verify(entity)
        .addGlobalError(
            "productCatalogNumbers.productCatalogNumber.validationError.alreadyExistsProductForCompany");
  }
  private void updateBasicProductionCounting(
      final Entity productionTracking, final Operation operation) {
    final Entity order = productionTracking.getBelongsToField(ProductionTrackingFields.ORDER);

    final List<Entity> basicProductionCountings =
        order.getHasManyField(OrderFieldsBPC.BASIC_PRODUCTION_COUNTINGS);

    final List<Entity> trackingOperationProductInComponents =
        productionTracking.getHasManyField(
            ProductionTrackingFields.TRACKING_OPERATION_PRODUCT_IN_COMPONENTS);
    final List<Entity> trackingOperationProductOutComponents =
        productionTracking.getHasManyField(
            ProductionTrackingFields.TRACKING_OPERATION_PRODUCT_OUT_COMPONENTS);

    for (Entity trackingOperationProductInComponent : trackingOperationProductInComponents) {
      Entity basicProductionCounting;

      try {
        basicProductionCounting =
            getBasicProductionCounting(
                trackingOperationProductInComponent, basicProductionCountings);
      } catch (IllegalStateException e) {
        continue;
      }

      final BigDecimal usedQuantity =
          basicProductionCounting.getDecimalField(BasicProductionCountingFields.USED_QUANTITY);
      final BigDecimal productQuantity =
          trackingOperationProductInComponent.getDecimalField(
              TrackingOperationProductInComponentFields.USED_QUANTITY);
      final BigDecimal result = operation.perform(usedQuantity, productQuantity);

      basicProductionCounting.setField(BasicProductionCountingFields.USED_QUANTITY, result);
      basicProductionCounting =
          basicProductionCounting.getDataDefinition().save(basicProductionCounting);
    }

    for (Entity trackingOperationProductOutComponent : trackingOperationProductOutComponents) {
      Entity productionCounting;

      try {
        productionCounting =
            getBasicProductionCounting(
                trackingOperationProductOutComponent, basicProductionCountings);
      } catch (IllegalStateException e) {
        continue;
      }

      final BigDecimal usedQuantity =
          productionCounting.getDecimalField(BasicProductionCountingFields.PRODUCED_QUANTITY);
      final BigDecimal productQuantity =
          trackingOperationProductOutComponent.getDecimalField(
              TrackingOperationProductOutComponentFields.USED_QUANTITY);
      final BigDecimal result = operation.perform(usedQuantity, productQuantity);

      productionCounting.setField(BasicProductionCountingFields.PRODUCED_QUANTITY, result);
      productionCounting = productionCounting.getDataDefinition().save(productionCounting);
    }
  }
Ejemplo n.º 19
0
  @Test
  public void shouldChangedProdLineWhenProdLineIsNullify() throws Exception {
    // given
    Long orderId = 1L;
    when(entity.getId()).thenReturn(orderId);
    when(dataDefinition.get(orderId)).thenReturn(order);
    when(order.getBelongsToField(OrderFields.PRODUCTION_LINE)).thenReturn(orderProdLine);
    when(entity.getBelongsToField(OrderFields.PRODUCTION_LINE)).thenReturn(null);
    EntityList tasks = mockEntityList(Lists.newArrayList(task1));

    when(result.getEntities()).thenReturn(tasks);
    // when
    hooksOTFO.changedProductionLine(dataDefinition, entity);
    // then

    Mockito.verify(task1).setField(OrderFields.PRODUCTION_LINE, null);
  }
  private void setOrderDoneQuantity(final Entity productionTracking) {
    Entity order = productionTracking.getBelongsToField(ProductionTrackingFields.ORDER);

    order.setField(
        OrderFields.DONE_QUANTITY,
        basicProductionCountingService.getProducedQuantityFromBasicProductionCountings(order));

    order.getDataDefinition().save(order);
  }
Ejemplo n.º 21
0
 public void setTechnologyNumber(final DataDefinition orderDD, final Entity order) {
   String orderType = order.getStringField(OrderFields.ORDER_TYPE);
   Entity technology = order.getBelongsToField(OrderFields.TECHNOLOGY);
   if (technology == null) {
     return;
   }
   String number = "";
   if (OrderType.WITH_PATTERN_TECHNOLOGY.getStringValue().equals(orderType)) {
     number =
         generateNumberForTechnologyInOrder(
             order, order.getBelongsToField(OrderFields.TECHNOLOGY_PROTOTYPE));
   } else if (OrderType.WITH_OWN_TECHNOLOGY.getStringValue().equals(orderType)) {
     number = generateNumberForTechnologyInOrder(order, null);
   }
   technology.setField(TechnologyFields.NUMBER, number);
   technology = technology.getDataDefinition().save(technology);
   order.setField(OrderFields.TECHNOLOGY, technology);
 }
Ejemplo n.º 22
0
  private boolean isTechnologyCopied(final Entity order) {
    Entity technology = order.getBelongsToField(OrderFields.TECHNOLOGY);

    if (technology == null) {
      return false;
    }

    return true;
  }
Ejemplo n.º 23
0
  @Override
  @Transactional
  public void createResourcesForReceiptDocuments(final Entity document) {
    Entity warehouse = document.getBelongsToField(DocumentFields.LOCATION_TO);
    Object date = document.getField(DocumentFields.TIME);

    for (Entity position : document.getHasManyField(DocumentFields.POSITIONS)) {
      createResource(document, warehouse, position, date);
    }
  }
Ejemplo n.º 24
0
  private Entity createTechnology(final Entity order) {
    Entity newTechnology = getTechnologyDD().create();

    String number = generateNumberForTechnologyInOrder(order, null);

    Entity product = order.getBelongsToField(TechnologyFields.PRODUCT);
    Entity technologyPrototype = order.getBelongsToField(OrderFields.TECHNOLOGY_PROTOTYPE);

    newTechnology.setField(TechnologyFields.NUMBER, number);
    newTechnology.setField(TechnologyFields.NAME, makeTechnologyName(number, product));
    newTechnology.setField(TechnologyFields.PRODUCT, product);
    newTechnology.setField(TechnologyFields.TECHNOLOGY_PROTOTYPE, technologyPrototype);
    newTechnology.setField(
        TechnologyFields.TECHNOLOGY_TYPE, TechnologyType.WITH_OWN_TECHNOLOGY.getStringValue());

    newTechnology = newTechnology.getDataDefinition().save(newTechnology);

    return newTechnology;
  }
  @Test
  public void shouldSetNullWhenTechnologyIsNull() throws Exception {
    // given
    when(order.getBelongsToField("technology")).thenReturn(null);

    // when
    hooks.setTechnologyNumber(view);
    // then
    Mockito.verify(technologyField).setFieldValue(null);
  }
 private Entity mockProductComponent(final Long productId) {
   Entity productComponent = mock(Entity.class);
   Entity product = mock(Entity.class);
   given(product.getField("id")).willReturn(productId);
   given(product.getId()).willReturn(productId);
   given(productComponent.getField("product")).willReturn(product);
   given(productComponent.getBelongsToField("product")).willReturn(product);
   given(dataDefinition.get(productId)).willReturn(productComponent);
   return productComponent;
 }
  public void closeOrder(final StateChangeContext stateChangeContext) {
    final Entity productionTracking = stateChangeContext.getOwner();
    final Entity order = productionTracking.getBelongsToField(ORDER);

    if (!orderClosingHelper.orderShouldBeClosed(productionTracking)) {
      return;
    }
    if (order.getStringField(STATE).equals(COMPLETED.getStringValue())) {
      stateChangeContext.addMessage(
          "productionCounting.order.orderIsAlreadyClosed", StateMessageType.INFO, false);
      return;
    }
    final StateChangeContext orderStateChangeContext =
        stateChangeContextBuilder.build(
            orderStateChangeAspect.getChangeEntityDescriber(),
            order,
            OrderState.COMPLETED.getStringValue());
    orderStateChangeAspect.changeState(orderStateChangeContext);
    Entity orderFromDB = order.getDataDefinition().get(orderStateChangeContext.getOwner().getId());
    if (orderFromDB.getStringField(STATE).equals(COMPLETED.getStringValue())) {
      stateChangeContext.addMessage(
          "productionCounting.order.orderClosed", StateMessageType.INFO, false);
    } else if (StateChangeStatus.PAUSED.equals(orderStateChangeContext.getStatus())) {
      stateChangeContext.addMessage(
          "productionCounting.order.orderWillBeClosedAfterExtSync", StateMessageType.INFO, false);
    } else {
      stateChangeContext.addMessage(
          "productionCounting.order.orderCannotBeClosed", StateMessageType.FAILURE, false);

      List<ErrorMessage> errors = Lists.newArrayList();

      if (!orderFromDB.getErrors().isEmpty()) {
        errors.addAll(order.getErrors().values());
      }
      if (!orderFromDB.getGlobalErrors().isEmpty()) {
        errors.addAll(order.getGlobalErrors());
      }

      if (!errors.isEmpty()) {
        StringBuilder errorMessages = new StringBuilder();

        for (ErrorMessage errorMessage : errors) {
          String translatedErrorMessage =
              translationService.translate(
                  errorMessage.getMessage(), Locale.getDefault(), errorMessage.getVars());
          errorMessages.append(translatedErrorMessage);
          errorMessages.append(", ");
        }

        stateChangeContext.addValidationError(
            "orders.order.orderStates.error", errorMessages.toString());
      }
    }
  }
Ejemplo n.º 28
0
 @Test
 public void shouldReturnWhenProductQuantitiesFromTechnologyIsnotEmpty() throws Exception {
   // given
   Long orderId = 1L;
   Long technologyId = 2L;
   when(order.getBelongsToField("technology")).thenReturn(technology);
   when(order.getId()).thenReturn(orderId);
   when(orderDD.get(orderId)).thenReturn(order);
   when(technology.getId()).thenReturn(technologyId);
   // when
   orderHooksCNFM.fillOrderOperationProductsInComponents(orderDD, order);
 }
Ejemplo n.º 29
0
  private List<Entity> getResourcesForLocationAndProductMANUAL(
      final Entity warehouse,
      final Entity product,
      final Entity position,
      final Entity additionalCode) {
    Entity resource = position.getBelongsToField(PositionFields.RESOURCE);

    if (resource != null) {
      return Lists.newArrayList(resource);
    } else {
      return getResourcesForLocationAndProductFIFO(warehouse, product, additionalCode, position);
    }
  }
  @Test
  public void shouldSetTechnologyNumberToField() throws Exception {
    // given

    String technologyNumber = "0001";

    when(order.getBelongsToField("technology")).thenReturn(technology);
    when(technology.getStringField("number")).thenReturn(technologyNumber);
    // when
    hooks.setTechnologyNumber(view);
    // then
    Mockito.verify(technologyField).setFieldValue(technologyNumber);
  }