From d6121597b0812ead62c271b31eeb3308be13dba8 Mon Sep 17 00:00:00 2001 From: Carlos Ruiz Date: Tue, 5 Dec 2023 15:01:12 +0100 Subject: [PATCH] IDEMPIERE-5782 Generated Shipments/MR and Invoices with Invalid SalesRep (#2127) * IDEMPIERE-5782 Generated Shipments/MR and Invoices with Invalid Sales Rep - Fix same issue with RMA * - add the callout validations also on beforeSave --- .../oracle/202312041243_IDEMPIERE-5782.sql | 10 +++++++ .../202312041243_IDEMPIERE-5782.sql | 7 +++++ .../src/org/adempiere/model/CalloutRMA.java | 30 +++++++++++++++++++ .../src/org/compiere/model/CalloutInOut.java | 1 + .../src/org/compiere/model/MInOut.java | 11 +++++++ .../src/org/compiere/model/MRMA.java | 4 +++ 6 files changed, 63 insertions(+) create mode 100644 migration/iD10/oracle/202312041243_IDEMPIERE-5782.sql create mode 100644 migration/iD10/postgresql/202312041243_IDEMPIERE-5782.sql diff --git a/migration/iD10/oracle/202312041243_IDEMPIERE-5782.sql b/migration/iD10/oracle/202312041243_IDEMPIERE-5782.sql new file mode 100644 index 0000000000..4ddf9edfd6 --- /dev/null +++ b/migration/iD10/oracle/202312041243_IDEMPIERE-5782.sql @@ -0,0 +1,10 @@ +-- IDEMPIERE-5782 Generated Shipments/MR and Invoices with Invalid Sales Rep +SELECT register_migration_script('202312041243_IDEMPIERE-5782.sql') FROM dual; + +SET SQLBLANKLINES ON +SET DEFINE OFF + +-- Dec 4, 2023, 12:43:33 PM CET +UPDATE AD_Column SET Callout='org.adempiere.model.CalloutRMA.inout',Updated=TO_TIMESTAMP('2023-12-04 12:43:33','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Column_ID=10842 +; + diff --git a/migration/iD10/postgresql/202312041243_IDEMPIERE-5782.sql b/migration/iD10/postgresql/202312041243_IDEMPIERE-5782.sql new file mode 100644 index 0000000000..41a4557cce --- /dev/null +++ b/migration/iD10/postgresql/202312041243_IDEMPIERE-5782.sql @@ -0,0 +1,7 @@ +-- IDEMPIERE-5782 Generated Shipments/MR and Invoices with Invalid Sales Rep +SELECT register_migration_script('202312041243_IDEMPIERE-5782.sql') FROM dual; + +-- Dec 4, 2023, 12:43:33 PM CET +UPDATE AD_Column SET Callout='org.adempiere.model.CalloutRMA.inout',Updated=TO_TIMESTAMP('2023-12-04 12:43:33','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Column_ID=10842 +; + diff --git a/org.adempiere.base.callout/src/org/adempiere/model/CalloutRMA.java b/org.adempiere.base.callout/src/org/adempiere/model/CalloutRMA.java index 4eab58ce9a..d71138b047 100644 --- a/org.adempiere.base.callout/src/org/adempiere/model/CalloutRMA.java +++ b/org.adempiere.base.callout/src/org/adempiere/model/CalloutRMA.java @@ -28,6 +28,7 @@ import org.compiere.model.GridField; import org.compiere.model.GridTab; import org.compiere.model.I_C_InvoiceLine; import org.compiere.model.MCharge; +import org.compiere.model.MInOut; import org.compiere.model.MInOutLine; import org.compiere.model.MInvoice; import org.compiere.model.MInvoiceLine; @@ -255,4 +256,33 @@ public class CalloutRMA extends CalloutEngine { return ""; } + + /** + * inOut - set sales rep based on shipment/receipt + * + * @param ctx + * @param WindowNo + * @param mTab + * @param mField + * @param value + * @return error message or "" + */ + public String inout(Properties ctx, int WindowNo, GridTab mTab, GridField mField, Object value) + { + Integer M_InOut_ID = (Integer) value; + if (M_InOut_ID == null || M_InOut_ID.intValue() == 0) + return ""; + + MInOut inout = new MInOut(ctx, M_InOut_ID, null); + if (inout.get_ID() != 0) + { + if (inout.getSalesRep_ID() > 0) + mTab.setValue("SalesRep_ID", Integer.valueOf(inout.getSalesRep_ID())); + else + mTab.setValue("SalesRep_ID", null); + } + + return ""; + } + } 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 d36ff9d6db..412e02f231 100644 --- a/org.adempiere.base.callout/src/org/compiere/model/CalloutInOut.java +++ b/org.adempiere.base.callout/src/org/compiere/model/CalloutInOut.java @@ -153,6 +153,7 @@ public class CalloutInOut extends CalloutEngine mTab.setValue("FreightAmt", originalReceipt.getFreightAmt()); mTab.setValue("C_BPartner_ID", Integer.valueOf(originalReceipt.getC_BPartner_ID())); + mTab.setValue("SalesRep_ID", Integer.valueOf(originalReceipt.getSalesRep_ID())); //[ 1867464 ] mTab.setValue("C_BPartner_Location_ID", Integer.valueOf(originalReceipt.getC_BPartner_Location_ID())); diff --git a/org.adempiere.base/src/org/compiere/model/MInOut.java b/org.adempiere.base/src/org/compiere/model/MInOut.java index 1da39171da..619a9e7a32 100644 --- a/org.adempiere.base/src/org/compiere/model/MInOut.java +++ b/org.adempiere.base/src/org/compiere/model/MInOut.java @@ -1337,6 +1337,17 @@ public class MInOut extends X_M_InOut implements DocAction, IDocsPostProcess } } + if (getSalesRep_ID() == 0) { + if (getC_Order_ID() > 0) { + MOrder order = new MOrder(getCtx(), getC_Order_ID(), get_TrxName()); + setSalesRep_ID(order.getSalesRep_ID()); + } else if (getM_RMA_ID() > 0) { + MRMA rma = new MRMA(getCtx(), getM_RMA_ID(), get_TrxName()); + MInOut originalReceipt = rma.getShipment(); + setSalesRep_ID(originalReceipt.getSalesRep_ID()); + } + } + return true; } // beforeSave diff --git a/org.adempiere.base/src/org/compiere/model/MRMA.java b/org.adempiere.base/src/org/compiere/model/MRMA.java index 7450110c25..1923f76b9d 100644 --- a/org.adempiere.base/src/org/compiere/model/MRMA.java +++ b/org.adempiere.base/src/org/compiere/model/MRMA.java @@ -294,6 +294,10 @@ public class MRMA extends X_M_RMA implements DocAction return false; } + if (getSalesRep_ID() == 0 && m_inout != null && m_inout.getSalesRep_ID() > 0) { + setSalesRep_ID(m_inout.getSalesRep_ID()); + } + return true; } // beforeSave