use of org.adempiere.mm.attributes.AttributeSetInstanceId in project metasfresh-webui-api by metasfresh.
the class OrderLinePricingConditionsViewFactory method createPricingConditionsBreakQuery.
private final PricingConditionsBreakQuery createPricingConditionsBreakQuery(final I_C_OrderLine salesOrderLine) {
final IProductDAO productsRepo = Services.get(IProductDAO.class);
final IAttributeDAO attributesRepo = Services.get(IAttributeDAO.class);
final ProductId productId = ProductId.ofRepoId(salesOrderLine.getM_Product_ID());
final ProductAndCategoryAndManufacturerId product = productsRepo.retrieveProductAndCategoryAndManufacturerByProductId(productId);
final AttributeSetInstanceId asiId = AttributeSetInstanceId.ofRepoIdOrNone(salesOrderLine.getM_AttributeSetInstance_ID());
final ImmutableAttributeSet attributes = attributesRepo.getImmutableAttributeSetById(asiId);
final BigDecimal qty = salesOrderLine.getQtyOrdered();
final BigDecimal price = salesOrderLine.getPriceActual();
return PricingConditionsBreakQuery.builder().product(product).attributes(attributes).qty(qty).price(price).build();
}
use of org.adempiere.mm.attributes.AttributeSetInstanceId in project metasfresh-webui-api by metasfresh.
the class ShipmentCandidateRowsLoader method toShipmentCandidateRow.
private ShipmentCandidateRow toShipmentCandidateRow(@NonNull final I_M_ShipmentSchedule record) {
final AttributeSetInstanceId asiId = AttributeSetInstanceId.ofRepoIdOrNone(record.getM_AttributeSetInstance_ID());
final BigDecimal qtyOrdered = shipmentScheduleEffectiveBL.computeQtyOrdered(record);
final boolean catchWeight = shipmentScheduleBL.isCatchWeight(record);
final BigDecimal qtyToDeliverCatchOverride = extractQtyToDeliverCatchOverride(record);
final PackingInfo packingInfo = extractPackingInfo(record);
final Quantity qtyCUsToDeliver = extractQtyCUToDeliver(record);
final BigDecimal qtyToDeliverUserEntered = packingInfo.computeQtyUserEnteredByQtyCUs(qtyCUsToDeliver);
return ShipmentCandidateRow.builder().shipmentScheduleId(ShipmentScheduleId.ofRepoId(record.getM_ShipmentSchedule_ID())).salesOrder(extractSalesOrder(record)).salesOrderLineNo(extractSalesOrderLineNo(record)).customer(extractCustomer(record)).warehouse(extractWarehouse(record)).product(extractProduct(record)).packingInfo(packingInfo).preparationDate(extractPreparationTime(record)).qtyOrdered(packingInfo.computeQtyUserEnteredByQtyCUs(qtyOrdered)).qtyToDeliverUserEnteredInitial(qtyToDeliverUserEntered).qtyToDeliverUserEntered(qtyToDeliverUserEntered).catchWeight(catchWeight).qtyToDeliverCatchOverrideInitial(qtyToDeliverCatchOverride).qtyToDeliverCatchOverride(qtyToDeliverCatchOverride).catchUOM(extractCatchUOM(record)).asiIdInitial(asiId).asi(toLookupValue(asiId)).processed(record.isProcessed()).build();
}
use of org.adempiere.mm.attributes.AttributeSetInstanceId in project metasfresh-webui-api by metasfresh.
the class OrderLineQuickInputProcessor method explodePhantomBOM.
private List<OrderLineCandidate> explodePhantomBOM(final OrderLineCandidate initialCandidate) {
final ProductId bomProductId = initialCandidate.getProductId();
final I_PP_Product_BOM bom = bomsRepo.getDefaultBOMByProductId(bomProductId).orElse(null);
if (bom == null) {
return ImmutableList.of(initialCandidate);
}
final BOMUse bomUse = BOMUse.ofNullableCode(bom.getBOMUse());
if (!BOMUse.Phantom.equals(bomUse)) {
return ImmutableList.of(initialCandidate);
}
GroupId compensationGroupId = null;
final ArrayList<OrderLineCandidate> result = new ArrayList<>();
final List<I_PP_Product_BOMLine> bomLines = bomsRepo.retrieveLines(bom);
for (final I_PP_Product_BOMLine bomLine : bomLines) {
final ProductBOMLineId bomLineId = ProductBOMLineId.ofRepoId(bomLine.getPP_Product_BOMLine_ID());
final ProductId bomLineProductId = ProductId.ofRepoId(bomLine.getM_Product_ID());
final BigDecimal bomLineQty = bomsService.computeQtyRequired(bomLine, bomProductId, initialCandidate.getQty());
final AttributeSetInstanceId bomLineAsiId = AttributeSetInstanceId.ofRepoIdOrNone(bomLine.getM_AttributeSetInstance_ID());
final ImmutableAttributeSet attributes = asiBL.getImmutableAttributeSetById(bomLineAsiId);
if (compensationGroupId == null) {
compensationGroupId = orderGroupsRepo.createNewGroupId(GroupCreateRequest.builder().orderId(initialCandidate.getOrderId()).name(productBL.getProductName(bomProductId)).build());
}
result.add(initialCandidate.toBuilder().productId(bomLineProductId).attributes(attributes).qty(bomLineQty).compensationGroupId(compensationGroupId).explodedFromBOMLineId(bomLineId).build());
}
return result;
}
use of org.adempiere.mm.attributes.AttributeSetInstanceId in project metasfresh-webui-api by metasfresh.
the class ShipmentCandidateRow method createShipmentScheduleUserChangeRequest.
Optional<ShipmentScheduleUserChangeRequest> createShipmentScheduleUserChangeRequest() {
final ShipmentScheduleUserChangeRequestBuilder builder = ShipmentScheduleUserChangeRequest.builder().shipmentScheduleId(shipmentScheduleId);
boolean changes = false;
if (qtyToDeliverUserEnteredInitial.compareTo(qtyToDeliverUserEntered) != 0) {
BigDecimal qtyCUsToDeliver = packingInfo.computeQtyCUsByQtyUserEntered(qtyToDeliverUserEntered);
builder.qtyToDeliverStockOverride(qtyCUsToDeliver);
changes = true;
}
if (qtyToDeliverCatchOverrideIsChanged()) {
builder.qtyToDeliverCatchOverride(qtyToDeliverCatchOverride);
changes = true;
}
final AttributeSetInstanceId asiId = asi.getIdAs(AttributeSetInstanceId::ofRepoIdOrNone);
if (!Objects.equals(asiIdInitial, asiId)) {
builder.asiId(asiId);
changes = true;
}
return changes ? Optional.of(builder.build()) : Optional.empty();
}
use of org.adempiere.mm.attributes.AttributeSetInstanceId in project metasfresh-webui-api by metasfresh.
the class MaterialCockpitRowFactoryTest method createRows_contains_attribute_groups.
/**
* Verifies that the {@link I_MD_Cockpit} and {@link I_MD_Stock} data rows are correctly applied to {@link MaterialCockpitRow}s based on the given dimension spec.
* In this test, we have a dimension spec with tree groups, on of them is empty.
*/
@Test
public void createRows_contains_attribute_groups() {
final I_M_AttributeSetInstance asi1 = newInstance(I_M_AttributeSetInstance.class);
save(asi1);
final AttributeSetInstanceId asiId1 = AttributeSetInstanceId.ofRepoId(asi1.getM_AttributeSetInstance_ID());
final IAttributeSetInstanceBL attributeSetInstanceBL = Services.get(IAttributeSetInstanceBL.class);
attributeSetInstanceBL.getCreateAttributeInstance(asiId1, attr1_value1);
attributeSetInstanceBL.getCreateAttributeInstance(asiId1, attr2_value1);
final AttributesKey attributesKeyWithAttr1_and_attr2 = AttributesKeys.createAttributesKeyFromASIAllAttributes(asiId1).get();
final I_MD_Cockpit cockpitRecordWithAttributes = newInstance(I_MD_Cockpit.class);
cockpitRecordWithAttributes.setM_Product(product);
cockpitRecordWithAttributes.setDateGeneral(SystemTime.asTimestamp());
cockpitRecordWithAttributes.setAttributesKey(attributesKeyWithAttr1_and_attr2.getAsString());
cockpitRecordWithAttributes.setQtyReserved_Purchase(TEN);
save(cockpitRecordWithAttributes);
final AttributesKey attributesKey2 = AttributesKey.NONE;
final I_MD_Cockpit cockpitRecordWithEmptyAttributesKey = newInstance(I_MD_Cockpit.class);
cockpitRecordWithEmptyAttributesKey.setM_Product(product);
cockpitRecordWithEmptyAttributesKey.setDateGeneral(SystemTime.asTimestamp());
cockpitRecordWithEmptyAttributesKey.setAttributesKey(attributesKey2.getAsString());
cockpitRecordWithEmptyAttributesKey.setQtyReserved_Purchase(ONE);
save(cockpitRecordWithEmptyAttributesKey);
final I_M_Warehouse warehouseWithPlant = createWarehousewithPlant("plantName");
final I_MD_Stock stockRecordWithAttributes = newInstance(I_MD_Stock.class);
stockRecordWithAttributes.setM_Product(product);
stockRecordWithAttributes.setAttributesKey(attributesKeyWithAttr1_and_attr2.getAsString());
stockRecordWithAttributes.setM_Warehouse(warehouseWithPlant);
stockRecordWithAttributes.setQtyOnHand(ELEVEN);
save(stockRecordWithAttributes);
final I_MD_Stock stockRecordWithEmptyAttributesKey = newInstance(I_MD_Stock.class);
stockRecordWithEmptyAttributesKey.setM_Product(product);
stockRecordWithEmptyAttributesKey.setAttributesKey(attributesKey2.getAsString());
stockRecordWithEmptyAttributesKey.setM_Warehouse(warehouseWithPlant);
stockRecordWithEmptyAttributesKey.setQtyOnHand(TWELVE);
save(stockRecordWithEmptyAttributesKey);
final LocalDate today = SystemTime.asLocalDate();
final CreateRowsRequest request = CreateRowsRequest.builder().date(today).productIdsToListEvenIfEmpty(ImmutableSet.of()).cockpitRecords(ImmutableList.of(cockpitRecordWithAttributes, cockpitRecordWithEmptyAttributesKey)).stockRecords(ImmutableList.of(stockRecordWithAttributes, stockRecordWithEmptyAttributesKey)).includePerPlantDetailRows(// without this, we would not get 4 but 3 included rows
true).build();
// invoke method under test
final List<MaterialCockpitRow> result = materialCockpitRowFactory.createRows(request);
assertThat(result).hasSize(1);
final MaterialCockpitRow mainRow = result.get(0);
assertThat(mainRow.getQtyOnHandStock()).isEqualByComparingTo(ELEVEN.add(TWELVE));
assertThat(mainRow.getQtyReservedPurchase()).isEqualByComparingTo(TEN.add(ONE));
final List<MaterialCockpitRow> includedRows = mainRow.getIncludedRows();
// there shall be 4 rows:
// 2: the cockpitRecordWithAttributes and stockRecordWithAttributes are added to the matching non-empty groups of the dimension spec
// 1: the cockpit and stock record with the empty attributesKey is added to the empty dimension spec group
// 1: both stock records are added to a counting record
assertThat(includedRows).hasSize(4);
final MaterialCockpitRow emptyGroupRow = extractRowWithDimensionSpecGroup(includedRows, dimensionspecGroup_empty);
assertThat(emptyGroupRow.getQtyOnHandStock()).isEqualByComparingTo(TWELVE);
assertThat(emptyGroupRow.getQtyReservedPurchase()).isEqualByComparingTo(ONE);
final MaterialCockpitRow attr1GroupRow = extractRowWithDimensionSpecGroup(includedRows, dimensionspecGroup_attr1_value1);
assertThat(attr1GroupRow.getQtyOnHandStock()).isEqualByComparingTo(ELEVEN);
assertThat(attr1GroupRow.getQtyReservedPurchase()).isEqualByComparingTo(TEN);
final MaterialCockpitRow attr2GroupRow = extractRowWithDimensionSpecGroup(includedRows, dimensionspecGroup_attr2_value1);
assertThat(attr2GroupRow.getQtyOnHandStock()).isEqualByComparingTo(ELEVEN);
assertThat(attr2GroupRow.getQtyReservedPurchase()).isEqualByComparingTo(TEN);
final MaterialCockpitRow countingRow = extractSingleCountingRow(includedRows);
assertThat(countingRow.getQtyOnHandStock()).isEqualByComparingTo(ELEVEN.add(TWELVE));
assertThat(countingRow.getProductCategoryOrSubRowName()).isEqualTo("plantName");
}
Aggregations