Search in sources :

Example 6 with I_M_Attribute

use of org.compiere.model.I_M_Attribute in project metasfresh-webui-api by metasfresh.

the class WEBUIHUCreationWithSerialNumberService method assignSerialNumberToCU.

private void assignSerialNumberToCU(final int huId, final String serialNo) {
    final I_M_HU hu = create(Env.getCtx(), huId, I_M_HU.class, ITrx.TRXNAME_ThreadInherited);
    final IContextAware ctxAware = getContextAware(hu);
    final IHUContext huContext = handlingUnitsBL.createMutableHUContext(ctxAware);
    final IAttributeStorage attributeStorage = getAttributeStorage(huContext, hu);
    final I_M_Attribute serialNoAttribute = serialNoDAO.getSerialNoAttribute(ctxAware.getCtx());
    Check.errorUnless(attributeStorage.hasAttribute(serialNoAttribute), "There is no SerialNo attribute {} defined for the handling unit {}", serialNoAttribute, hu);
    attributeStorage.setValue(serialNoAttribute, serialNo.trim());
    attributeStorage.saveChangesIfNeeded();
}
Also used : IAttributeStorage(de.metas.handlingunits.attribute.storage.IAttributeStorage) I_M_HU(de.metas.handlingunits.model.I_M_HU) I_M_Attribute(org.compiere.model.I_M_Attribute) IContextAware(org.adempiere.model.IContextAware) IHUContext(de.metas.handlingunits.IHUContext)

Example 7 with I_M_Attribute

use of org.compiere.model.I_M_Attribute in project metasfresh-webui-api by metasfresh.

the class ASIDescriptorFactory method createDocumentFieldDescriptor.

