use of com.qcadoo.mes.technologies.dto.OperationProductComponentWithQuantityContainer in project mes by qcadoo.
the class MrpAlgorithmStrategyTS method perform.
public Map<Long, BigDecimal> perform(final OperationProductComponentWithQuantityContainer productComponentWithQuantities, final Set<OperationProductComponentHolder> nonComponents, final MrpAlgorithm mrpAlgorithm, final String operationProductComponentModelName) {
OperationProductComponentWithQuantityContainer allWithSameEntityType = productComponentWithQuantities.getAllWithSameEntityType(operationProductComponentModelName);
Map<Long, BigDecimal> productWithQuantities = Maps.newHashMap();
for (Entry<OperationProductComponentHolder, BigDecimal> productComponentWithQuantity : allWithSameEntityType.asMap().entrySet()) {
OperationProductComponentHolder operationProductComponentHolder = productComponentWithQuantity.getKey();
if (nonComponents.contains(operationProductComponentHolder)) {
Entity product = operationProductComponentHolder.getProduct();
Entity technologyOperationComponent = operationProductComponentHolder.getTechnologyOperationComponent();
if (technologyOperationComponent != null) {
List<Entity> children = technologyOperationComponent.getHasManyField(CHILDREN).find().add(SearchRestrictions.eq(TechnologyOperationComponentFieldsTS.IS_SUBCONTRACTING, true)).list().getEntities();
boolean isSubcontracting = false;
for (Entity child : children) {
Entity operationProductOutComponent = child.getHasManyField(OPERATION_PRODUCT_OUT_COMPONENTS).find().add(SearchRestrictions.belongsTo(PRODUCT, product)).setMaxResults(1).uniqueResult();
if (operationProductOutComponent != null) {
isSubcontracting = true;
}
}
if (!isSubcontracting) {
continue;
}
}
}
productQuantitiesService.addProductQuantitiesToList(productComponentWithQuantity, productWithQuantities);
}
return productWithQuantities;
}
use of com.qcadoo.mes.technologies.dto.OperationProductComponentWithQuantityContainer in project mes by qcadoo.
the class ProductQuantitiesWithComponentsServiceImpl method getProductComponentQuantities.
@Override
public ProductQuantitiesHolder getProductComponentQuantities(final Entity technology, final BigDecimal givenQuantity) {
Map<Long, BigDecimal> operationRuns = Maps.newHashMap();
Set<OperationProductComponentHolder> nonComponents = Sets.newHashSet();
OperationProductComponentWithQuantityContainer productQuantities = getProductComponentWithQuantitiesForTechnology(technology, givenQuantity, operationRuns, nonComponents);
return new ProductQuantitiesHolder(productQuantities, operationRuns);
}
use of com.qcadoo.mes.technologies.dto.OperationProductComponentWithQuantityContainer in project mes by qcadoo.
the class ProductQuantitiesWithComponentsServiceImpl method getNeededProductQuantitiesByOPC.
@Override
public Map<OperationProductComponentHolder, BigDecimal> getNeededProductQuantitiesByOPC(Entity technology, BigDecimal givenQuantity, MrpAlgorithm mrpAlgorithm) {
Map<Long, BigDecimal> operationRuns = Maps.newHashMap();
Set<OperationProductComponentHolder> nonComponents = Sets.newHashSet();
OperationProductComponentWithQuantityContainer productComponentWithQuantities = getProductComponentWithQuantitiesForTechnology(technology, givenQuantity, operationRuns, nonComponents);
OperationProductComponentWithQuantityContainer allWithSameEntityType = productComponentWithQuantities.getAllWithSameEntityType(TechnologiesConstants.MODEL_OPERATION_PRODUCT_IN_COMPONENT);
if (mrpAlgorithm.equals(MrpAlgorithm.ALL_PRODUCTS_IN)) {
return getOperationProductComponentWithQuantities(allWithSameEntityType, nonComponents, false, false);
} else if (mrpAlgorithm.equals(MrpAlgorithm.ONLY_COMPONENTS)) {
return getOperationProductComponentWithQuantities(allWithSameEntityType, nonComponents, true, false);
} else if (mrpAlgorithm.equals(MrpAlgorithm.COMPONENTS_AND_SUBCONTRACTORS_PRODUCTS)) {
return getOperationProductComponentWithQuantities(allWithSameEntityType, nonComponents, false, false);
} else {
return getOperationProductComponentWithQuantities(allWithSameEntityType, nonComponents, true, true);
}
}
use of com.qcadoo.mes.technologies.dto.OperationProductComponentWithQuantityContainer in project mes by qcadoo.
the class ProductQuantitiesServiceImplTest method shouldNotRoundToTheIntegerOperationRunsIfOperationComponentHasDivisableProductQuantities.
@Test
public void shouldNotRoundToTheIntegerOperationRunsIfOperationComponentHasDivisableProductQuantities() {
// given
when(operationComponent1.getBooleanField("areProductQuantitiesDivisible")).thenReturn(true);
when(operationComponent2.getBooleanField("areProductQuantitiesDivisible")).thenReturn(true);
// when
OperationProductComponentWithQuantityContainer productQuantities = productQuantitiesService.getProductComponentQuantities(order);
// then
assertEquals(0, new BigDecimal(45).compareTo(productQuantities.get(productInComponent1)));
assertEquals(0, new BigDecimal(9).compareTo(productQuantities.get(productInComponent2)));
assertEquals(0, new BigDecimal(4.5).compareTo(productQuantities.get(productInComponent3)));
assertEquals(0, new BigDecimal(9).compareTo(productQuantities.get(productOutComponent2)));
assertEquals(0, new BigDecimal(4.5).compareTo(productQuantities.get(productOutComponent4)));
}
use of com.qcadoo.mes.technologies.dto.OperationProductComponentWithQuantityContainer in project mes by qcadoo.
the class WorkPlansColumnFillerTest method shouldReturnCorrectColumnValuesForProducts.
@Test
public void shouldReturnCorrectColumnValuesForProducts() {
// given
EntityTree operComps = mockEntityTree(asList(operationComponent));
EntityTree operComps2 = mockEntityTree(asList(operationComponent));
given(technology.getTreeField(TechnologyFields.OPERATION_COMPONENTS)).willReturn(operComps, operComps2);
given(operationComponent.getId()).willReturn(1L);
EntityList prodInComps = mockEntityList(asList(operationProductComponent));
EntityList prodInComps2 = mockEntityList(asList(operationProductComponent));
given(operationProductComponent.getBelongsToField("operationComponent")).willReturn(operationComponent);
given(operationProductComponent.getBelongsToField(L_PRODUCT)).willReturn(product);
given(operationComponent.getHasManyField(TechnologyOperationComponentFields.OPERATION_PRODUCT_IN_COMPONENTS)).willReturn(prodInComps, prodInComps2);
EntityList prodOutComps = mockEntityList(new ArrayList<Entity>());
given(operationComponent.getHasManyField(TechnologyOperationComponentFields.OPERATION_PRODUCT_OUT_COMPONENTS)).willReturn(prodOutComps);
given(operationProductComponent.getDataDefinition()).willReturn(operationProductComponentDD);
given(operationProductComponentDD.getName()).willReturn(TechnologiesConstants.MODEL_OPERATION_PRODUCT_IN_COMPONENT);
OperationProductComponentWithQuantityContainer quantities = new OperationProductComponentWithQuantityContainer();
quantities.put(operationProductComponent, new BigDecimal(11));
given(productQuantitiesService.getProductComponentQuantities(order)).willReturn(quantities);
// when
Map<Entity, Map<String, String>> columnValues = workPlansColumnFiller.getValues(asList(order));
// then
assertEquals(1, columnValues.size());
assertEquals("product (123)", columnValues.get(operationProductComponent).get(L_PRODUCT_NAME));
assertEquals("11.00000 abc", columnValues.get(operationProductComponent).get(L_PLANNED_QUANTITY));
}
Aggregations