Search in sources :

Example 1 with AttributeSetInstanceId

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();
}
Also used : ProductAndCategoryAndManufacturerId(de.metas.product.ProductAndCategoryAndManufacturerId) AttributeSetInstanceId(org.adempiere.mm.attributes.AttributeSetInstanceId) ImmutableAttributeSet(org.adempiere.mm.attributes.api.ImmutableAttributeSet) IProductDAO(de.metas.product.IProductDAO) ProductId(de.metas.product.ProductId) BigDecimal(java.math.BigDecimal) IAttributeDAO(org.adempiere.mm.attributes.api.IAttributeDAO)

Example 2 with AttributeSetInstanceId

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();
}
Also used : AttributeSetInstanceId(org.adempiere.mm.attributes.AttributeSetInstanceId) Quantity(de.metas.quantity.Quantity) BigDecimal(java.math.BigDecimal)

Example 3 with AttributeSetInstanceId

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;
}
Also used : AttributeSetInstanceId(org.adempiere.mm.attributes.AttributeSetInstanceId) ArrayList(java.util.ArrayList) ProductId(de.metas.product.ProductId) HUPIItemProductId(de.metas.handlingunits.HUPIItemProductId) BigDecimal(java.math.BigDecimal) GroupId(de.metas.order.compensationGroup.GroupId) I_PP_Product_BOM(org.eevolution.model.I_PP_Product_BOM) ImmutableAttributeSet(org.adempiere.mm.attributes.api.ImmutableAttributeSet) ProductBOMLineId(org.eevolution.api.ProductBOMLineId) BOMUse(org.eevolution.api.BOMUse) I_PP_Product_BOMLine(org.eevolution.model.I_PP_Product_BOMLine)

Example 4 with AttributeSetInstanceId

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();
}
Also used : AttributeSetInstanceId(org.adempiere.mm.attributes.AttributeSetInstanceId) ShipmentScheduleUserChangeRequestBuilder(de.metas.inoutcandidate.api.ShipmentScheduleUserChangeRequest.ShipmentScheduleUserChangeRequestBuilder) BigDecimal(java.math.BigDecimal)

Example 5 with AttributeSetInstanceId

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");
}
Also used : AttributeSetInstanceId(org.adempiere.mm.attributes.AttributeSetInstanceId) AttributesKey(de.metas.material.event.commons.AttributesKey) IAttributeSetInstanceBL(org.adempiere.mm.attributes.api.IAttributeSetInstanceBL) I_MD_Stock(de.metas.material.cockpit.model.I_MD_Stock) I_M_AttributeSetInstance(org.compiere.model.I_M_AttributeSetInstance) CreateRowsRequest(de.metas.ui.web.material.cockpit.rowfactory.MaterialCockpitRowFactory.CreateRowsRequest) LocalDate(java.time.LocalDate) I_MD_Cockpit(de.metas.material.cockpit.model.I_MD_Cockpit) I_M_Warehouse(de.metas.handlingunits.model.I_M_Warehouse) MaterialCockpitRow(de.metas.ui.web.material.cockpit.MaterialCockpitRow) Test(org.junit.jupiter.api.Test)

Aggregations

AttributeSetInstanceId (org.adempiere.mm.attributes.AttributeSetInstanceId)8 BigDecimal (java.math.BigDecimal)4 ProductId (de.metas.product.ProductId)2 AdempiereException (org.adempiere.exceptions.AdempiereException)2 ImmutableAttributeSet (org.adempiere.mm.attributes.api.ImmutableAttributeSet)2 HUPIItemProductId (de.metas.handlingunits.HUPIItemProductId)1 I_M_Warehouse (de.metas.handlingunits.model.I_M_Warehouse)1 ShipmentScheduleUserChangeRequestBuilder (de.metas.inoutcandidate.api.ShipmentScheduleUserChangeRequest.ShipmentScheduleUserChangeRequestBuilder)1 I_MD_Cockpit (de.metas.material.cockpit.model.I_MD_Cockpit)1 I_MD_Stock (de.metas.material.cockpit.model.I_MD_Stock)1 AttributesKey (de.metas.material.event.commons.AttributesKey)1 GroupId (de.metas.order.compensationGroup.GroupId)1 IProductDAO (de.metas.product.IProductDAO)1 ProductAndCategoryAndManufacturerId (de.metas.product.ProductAndCategoryAndManufacturerId)1 Quantity (de.metas.quantity.Quantity)1 MaterialCockpitRow (de.metas.ui.web.material.cockpit.MaterialCockpitRow)1 CreateRowsRequest (de.metas.ui.web.material.cockpit.rowfactory.MaterialCockpitRowFactory.CreateRowsRequest)1 ASIDocument (de.metas.ui.web.pattribute.ASIDocument)1 ASILayout (de.metas.ui.web.pattribute.ASILayout)1 JSONDocumentPath (de.metas.ui.web.window.datatypes.json.JSONDocumentPath)1