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();
}
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));
}
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();
}
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);
}
Aggregations