private DocumentFieldDescriptor.Builder createDocumentFieldDescriptor(final I_M_Attribute attribute) {
    final int attributeId = attribute.getM_Attribute_ID();
    final String fieldName = attribute.getValue();
    final String attributeValueType = attribute.getAttributeValueType();
    final Class<?> valueClass;
    final DocumentFieldWidgetType widgetType;
    final Function<I_M_AttributeInstance, Object> readMethod;
    final BiConsumer<I_M_AttributeInstance, IDocumentFieldView> writeMethod;
    LookupDescriptor lookupDescriptor = null;
    if (X_M_Attribute.ATTRIBUTEVALUETYPE_Date.equals(attributeValueType)) {
        valueClass = java.util.Date.class;
        widgetType = DocumentFieldWidgetType.Date;
        readMethod = I_M_AttributeInstance::getValueDate;
        writeMethod = (aiRecord, field) -> aiRecord.setValueDate(TimeUtil.asTimestamp(field.getValueAs(java.util.Date.class)));
    } else if (X_M_Attribute.ATTRIBUTEVALUETYPE_List.equals(attributeValueType)) {
        valueClass = StringLookupValue.class;
        widgetType = DocumentFieldWidgetType.List;
        readMethod = I_M_AttributeInstance::getValue;
        writeMethod = ASIAttributeFieldBinding::writeValueFromLookup;
        lookupDescriptor = getLookupDescriptor(attribute);
    } else if (X_M_Attribute.ATTRIBUTEVALUETYPE_Number.equals(attributeValueType)) {
        valueClass = BigDecimal.class;
        widgetType = DocumentFieldWidgetType.Number;
        readMethod = I_M_AttributeInstance::getValueNumber;
        writeMethod = (aiRecord, field) -> aiRecord.setValueNumber(field.getValueAs(BigDecimal.class));
    } else if (X_M_Attribute.ATTRIBUTEVALUETYPE_StringMax40.equals(attributeValueType)) {
        valueClass = String.class;
        widgetType = DocumentFieldWidgetType.Text;
        readMethod = I_M_AttributeInstance::getValue;
        writeMethod = (aiRecord, field) -> aiRecord.setValue(field.getValueAs(String.class));
    } else {
        throw new IllegalArgumentException("@NotSupported@ @AttributeValueType@=" + attributeValueType + ", @M_Attribute_ID@=" + attribute);
    }
    final ILogicExpression readonlyLogic = ConstantLogicExpression.FALSE;
    final ILogicExpression displayLogic = ConstantLogicExpression.TRUE;
    final ILogicExpression mandatoryLogic = ConstantLogicExpression.of(attribute.isMandatory());
    final Optional<IExpression<?>> defaultValueExpr = Optional.empty();
    return DocumentFieldDescriptor.builder(fieldName).setCaption(attribute.getName()).setDescription(attribute.getDescription()).setValueClass(valueClass).setWidgetType(widgetType).setLookupDescriptorProvider(lookupDescriptor).setDefaultValueExpression(defaultValueExpr).setReadonlyLogic(readonlyLogic).setDisplayLogic(displayLogic).setMandatoryLogic(mandatoryLogic).addCharacteristic(Characteristic.PublicField).setDataBinding(new ASIAttributeFieldBinding(attributeId, fieldName, attribute.isMandatory(), readMethod, writeMethod));
}
Also used : X_M_Attribute(org.compiere.model.X_M_Attribute) ArrayKey(org.compiere.util.Util.ArrayKey) CCache(org.compiere.util.CCache) IExpression(org.adempiere.ad.expression.api.IExpression) DocumentId(de.metas.ui.web.window.datatypes.DocumentId) TimeUtil(org.compiere.util.TimeUtil) LookupDescriptorProvider(de.metas.ui.web.window.descriptor.LookupDescriptorProvider) ILogicExpression(org.adempiere.ad.expression.api.ILogicExpression) Function(java.util.function.Function) DocumentLayoutElementDescriptor(de.metas.ui.web.window.descriptor.DocumentLayoutElementDescriptor) BigDecimal(java.math.BigDecimal) LookupDescriptor(de.metas.ui.web.window.descriptor.LookupDescriptor) InterfaceWrapperHelper(org.adempiere.model.InterfaceWrapperHelper) I_M_AttributeSet(org.compiere.model.I_M_AttributeSet) Characteristic(de.metas.ui.web.window.descriptor.DocumentFieldDescriptor.Characteristic) IDocumentFieldView(de.metas.ui.web.window.model.IDocumentFieldView) BiConsumer(java.util.function.BiConsumer) DocumentEntityDescriptor(de.metas.ui.web.window.descriptor.DocumentEntityDescriptor) I_M_AttributeInstance(org.compiere.model.I_M_AttributeInstance) I_M_Attribute(org.compiere.model.I_M_Attribute) DocumentsRepository(de.metas.ui.web.window.model.DocumentsRepository) ConstantLogicExpression(org.adempiere.ad.expression.api.ConstantLogicExpression) DocumentFieldDataBindingDescriptor(de.metas.ui.web.window.descriptor.DocumentFieldDataBindingDescriptor) MAttribute(org.compiere.model.MAttribute) ASIEditingInfo(org.adempiere.mm.attributes.util.ASIEditingInfo) DocumentFieldDescriptor(de.metas.ui.web.window.descriptor.DocumentFieldDescriptor) DocumentEntityDataBindingDescriptor(de.metas.ui.web.window.descriptor.DocumentEntityDataBindingDescriptor) DocumentLayoutElementFieldDescriptor(de.metas.ui.web.window.descriptor.DocumentLayoutElementFieldDescriptor) List(java.util.List) Component(org.springframework.stereotype.Component) StringLookupValue(de.metas.ui.web.window.datatypes.LookupValue.StringLookupValue) DocumentEntityDataBindingDescriptorBuilder(de.metas.ui.web.window.descriptor.DocumentEntityDataBindingDescriptor.DocumentEntityDataBindingDescriptorBuilder) AdempiereException(org.adempiere.exceptions.AdempiereException) Check(de.metas.printing.esb.base.util.Check) DocumentFieldWidgetType(de.metas.ui.web.window.descriptor.DocumentFieldWidgetType) Optional(java.util.Optional) DocumentType(de.metas.ui.web.window.datatypes.DocumentType) I_M_AttributeSetInstance(org.compiere.model.I_M_AttributeSetInstance) StringLookupValue(de.metas.ui.web.window.datatypes.LookupValue.StringLookupValue) IExpression(org.adempiere.ad.expression.api.IExpression) IDocumentFieldView(de.metas.ui.web.window.model.IDocumentFieldView) ILogicExpression(org.adempiere.ad.expression.api.ILogicExpression) DocumentFieldWidgetType(de.metas.ui.web.window.descriptor.DocumentFieldWidgetType) I_M_AttributeInstance(org.compiere.model.I_M_AttributeInstance) LookupDescriptor(de.metas.ui.web.window.descriptor.LookupDescriptor)

Example 8 with I_M_Attribute

use of org.compiere.model.I_M_Attribute in project metasfresh-webui-api by metasfresh.

the class HUEditorRowAttributesHelper method createLayoutElement.

private static final DocumentLayoutElementDescriptor createLayoutElement(final IAttributeValue attributeValue, final int warehouseId) {
    final I_M_Attribute attribute = attributeValue.getM_Attribute();
    final IModelTranslationMap attributeTrlMap = InterfaceWrapperHelper.getModelTranslationMap(attribute);
    final ITranslatableString caption = attributeTrlMap.getColumnTrl(I_M_Attribute.COLUMNNAME_Name, attribute.getName());
    final ITranslatableString description = attributeTrlMap.getColumnTrl(I_M_Attribute.COLUMNNAME_Description, attribute.getDescription());
    final String attributeName = HUEditorRowAttributesHelper.extractAttributeName(attributeValue);
    final DocumentFieldWidgetType widgetType = HUEditorRowAttributesHelper.extractWidgetType(attributeValue);
    return DocumentLayoutElementDescriptor.builder().setCaption(caption).setDescription(description).setWidgetType(widgetType).addField(DocumentLayoutElementFieldDescriptor.builder(attributeName).setPublicField(true).addDevices(createDevices(attribute.getValue(), warehouseId))).build();
}
Also used : IModelTranslationMap(de.metas.i18n.IModelTranslationMap) DocumentFieldWidgetType(de.metas.ui.web.window.descriptor.DocumentFieldWidgetType) ITranslatableString(de.metas.i18n.ITranslatableString) I_M_Attribute(org.compiere.model.I_M_Attribute) ITranslatableString(de.metas.i18n.ITranslatableString)

