diff --git a/org.adempiere.base.callout/src/org/compiere/model/CalloutInOut.java b/org.adempiere.base.callout/src/org/compiere/model/CalloutInOut.java index ad6ba41f53..fbd14fc420 100644 --- a/org.adempiere.base.callout/src/org/compiere/model/CalloutInOut.java +++ b/org.adempiere.base.callout/src/org/compiere/model/CalloutInOut.java @@ -86,6 +86,20 @@ public class CalloutInOut extends CalloutEngine else mTab.setValue("AD_User_ID", null); } + /** + * Modification: set corresponding document type + */ + int docTypeId = order.getC_DocType_ID(); + int relatedDocTypeId = 0; + + if (docTypeId == 0) + { + docTypeId = order.getC_DocTypeTarget_ID(); + } + + relatedDocTypeId = MDocType.getShipmentReceiptDocType(docTypeId); + + mTab.setValue("C_DocType_ID", relatedDocTypeId); return ""; } // order @@ -179,6 +193,8 @@ public class CalloutInOut extends CalloutEngine String DocBaseType = rs.getString("DocBaseType"); // BF [2708789] Read IsSOTrx from C_DocType String trxFlag = rs.getString(7); + if (!(trxFlag.equals(mTab.getValue("IsSOTrx")))) + mTab.setValue("IsSOTrx", trxFlag); if (DocBaseType.equals("MMS")) // Material Shipments /**solve 1648131 bug vpj-cd e-evolution */ { @@ -198,9 +214,7 @@ public class CalloutInOut extends CalloutEngine mTab.setValue("MovementType", "C+"); // Customer Return else mTab.setValue("MovementType", "V+"); // Vendor Receipts - } - if (!(trxFlag.equals(mTab.getValue("IsSOTrx")))) - mTab.setValue("IsSOTrx", trxFlag); + } /**END vpj-cd e-evolution */ // DocumentNo diff --git a/org.adempiere.base/src/org/compiere/model/MDocType.java b/org.adempiere.base/src/org/compiere/model/MDocType.java index 927700fb48..16dd8a0cad 100644 --- a/org.adempiere.base/src/org/compiere/model/MDocType.java +++ b/org.adempiere.base/src/org/compiere/model/MDocType.java @@ -302,5 +302,59 @@ public class MDocType extends X_C_DocType } return success; } // afterDelete - + + /** + * Returns Document type for the shipment/receipt based + * on Document type provided for order/rma + * @param docTypeId + * @return shipment/receipt doctype id + */ + public static int getShipmentReceiptDocType(int docTypeId) + { + int relatedDocTypeId = 0; + if (docTypeId != 0) + { + MDocType docType = MDocType.get(Env.getCtx(), docTypeId); + // FIXME: Should refactor code and remove the hard coded name + // Should change document type to allow query the value + if ("Return Material".equals(docType.getName()) || + "Vendor Return".equals(docType.getName())|| !docType.isSOTrx()) + { + String relatedDocTypeName = null; + if (("Purchase Order").equals(docType.getName())) + { + relatedDocTypeName = "MM Receipt"; + } + else if ("Return Material".equals(docType.getName())) + { + relatedDocTypeName = "MM Returns"; + } + else if ("Vendor Return".equals(docType.getName())) + { + relatedDocTypeName = "MM Vendor Returns"; + } + + if (relatedDocTypeName != null) + { + StringBuffer whereClause = new StringBuffer(30); + whereClause.append("Name='").append(relatedDocTypeName).append("' "); + whereClause.append("and AD_Client_ID=").append(Env.getAD_Client_ID(Env.getCtx())); + whereClause.append(" AND IsActive='Y'"); + + int relDocTypeIds[] = MDocType.getAllIDs(MDocType.Table_Name, whereClause.toString(), null); + + if (relDocTypeIds.length > 0) + { + relatedDocTypeId = relDocTypeIds[0]; + } + } + } + else + { + relatedDocTypeId = docType.getC_DocTypeShipment_ID(); + } + } + + return relatedDocTypeId; + } } // MDocType