Search in sources :

Example 1 with AttributesKey

use of de.metas.material.event.commons.AttributesKey in project metasfresh-webui-api by metasfresh.

the class AvailableToPromiseAdapter method createClientResultGroup0.

private Group createClientResultGroup0(final ResultGroup commonsResultGroup) {
    final GroupBuilder groupBuilder = Group.builder().productId(commonsResultGroup.getProductId());
    final Quantity quantity = Quantity.of(commonsResultGroup.getQty(), retrieveStockingUOM(commonsResultGroup.getProductId()));
    groupBuilder.qty(quantity);
    final AttributesKey attributesKey = commonsResultGroup.getStorageAttributesKey();
    final Type type = extractType(attributesKey);
    groupBuilder.type(type);
    if (type == Type.ATTRIBUTE_SET) {
        final List<I_M_AttributeValue> attributevalues = extractAttributeSetFromStorageAttributesKey(attributesKey);
        groupBuilder.attributeValues(attributevalues);
    }
    return groupBuilder.build();
}
Also used : Type(de.metas.ui.web.material.adapter.AvailableToPromiseResultForWebui.Group.Type) AttributesKey(de.metas.material.event.commons.AttributesKey) GroupBuilder(de.metas.ui.web.material.adapter.AvailableToPromiseResultForWebui.Group.GroupBuilder) Quantity(de.metas.quantity.Quantity) I_M_AttributeValue(org.compiere.model.I_M_AttributeValue)

Example 2 with AttributesKey

use of de.metas.material.event.commons.AttributesKey in project metasfresh-webui-api by metasfresh.

the class MainRowWithSubRows method findOrCreateSubRowBucket.

private List<DimensionGroupSubRowBucket> findOrCreateSubRowBucket(@NonNull final AttributesKey dataRecordAttributesKey, @NonNull final DimensionSpec dimensionSpec) {
    final ImmutableList.Builder<DimensionGroupSubRowBucket> result = ImmutableList.builder();
    DimensionSpecGroup otherGroup = null;
    boolean addedToAnyGroup = false;
    for (final DimensionSpecGroup group : dimensionSpec.retrieveGroups()) {
        final AttributesKey dimensionAttributesKey = group.getAttributesKey();
        if (DimensionSpecGroup.EMPTY_GROUP.equals(group) && AttributesKey.NONE.equals(dataRecordAttributesKey)) {
            result.add(dimensionGroupSubRows.computeIfAbsent(group, DimensionGroupSubRowBucket::create));
            addedToAnyGroup = true;
            continue;
        } else if (dataRecordAttributesKey.intersects(dimensionAttributesKey)) {
            result.add(dimensionGroupSubRows.computeIfAbsent(group, DimensionGroupSubRowBucket::create));
            addedToAnyGroup = true;
            continue;
        }
        // while iterating, also look out out for "otherGroup"
        if (DimensionSpecGroup.OTHER_GROUP.equals(group)) {
            otherGroup = group;
        }
    }
    if (!addedToAnyGroup && otherGroup != null) {
        result.add(dimensionGroupSubRows.computeIfAbsent(otherGroup, DimensionGroupSubRowBucket::create));
    }
    return result.build();
}
Also used : DimensionSpecGroup(de.metas.dimension.DimensionSpecGroup) AttributesKey(de.metas.material.event.commons.AttributesKey) ImmutableList(com.google.common.collect.ImmutableList)

Example 3 with AttributesKey

use of de.metas.material.event.commons.AttributesKey in project metasfresh-webui-api by metasfresh.

the class MainRowWithSubRows method addCockpitRecordToDimensionGroups.

private void addCockpitRecordToDimensionGroups(@NonNull final I_MD_Cockpit dataRecord, @NonNull final DimensionSpec dimensionSpec) {
    assertProductIdAndDateOfDataRecord(dataRecord);
    final AttributesKey attributesKey = AttributesKey.ofString(dataRecord.getAttributesKey());
    final List<DimensionGroupSubRowBucket> subRowBuckets = findOrCreateSubRowBucket(attributesKey, dimensionSpec);
    subRowBuckets.forEach(bucket -> bucket.addCockpitRecord(dataRecord));
}
Also used : AttributesKey(de.metas.material.event.commons.AttributesKey)

Example 4 with AttributesKey

use of de.metas.material.event.commons.AttributesKey in project metasfresh-webui-api by metasfresh.

the class MainRowWithSubRows method addStockRecordToDimensionGroups.

private void addStockRecordToDimensionGroups(@NonNull final I_MD_Stock dataRecord, @NonNull final DimensionSpec dimensionSpec) {
    final AttributesKey attributesKey = AttributesKey.ofString(dataRecord.getAttributesKey());
    final List<DimensionGroupSubRowBucket> subRowBuckets = findOrCreateSubRowBucket(attributesKey, dimensionSpec);
    subRowBuckets.forEach(bucket -> bucket.addStockRecord(dataRecord));
}
Also used : AttributesKey(de.metas.material.event.commons.AttributesKey)

Example 5 with AttributesKey

use of de.metas.material.event.commons.AttributesKey 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 IAttributeSetInstanceBL attributeSetInstanceBL = Services.get(IAttributeSetInstanceBL.class);
    attributeSetInstanceBL.getCreateAttributeInstance(asi1, attr1_value1);
    attributeSetInstanceBL.getCreateAttributeInstance(asi1, attr2_value1);
    final AttributesKey attributesKeyWithAttr1_and_attr2 = AttributesKeys.createAttributesKeyFromASIAllAttributeValues(asi1.getM_AttributeSetInstance_ID()).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 Timestamp today = TimeUtil.getDay(SystemTime.asTimestamp());
    final CreateRowsRequest request = CreateRowsRequest.builder().date(today).productsToListEvenIfEmpty(ImmutableList.of()).cockpitRecords(ImmutableList.of(cockpitRecordWithAttributes, cockpitRecordWithEmptyAttributesKey)).stockRecords(ImmutableList.of(stockRecordWithAttributes, stockRecordWithEmptyAttributesKey)).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 : 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) Timestamp(java.sql.Timestamp) 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.Test)

Aggregations

AttributesKey (de.metas.material.event.commons.AttributesKey)7 Test (org.junit.Test)3 Type (de.metas.ui.web.material.adapter.AvailableToPromiseResultForWebui.Group.Type)2 I_M_AttributeValue (org.compiere.model.I_M_AttributeValue)2 ImmutableList (com.google.common.collect.ImmutableList)1 DimensionSpecGroup (de.metas.dimension.DimensionSpecGroup)1 I_M_Warehouse (de.metas.handlingunits.model.I_M_Warehouse)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 Quantity (de.metas.quantity.Quantity)1 Group (de.metas.ui.web.material.adapter.AvailableToPromiseResultForWebui.Group)1 GroupBuilder (de.metas.ui.web.material.adapter.AvailableToPromiseResultForWebui.Group.GroupBuilder)1 MaterialCockpitRow (de.metas.ui.web.material.cockpit.MaterialCockpitRow)1 CreateRowsRequest (de.metas.ui.web.material.cockpit.rowfactory.MaterialCockpitRowFactory.CreateRowsRequest)1 Timestamp (java.sql.Timestamp)1 IAttributeSetInstanceBL (org.adempiere.mm.attributes.api.IAttributeSetInstanceBL)1 I_M_Attribute (org.compiere.model.I_M_Attribute)1 I_M_AttributeSetInstance (org.compiere.model.I_M_AttributeSetInstance)1