use of org.adempiere.exceptions.AdempiereException in project adempiere by adempiere.
the class InterfaceWrapperHelper method getValue.
private static <T> T getValue(final Object model, final String columnName, final boolean throwExIfColumnNotFound) {
Check.assumeNotNull(model, "model is not null");
Check.assumeNotNull(columnName, "columnName is not null");
if (GridTabWrapper.isHandled(model)) {
final GridTab gridTab = GridTabWrapper.getGridTab(model);
final GridField gridField = gridTab.getField(columnName);
if (gridField == null) {
if (throwExIfColumnNotFound) {
throw new AdempiereException("No field with ColumnName=" + columnName + " found in " + gridTab + " for " + model);
} else {
return null;
}
}
@SuppressWarnings("unchecked") final T value = (T) gridField.getValue();
return value;
} else if (POWrapper.isHandled(model)) {
PO po = POWrapper.getPO(model, false);
final int idx = po.get_ColumnIndex(columnName);
if (idx < 0) {
if (throwExIfColumnNotFound) {
throw new AdempiereException("No columnName " + columnName + " found for " + model);
} else {
return null;
}
}
@SuppressWarnings("unchecked") T value = (T) po.get_Value(idx);
return value;
} else {
throw new AdempiereException("Model wrapping is not supported for " + model + " (class:" + model.getClass() + ")");
}
}
use of org.adempiere.exceptions.AdempiereException in project adempiere by adempiere.
the class ImpFormat method loadFile.
// updateDB
public void loadFile(Properties ctx, File file, String trxName, int AD_Client_ID, int AD_Org_ID, boolean excludeHeaderRow) {
m_AD_Client_ID = AD_Client_ID;
m_AD_Org_ID = AD_Org_ID;
if (file == null)
throw new AdempiereException("No file");
try {
Charset charset = Ini.getCharset();
BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(file), charset), 10240);
String s = null;
boolean first = true;
while ((s = in.readLine()) != null) {
if (first && excludeHeaderRow) {
first = false;
continue;
}
first = false;
updateDB(ctx, s, trxName);
}
in.close();
} catch (Exception e) {
throw new AdempiereException("Load error", e);
}
}
use of org.adempiere.exceptions.AdempiereException in project adempiere by adempiere.
the class MInvoiceLine method setRMALine.
// copyLinesFrom
// end MZ
/**
* @param rmaline
*/
public void setRMALine(MRMALine rmaLine) {
// Check if this invoice is CreditMemo - teo_sarca [ 2804142 ]
if (!getParent().isCreditMemo()) {
throw new AdempiereException("InvoiceNotCreditMemo");
}
setAD_Org_ID(rmaLine.getAD_Org_ID());
setM_RMALine_ID(rmaLine.getM_RMALine_ID());
setDescription(rmaLine.getDescription());
setLine(rmaLine.getLine());
setC_Charge_ID(rmaLine.getC_Charge_ID());
setM_Product_ID(rmaLine.getM_Product_ID());
setC_UOM_ID(rmaLine.getC_UOM_ID());
setC_Tax_ID(rmaLine.getC_Tax_ID());
setPrice(rmaLine.getAmt());
BigDecimal qty = rmaLine.getQty();
if (rmaLine.getQtyInvoiced() != null)
qty = qty.subtract(rmaLine.getQtyInvoiced());
setQty(qty);
setLineNetAmt();
setTaxAmt();
setLineTotalAmt(rmaLine.getLineNetAmt());
setC_Project_ID(rmaLine.getC_Project_ID());
setC_Activity_ID(rmaLine.getC_Activity_ID());
setC_Campaign_ID(rmaLine.getC_Campaign_ID());
}
use of org.adempiere.exceptions.AdempiereException in project adempiere by adempiere.
the class Browser method getInfoColumnForAxisField.
/**
* Get Info_Column for Axis Field
* @param field defined as Axis
* @return Info_Column with Axis Field
*/
public List<MBrowseField> getInfoColumnForAxisField(MBrowseField field) {
List<MBrowseField> list = new ArrayList<MBrowseField>();
axisParameters = new ArrayList<>();
axisParametersValues = new ArrayList<>();
try {
I_AD_View_Column xcol, pcol, ycol;
xcol = field.getAD_View_Column();
pcol = field.getAxis_Parent_Column();
ycol = field.getAxis_Column();
String columnName = xcol.getAD_Column().getColumnName();
MBrowseField fieldKey = ((MBrowse) field.getAD_Browse()).getFieldKey();
if (fieldKey == null)
throw new AdempiereException("@NotFound@ @IsKey@");
MTable xTable = (MTable) ycol.getAD_View_Definition().getAD_Table();
String xTableName = xTable.getTableName();
String keyColumn = MQuery.getZoomColumnName(columnName);
String tableName = MQuery.getZoomTableName(columnName);
String whereClause = "";
if (pcol != null && pcol.getAD_View_Column_ID() > 0) {
MTable parentTable = MTable.get(field.getCtx(), tableName);
MColumn parentColumn = getParentColumn(parentTable.getAD_Table_ID());
if (parentColumn == null)
throw new AdempiereException("@NotFound@ @IsParent@");
// BR [ 242 ]
if (field.getAD_Val_Rule_ID() > 0)
whereClause = Env.parseContext(Env.getCtx(), getWindowNo(), field.getAD_Val_Rule().getCode(), false);
}
MLookup lookup = MLookupFactory.get(Env.getCtx(), 0, xcol.getAD_Column_ID(), field.getAD_Reference_ID(), m_language, keyColumn, field.getAD_Reference_Value_ID(), false, whereClause);
int cols = 0;
StringBuilder axisSql = new StringBuilder("(SELECT ");
axisSql.append("SUM(").append(ycol.getAD_Column().getColumnName()).append(") FROM ").append(ycol.getAD_View_Definition().getAD_Table().getTableName()).append(" WHERE ").append(xTableName).append(".").append(fieldKey.getAD_View_Column().getAD_Column().getColumnName()).append("=").append(fieldKey.getAD_View_Column().getColumnSQL());
for (int id : getAxisRecordIds(tableName, whereClause)) {
cols++;
String display = lookup.getDisplay(id).trim();
display = display.length() > 12 ? display.substring(1, 12) + "_" + cols : display;
String joinColumn = Msg.translate(m_language, ycol.getAD_Column().getColumnName());
joinColumn = joinColumn.length() > 15 ? joinColumn.substring(1, 15) : joinColumn;
String sqlColName = display + "/" + joinColumn;
String colName = lookup.getDisplay(id).trim() + "/" + Msg.translate(m_language, ycol.getAD_Column().getColumnName());
StringBuilder axisWhere = new StringBuilder(" ");
axisWhere.append(getAxisSQLWhere(ycol)).append(" AND ").append(xcol.getAD_View_Definition().getTableAlias()).append(".").append(xcol.getAD_Column().getColumnName());
StringBuffer select = new StringBuffer();
select.append(axisSql).append(axisWhere);
select.append("=").append(id).append(")");
MViewColumn viewColumn = new MViewColumn(field.getCtx(), 0, field.get_TrxName());
MViewColumn.copyValues((MViewColumn) ycol, viewColumn);
viewColumn.setAD_View_Column_ID(ycol.getAD_View_Column_ID());
viewColumn.setAD_Column_ID(ycol.getAD_Column_ID());
viewColumn.setColumnSQL(select.toString());
viewColumn.setColumnName("\"" + sqlColName + "\"");
MBrowseField browseField = new MBrowseField((MBrowse) field.getAD_Browse(), viewColumn);
browseField.setAD_Browse_ID(field.getAD_Browse_ID());
browseField.setAD_Element_ID(field.getAD_Element_ID());
browseField.setName(colName);
browseField.setDescription(viewColumn.getDescription());
browseField.setHelp(viewColumn.getHelp());
if (viewColumn.get_ID() > 0)
browseField.setAD_View_Column_ID(viewColumn.getAD_View_Column_ID());
browseField.setIsActive(true);
browseField.setIsIdentifier(viewColumn.isIdentifier());
browseField.setIsRange(false);
browseField.setIsQueryCriteria(false);
browseField.setAD_Reference_ID(ycol.getAD_Column().getAD_Reference_ID());
browseField.setAD_Reference_Value_ID(ycol.getAD_Column().getAD_Reference_Value_ID());
browseField.setIsKey(false);
browseField.setIsDisplayed(true);
browseField.setAxis_Column_ID(field.getAxis_Column_ID());
browseField.setAxis_Parent_Column_ID(field.getAxis_Parent_Column_ID());
browseField.setIsReadOnly(field.isReadOnly());
browseField.setAD_Element_ID(field.getAD_Element_ID());
list.add(browseField);
log.finest("Added Column=" + sqlColName + " SQL = " + select);
}
} catch (Exception e) {
throw new AdempiereException(e);
}
return list;
}
use of org.adempiere.exceptions.AdempiereException in project adempiere by adempiere.
the class ReleaseInOutBound method createDistributionOrder.
/**
* get Out Bound Order Lines from Smart Browser
* @return
*/
/*private List <MWMInOutBoundLine> getOutBoundOrderLine()
{
StringBuilder whereClause = new StringBuilder();
whereClause.append("EXISTS (SELECT 1 FROM WM_InOutBound o WHERE o.WM_InOutBound_ID=WM_InOutBoundLine.WM_InOutBound_ID AND o.Processed='N' AND o.DocAction NOT IN ('CO','CL','VO')) AND ");
whereClause.append("EXISTS (SELECT T_Selection_ID FROM T_Selection WHERE T_Selection.AD_PInstance_ID=? AND T_Selection.T_Selection_ID=WM_InOutBoundLine.WM_InOutboundLine_ID)");
return new Query(getCtx(), I_WM_InOutBoundLine.Table_Name, whereClause.toString(), get_TrxName())
.setClient_ID()
.setParameters(getAD_PInstance_ID())
.list();
}*/
/**
* create Distribution Order to performance a Pick List
* @param outBoundOrderLine Out bound Line
* @return Quantity that was not covert for inventory
*/
protected BigDecimal createDistributionOrder(MWMInOutBoundLine outBoundOrderLine) {
WMRuleEngine engineRule = WMRuleEngine.get();
List<MStorage> storageList = engineRule.getStorage(outBoundOrderLine, getWarehouseAreaTypeId(), getWarehouseSectionTypeId());
int shipperId = 0;
BigDecimal qtySupply = BigDecimal.ZERO;
if (storageList != null && storageList.size() > 0) {
//get the warehouse in transit
MWarehouse[] wsts = MWarehouse.getInTransitForOrg(getCtx(), outBoundLocator.getAD_Org_ID());
if (wsts == null || wsts.length == 0)
throw new AdempiereException("@M_Warehouse_ID@ @IsInTransit@ @NotFound@");
//Org Must be linked to BPartner
MOrg org = MOrg.get(getCtx(), outBoundLocator.getAD_Org_ID());
int partnerId = org.getLinkedC_BPartner_ID(get_TrxName());
if (partnerId == 0)
throw new NoBPartnerLinkedforOrgException(org);
MBPartner partner = MBPartner.get(getCtx(), partnerId);
if (orderDistribution == null) {
orderDistribution = new MDDOrder(getCtx(), 0, get_TrxName());
orderDistribution.setAD_Org_ID(outBoundLocator.getAD_Org_ID());
orderDistribution.setC_BPartner_ID(partnerId);
if (getDocumentTypeId() > 0) {
orderDistribution.setC_DocType_ID(getDocumentTypeId());
} else {
orderDistribution.setC_DocType_ID(MDocType.getDocType(X_C_DocType.DOCBASETYPE_DistributionOrder));
}
orderDistribution.setM_Warehouse_ID(wsts[0].get_ID());
if (getDocumentAction() != null)
orderDistribution.setDocAction(getDocumentAction());
else
orderDistribution.setDocAction(X_DD_Order.DOCACTION_Prepare);
MUser[] users = MUser.getOfBPartner(getCtx(), partner.getC_BPartner_ID(), get_TrxName());
if (users == null || users.length == 0)
throw new AdempiereException("@AD_User_ID@ @NotFound@ @Value@ - @C_BPartner_ID@ : " + partner.getValue() + " - " + partner.getName());
orderDistribution.setAD_User_ID(users[0].getAD_User_ID());
orderDistribution.setDateOrdered(getToday());
orderDistribution.setDatePromised(getToday());
orderDistribution.setM_Shipper_ID(shipperId);
orderDistribution.setIsInDispute(false);
orderDistribution.setIsInTransit(false);
orderDistribution.setSalesRep_ID(getAD_User_ID());
orderDistribution.saveEx();
}
storageList.stream().forEach(storage -> {
MDDOrderLine orderLine = new MDDOrderLine(orderDistribution);
orderLine.setM_Locator_ID(storage.getM_Locator_ID());
orderLine.setM_LocatorTo_ID(outBoundLocator.getM_Locator_ID());
orderLine.setC_UOM_ID(outBoundOrderLine.getC_UOM_ID());
orderLine.setM_Product_ID(outBoundOrderLine.getM_Product_ID());
orderLine.setDateOrdered(getToday());
orderLine.setDatePromised(outBoundOrderLine.getPickDate());
orderLine.setWM_InOutBoundLine_ID(outBoundOrderLine.getWM_InOutBoundLine_ID());
orderLine.setIsInvoiced(false);
orderLine.saveEx();
});
} else {
qtySupply = outBoundOrderLine.getQtyToPick().subtract(qtySupply);
}
return qtySupply;
}
Aggregations