Example 9 with I_M_Attribute

use of org.compiere.model.I_M_Attribute in project metasfresh-webui-api by metasfresh.

the class WEBUI_M_Product_LotNumber_Lock method quarantineHUsForLotNo.

private void quarantineHUsForLotNo(final int lotNoLockId) {
    final I_M_Product_LotNumber_Lock lotNoLock = load(lotNoLockId, I_M_Product_LotNumber_Lock.class);
    final I_M_Attribute lotNoAttribute = Services.get(ILotNumberDateAttributeDAO.class).getLotNumberAttribute(getCtx());
    if (lotNoAttribute == null) {
        throw new AdempiereException("Not lotNo attribute found.");
    }
    final int productId = lotNoLock.getM_Product_ID();
    final String lotNoValue = lotNoLock.getLot();
    final List<I_M_HU> husForAttributeStringValue = retrieveHUsForAttributeStringValue(productId, lotNoAttribute, lotNoValue);
    final List<HUToDistribute> husToDistribute = new ArrayList<>();
    for (final I_M_HU hu : husForAttributeStringValue) {
        final List<de.metas.handlingunits.model.I_M_InOutLine> inOutLinesForHU = huInOutDAO.retrieveInOutLinesForHU(hu);
        if (Check.isEmpty(inOutLinesForHU)) {
            continue;
        }
        I_M_InOut firstReceipt = inOutLinesForHU.get(0).getM_InOut();
        final int bpartnerId = firstReceipt.getC_BPartner_ID();
        final int bpLocationId = firstReceipt.getC_BPartner_Location_ID();
        husToDistribute.add(HUToDistribute.builder().hu(hu).lockLotNo(lotNoLock).bpartnerId(bpartnerId).bpartnerLocationId(bpLocationId).build());
    }
    Services.get(IHUDDOrderBL.class).createQuarantineDDOrderForHUs(husToDistribute);
    setExistingInvoiceCandsInDispute(husForAttributeStringValue);
}
Also used : I_M_HU(de.metas.handlingunits.model.I_M_HU) I_M_InOut(org.compiere.model.I_M_InOut) HUToDistribute(de.metas.handlingunits.ddorder.api.impl.HUs2DDOrderProducer.HUToDistribute) ArrayList(java.util.ArrayList) I_M_Product_LotNumber_Lock(de.metas.product.model.I_M_Product_LotNumber_Lock) ILotNumberDateAttributeDAO(org.adempiere.mm.attributes.api.ILotNumberDateAttributeDAO) AdempiereException(org.adempiere.exceptions.AdempiereException) I_M_Attribute(org.compiere.model.I_M_Attribute) IHUDDOrderBL(de.metas.handlingunits.ddorder.api.IHUDDOrderBL)

Aggregations

I_M_Attribute (org.compiere.model.I_M_Attribute)9 AdempiereException (org.adempiere.exceptions.AdempiereException)3 I_M_HU (de.metas.handlingunits.model.I_M_HU)2 DocumentEntityDescriptor (de.metas.ui.web.window.descriptor.DocumentEntityDescriptor)2 DocumentFieldDescriptor (de.metas.ui.web.window.descriptor.DocumentFieldDescriptor)2 DocumentFieldWidgetType (de.metas.ui.web.window.descriptor.DocumentFieldWidgetType)2 IHUContext (de.metas.handlingunits.IHUContext)1 IAttributeStorage (de.metas.handlingunits.attribute.storage.IAttributeStorage)1 ISSCC18CodeDAO (de.metas.handlingunits.attributes.sscc18.ISSCC18CodeDAO)1 IHUDDOrderBL (de.metas.handlingunits.ddorder.api.IHUDDOrderBL)1 HUToDistribute (de.metas.handlingunits.ddorder.api.impl.HUs2DDOrderProducer.HUToDistribute)1 IModelTranslationMap (de.metas.i18n.IModelTranslationMap)1 ITranslatableString (de.metas.i18n.ITranslatableString)1 AttributesKey (de.metas.material.event.commons.AttributesKey)1 Check (de.metas.printing.esb.base.util.Check)1 I_M_Product_LotNumber_Lock (de.metas.product.model.I_M_Product_LotNumber_Lock)1 DocumentId (de.metas.ui.web.window.datatypes.DocumentId)1 DocumentType (de.metas.ui.web.window.datatypes.DocumentType)1 StringLookupValue (de.metas.ui.web.window.datatypes.LookupValue.StringLookupValue)1 JSONDate (de.metas.ui.web.window.datatypes.json.JSONDate)1