From 0dbbdcadab3f0a52c7cbdd9ed08c3d1b1d80f37c Mon Sep 17 00:00:00 2001 From: PeterTakacs300 <93127072+PeterTakacs300@users.noreply.github.com> Date: Thu, 9 Dec 2021 12:39:12 +0100 Subject: [PATCH] IDEMPIERE-5078 - M_inout movementtype add to before save (#1038) * IDEMPIERE-5078 - M_inout movementtype add to before save * IDEMPIERE-5078 - shared logic between CalloutInOut.doctype and MInOut.getMovementType * IDEMPIERE-5078 - javadoc added (#1038) Co-authored-by: Igor Pojzl --- .../src/org/compiere/model/CalloutInOut.java | 26 ++------ .../src/org/compiere/model/MInOut.java | 59 +++++++++++++------ 2 files changed, 46 insertions(+), 39 deletions(-) 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 c5f1a36799..91c3d2008e 100644 --- a/org.adempiere.base.callout/src/org/compiere/model/CalloutInOut.java +++ b/org.adempiere.base.callout/src/org/compiere/model/CalloutInOut.java @@ -196,6 +196,7 @@ public class CalloutInOut extends CalloutEngine String trxFlag = rs.getString("IsSOTrx"); Object isSOTrxValue = mTab.getValue("IsSOTrx"); String isSOTrxValueStr = null; + boolean IsSOTrx = "Y".equals(trxFlag); if (isSOTrxValue != null) { if (isSOTrxValue instanceof Boolean) @@ -206,28 +207,9 @@ public class CalloutInOut extends CalloutEngine if (!(trxFlag.equals(isSOTrxValueStr))) mTab.setValue("IsSOTrx", trxFlag); - if (DocBaseType.equals("MMS")) // Material Shipments - /**solve 1648131 bug vpj-cd e-evolution */ - { - boolean IsSOTrx = "Y".equals(trxFlag); - if (IsSOTrx) - mTab.setValue("MovementType", "C-"); // Customer Shipments - else - mTab.setValue("MovementType", "V-"); // Vendor Return - - } - /**END vpj-cd e-evolution */ - else if (DocBaseType.equals("MMR")) // Material Receipts - /**solve 1648131 bug vpj-cd e-evolution */ - { - boolean IsSOTrx = "Y".equals(trxFlag); - if (IsSOTrx) - mTab.setValue("MovementType", "C+"); // Customer Return - else - mTab.setValue("MovementType", "V+"); // Vendor Receipts - } - /**END vpj-cd e-evolution */ - + + mTab.setValue("MovementType", MInOut.getMovementType(ctx, C_DocType_ID, IsSOTrx, null)); + // DocumentNo if (rs.getString("IsDocNoControlled").equals("Y")) { diff --git a/org.adempiere.base/src/org/compiere/model/MInOut.java b/org.adempiere.base/src/org/compiere/model/MInOut.java index a757cb67e1..3bd669e666 100644 --- a/org.adempiere.base/src/org/compiere/model/MInOut.java +++ b/org.adempiere.base/src/org/compiere/model/MInOut.java @@ -202,15 +202,7 @@ public class MInOut extends X_M_InOut implements DocAction, IDocsPostProcess to.setIsSOTrx(isSOTrx); if (counter) { - MDocType docType = MDocType.get(from.getCtx(), C_DocType_ID); - if (MDocType.DOCBASETYPE_MaterialDelivery.equals(docType.getDocBaseType())) - { - to.setMovementType (isSOTrx ? MOVEMENTTYPE_CustomerShipment : MOVEMENTTYPE_VendorReturns); - } - else if (MDocType.DOCBASETYPE_MaterialReceipt.equals(docType.getDocBaseType())) - { - to.setMovementType (isSOTrx ? MOVEMENTTYPE_CustomerReturns : MOVEMENTTYPE_VendorReceipts); - } + to.setMovementType(); } // @@ -373,13 +365,7 @@ public class MInOut extends X_M_InOut implements DocAction, IDocsPostProcess } setC_DocType_ID (C_DocTypeShipment_ID); - String movementTypeShipment = null; - MDocType dtShipment = new MDocType(order.getCtx(), C_DocTypeShipment_ID, order.get_TrxName()); - if (dtShipment.getDocBaseType().equals(MDocType.DOCBASETYPE_MaterialDelivery)) - movementTypeShipment = dtShipment.isSOTrx() ? MOVEMENTTYPE_CustomerShipment : MOVEMENTTYPE_VendorReturns; - else if (dtShipment.getDocBaseType().equals(MDocType.DOCBASETYPE_MaterialReceipt)) - movementTypeShipment = dtShipment.isSOTrx() ? MOVEMENTTYPE_CustomerReturns : MOVEMENTTYPE_VendorReceipts; - setMovementType (movementTypeShipment); + setMovementType(); // Default - Today if (movementDate != null) @@ -992,7 +978,42 @@ public class MInOut extends X_M_InOut implements DocAction, IDocsPostProcess } } // setM_Warehouse_ID + /** + * Gets Movement Type based on Document Type's DocBaseType and isSOTrx + * @param ctx + * @param C_DocType_ID Document Type ID + * @param issotrx is sales transaction + * @param trxName transaction name + * @return Movement Type + */ + public static String getMovementType(Properties ctx, int C_DocType_ID, boolean issotrx, String trxName) { + String movementType = null; + MDocType docType = MDocType.get(C_DocType_ID); + + if (docType == null) return null; + + if (docType.getDocBaseType().equals(MDocType.DOCBASETYPE_MaterialDelivery)) + movementType = docType.isSOTrx() ? MOVEMENTTYPE_CustomerShipment : MOVEMENTTYPE_VendorReturns; + else if (docType.getDocBaseType().equals(MDocType.DOCBASETYPE_MaterialReceipt)) + movementType = docType.isSOTrx() ? MOVEMENTTYPE_CustomerReturns : MOVEMENTTYPE_VendorReceipts; + + return movementType; + } + /** + * Sets Movement Type based on Document Type's DocBaseType and isSOTrx + */ + public void setMovementType() { + + if(getC_DocType_ID() <= 0) { + log.saveError("FillMandatory", Msg.translate(getCtx(), "C_DocType_ID")); + return; + } + + String movementType = getMovementType(getCtx(), getC_DocType_ID(), isSOTrx(), get_TrxName()); + setMovementType(movementType); + } + /** * Before Save * @param newRecord new @@ -1000,6 +1021,10 @@ public class MInOut extends X_M_InOut implements DocAction, IDocsPostProcess */ protected boolean beforeSave (boolean newRecord) { + if(newRecord || is_ValueChanged("C_DocType")) { + setMovementType(); + } + MWarehouse wh = MWarehouse.get(getCtx(), getM_Warehouse_ID()); // Warehouse Org if (newRecord) @@ -1038,7 +1063,7 @@ public class MInOut extends X_M_InOut implements DocAction, IDocsPostProcess MDocType docType = MDocType.get(getCtx(), rma.getC_DocType_ID()); setC_DocType_ID(docType.getC_DocTypeShipment_ID()); } - + return true; } // beforeSave