From 41aa4102cd678877198038a286ed09a3fa80d645 Mon Sep 17 00:00:00 2001 From: hengsin Date: Fri, 27 Mar 2020 11:34:27 +0800 Subject: [PATCH] IDEMPIERE-4223 Model class generated with wrong datatype for Column with displaytype=button and columname ends with _ID --- .../compiere/process/BPartnerOrgUnLink.java | 4 +-- .../org/compiere/process/DistributionRun.java | 30 +++++++++---------- .../org/compiere/process/ProjectSetType.java | 2 +- .../util/ModelInterfaceGenerator.java | 4 +++ .../src/org/compiere/model/I_C_BPartner.java | 4 +-- .../src/org/compiere/model/I_C_Project.java | 4 +-- .../src/org/compiere/model/MBPartner.java | 28 ++--------------- .../src/org/compiere/model/MInOut.java | 2 +- .../src/org/compiere/model/MInvoice.java | 2 +- .../src/org/compiere/model/MOrder.java | 2 +- .../src/org/compiere/model/MPayment.java | 2 +- .../src/org/compiere/model/MProject.java | 27 ++--------------- .../src/org/compiere/model/MRMA.java | 2 +- .../src/org/compiere/model/POInfoColumn.java | 4 +++ .../src/org/compiere/model/X_C_BPartner.java | 20 ++++++++----- .../src/org/compiere/model/X_C_Project.java | 16 ++++++---- 16 files changed, 63 insertions(+), 90 deletions(-) diff --git a/org.adempiere.base.process/src/org/compiere/process/BPartnerOrgUnLink.java b/org.adempiere.base.process/src/org/compiere/process/BPartnerOrgUnLink.java index 16170b9fc0..a422612e5e 100644 --- a/org.adempiere.base.process/src/org/compiere/process/BPartnerOrgUnLink.java +++ b/org.adempiere.base.process/src/org/compiere/process/BPartnerOrgUnLink.java @@ -64,9 +64,9 @@ public class BPartnerOrgUnLink extends SvrProcess if (bp.get_ID() == 0) throw new IllegalArgumentException ("Business Partner not found - C_BPartner_ID=" + p_C_BPartner_ID); // - if (bp.getAD_OrgBP_ID_Int() == 0) + if (bp.getAD_OrgBP_ID() == 0) throw new IllegalArgumentException ("Business Partner not linked to an Organization"); - bp.setAD_OrgBP_ID(null); + bp.setAD_OrgBP_ID(0); if (!bp.save()) throw new IllegalArgumentException ("Business Partner not changed"); diff --git a/org.adempiere.base.process/src/org/compiere/process/DistributionRun.java b/org.adempiere.base.process/src/org/compiere/process/DistributionRun.java index 757863c662..3b9de27e47 100644 --- a/org.adempiere.base.process/src/org/compiere/process/DistributionRun.java +++ b/org.adempiere.base.process/src/org/compiere/process/DistributionRun.java @@ -516,12 +516,12 @@ public class DistributionRun extends SvrProcess order.setC_DocType_ID(m_docType.getC_DocType_ID()); order.setIsSOTrx(m_docType.isSOTrx()); // Counter Doc - if (counter && bp.getAD_OrgBP_ID_Int() > 0) + if (counter && bp.getAD_OrgBP_ID() > 0) { - if (log.isLoggable(Level.FINE)) log.fine("Counter - From_BPOrg=" + bp.getAD_OrgBP_ID_Int() + if (log.isLoggable(Level.FINE)) log.fine("Counter - From_BPOrg=" + bp.getAD_OrgBP_ID() + "-" + bp + ", To_BP=" + runBPartner); - order.setAD_Org_ID(bp.getAD_OrgBP_ID_Int()); - MOrgInfo oi = MOrgInfo.get(getCtx(), bp.getAD_OrgBP_ID_Int(), get_TrxName()); + order.setAD_Org_ID(bp.getAD_OrgBP_ID()); + MOrgInfo oi = MOrgInfo.get(getCtx(), bp.getAD_OrgBP_ID(), get_TrxName()); if (oi.getM_Warehouse_ID() > 0) order.setM_Warehouse_ID(oi.getM_Warehouse_ID()); order.setBPartner(runBPartner); @@ -557,7 +557,7 @@ public class DistributionRun extends SvrProcess // Create Order Line MOrderLine line = new MOrderLine(order); - if (counter && bp.getAD_OrgBP_ID_Int() > 0) + if (counter && bp.getAD_OrgBP_ID() > 0) ; // don't overwrite counter doc else // normal - optionally overwrite { @@ -929,7 +929,7 @@ public class DistributionRun extends SvrProcess lastC_BPartner_Location_ID = detail.getC_BPartner_Location_ID(); bp = new MBPartner (getCtx(), detail.getC_BPartner_ID(), get_TrxName()); - MOrgInfo oi_target = MOrgInfo.get(getCtx(), bp.getAD_OrgBP_ID_Int(), get_TrxName()); + MOrgInfo oi_target = MOrgInfo.get(getCtx(), bp.getAD_OrgBP_ID(), get_TrxName()); m_target = MWarehouse.get(getCtx(), oi_target.getM_Warehouse_ID()); if(m_target==null) throw new AdempiereException("Do not exist Default Warehouse Target"); @@ -944,7 +944,7 @@ public class DistributionRun extends SvrProcess if(p_ConsolidateDocument) { - StringBuilder whereClause = new StringBuilder("DocStatus IN ('DR','IN') AND AD_Org_ID=").append(bp.getAD_OrgBP_ID_Int()).append(" AND ") + StringBuilder whereClause = new StringBuilder("DocStatus IN ('DR','IN') AND AD_Org_ID=").append(bp.getAD_OrgBP_ID()).append(" AND ") .append(MDDOrder.COLUMNNAME_C_BPartner_ID).append("=? AND ") .append(MDDOrder.COLUMNNAME_M_Warehouse_ID).append("=? AND ") .append(MDDOrder.COLUMNNAME_DatePromised).append("<=? "); @@ -961,16 +961,16 @@ public class DistributionRun extends SvrProcess if (!p_IsTest) { order = new MDDOrder (getCtx(), 0, get_TrxName()); - order.setAD_Org_ID(bp.getAD_OrgBP_ID_Int()); + order.setAD_Org_ID(bp.getAD_OrgBP_ID()); order.setC_DocType_ID(m_docType.getC_DocType_ID()); order.setIsSOTrx(m_docType.isSOTrx()); // Counter Doc - if (counter && bp.getAD_OrgBP_ID_Int() > 0) + if (counter && bp.getAD_OrgBP_ID() > 0) { - if (log.isLoggable(Level.FINE)) log.fine("Counter - From_BPOrg=" + bp.getAD_OrgBP_ID_Int() + if (log.isLoggable(Level.FINE)) log.fine("Counter - From_BPOrg=" + bp.getAD_OrgBP_ID() + "-" + bp + ", To_BP=" + runBPartner); - order.setAD_Org_ID(bp.getAD_OrgBP_ID_Int()); + order.setAD_Org_ID(bp.getAD_OrgBP_ID()); if (ws[0].getM_Warehouse_ID() > 0) order.setM_Warehouse_ID(ws[0].getM_Warehouse_ID()); order.setBPartner(runBPartner); @@ -979,7 +979,7 @@ public class DistributionRun extends SvrProcess { if (log.isLoggable(Level.FINE)) log.fine("From_Org=" + runAD_Org_ID + ", To_BP=" + bp); - order.setAD_Org_ID(bp.getAD_OrgBP_ID_Int()); + order.setAD_Org_ID(bp.getAD_OrgBP_ID()); order.setBPartner(bp); if (detail.getC_BPartner_Location_ID() != 0) order.setC_BPartner_Location_ID(detail.getC_BPartner_Location_ID()); @@ -1015,7 +1015,7 @@ public class DistributionRun extends SvrProcess if (DD_OrderLine_ID <= 0) { MDDOrderLine line = new MDDOrderLine(order); - line.setAD_Org_ID(bp.getAD_OrgBP_ID_Int()); + line.setAD_Org_ID(bp.getAD_OrgBP_ID()); line.setM_Locator_ID(m_locator.getM_Locator_ID()); line.setM_LocatorTo_ID(m_locator_to.getM_Locator_ID()); line.setIsInvoiced(false); @@ -1059,7 +1059,7 @@ public class DistributionRun extends SvrProcess { // Create Order Line MDDOrderLine line = new MDDOrderLine(order); - if (counter && bp.getAD_OrgBP_ID_Int() > 0) + if (counter && bp.getAD_OrgBP_ID() > 0) ; // don't overwrite counter doc /*else // normal - optionally overwrite { @@ -1068,7 +1068,7 @@ public class DistributionRun extends SvrProcess line.setC_BPartner_Location_ID(detail.getC_BPartner_Location_ID()); }*/ // - line.setAD_Org_ID(bp.getAD_OrgBP_ID_Int()); + line.setAD_Org_ID(bp.getAD_OrgBP_ID()); line.setM_Locator_ID(m_locator.getM_Locator_ID()); line.setM_LocatorTo_ID(m_locator_to.getM_Locator_ID()); line.setIsInvoiced(false); diff --git a/org.adempiere.base.process/src/org/compiere/process/ProjectSetType.java b/org.adempiere.base.process/src/org/compiere/process/ProjectSetType.java index d9d1ac8726..2d0d1f7e64 100644 --- a/org.adempiere.base.process/src/org/compiere/process/ProjectSetType.java +++ b/org.adempiere.base.process/src/org/compiere/process/ProjectSetType.java @@ -66,7 +66,7 @@ public class ProjectSetType extends SvrProcess MProject project = new MProject (getCtx(), m_C_Project_ID, get_TrxName()); if (project.getC_Project_ID() == 0 || project.getC_Project_ID() != m_C_Project_ID) throw new IllegalArgumentException("Project not found C_Project_ID=" + m_C_Project_ID); - if (project.getC_ProjectType_ID_Int() > 0) + if (project.getC_ProjectType_ID() > 0) throw new IllegalArgumentException("Project already has Type (Cannot overwrite) " + project.getC_ProjectType_ID()); // MProjectType type = new MProjectType (getCtx(), m_C_ProjectType_ID, get_TrxName()); diff --git a/org.adempiere.base/src/org/adempiere/util/ModelInterfaceGenerator.java b/org.adempiere.base/src/org/adempiere/util/ModelInterfaceGenerator.java index 2e6b4a12f4..ad06da5b93 100644 --- a/org.adempiere.base/src/org/adempiere/util/ModelInterfaceGenerator.java +++ b/org.adempiere.base/src/org/adempiere/util/ModelInterfaceGenerator.java @@ -533,6 +533,10 @@ public class ModelInterfaceGenerator // return getClass(columnName, displayType, AD_Reference_ID); // recursive call with new parameters } + else if (displayType == DisplayType.Button && columnName.endsWith("_ID")) + { + return Integer.class; + } else { return DisplayType.getClass(displayType, true); diff --git a/org.adempiere.base/src/org/compiere/model/I_C_BPartner.java b/org.adempiere.base/src/org/compiere/model/I_C_BPartner.java index 6f5053db00..0009b3b552 100644 --- a/org.adempiere.base/src/org/compiere/model/I_C_BPartner.java +++ b/org.adempiere.base/src/org/compiere/model/I_C_BPartner.java @@ -94,12 +94,12 @@ public interface I_C_BPartner /** Set Linked Organization. * The Business Partner is another Organization for explicit Inter-Org transactions */ - public void setAD_OrgBP_ID (String AD_OrgBP_ID); + public void setAD_OrgBP_ID (int AD_OrgBP_ID); /** Get Linked Organization. * The Business Partner is another Organization for explicit Inter-Org transactions */ - public String getAD_OrgBP_ID(); + public int getAD_OrgBP_ID(); /** Column name AD_Org_ID */ public static final String COLUMNNAME_AD_Org_ID = "AD_Org_ID"; diff --git a/org.adempiere.base/src/org/compiere/model/I_C_Project.java b/org.adempiere.base/src/org/compiere/model/I_C_Project.java index 4ed500144c..13b88f2c85 100644 --- a/org.adempiere.base/src/org/compiere/model/I_C_Project.java +++ b/org.adempiere.base/src/org/compiere/model/I_C_Project.java @@ -268,12 +268,12 @@ public interface I_C_Project /** Set Project Type. * Type of the project */ - public void setC_ProjectType_ID (String C_ProjectType_ID); + public void setC_ProjectType_ID (int C_ProjectType_ID); /** Get Project Type. * Type of the project */ - public String getC_ProjectType_ID(); + public int getC_ProjectType_ID(); /** Column name C_Project_UU */ public static final String COLUMNNAME_C_Project_UU = "C_Project_UU"; diff --git a/org.adempiere.base/src/org/compiere/model/MBPartner.java b/org.adempiere.base/src/org/compiere/model/MBPartner.java index f48e61ece5..4e00562582 100644 --- a/org.adempiere.base/src/org/compiere/model/MBPartner.java +++ b/org.adempiere.base/src/org/compiere/model/MBPartner.java @@ -573,41 +573,17 @@ public class MBPartner extends X_C_BPartner super.setClientOrg(AD_Client_ID, AD_Org_ID); } // setClientOrg - /** - * Set Linked Organization. - * (is Button) - * @param AD_OrgBP_ID - */ - public void setAD_OrgBP_ID (int AD_OrgBP_ID) - { - if (AD_OrgBP_ID == 0) - super.setAD_OrgBP_ID (null); - else - super.set_Value("AD_OrgBP_ID", AD_OrgBP_ID); - } // setAD_OrgBP_ID - /** * Get Linked Organization. * (is Button) * The Business Partner is another Organization * for explicit Inter-Org transactions * @return AD_Org_ID if BP + * @deprecated */ public int getAD_OrgBP_ID_Int() { - String org = super.getAD_OrgBP_ID(); - if (org == null) - return 0; - int AD_OrgBP_ID = 0; - try - { - AD_OrgBP_ID = Integer.parseInt (org); - } - catch (Exception ex) - { - log.log(Level.SEVERE, org, ex); - } - return AD_OrgBP_ID; + return getAD_OrgBP_ID(); } // getAD_OrgBP_ID_Int /** diff --git a/org.adempiere.base/src/org/compiere/model/MInOut.java b/org.adempiere.base/src/org/compiere/model/MInOut.java index 6b97cc497f..be0113f9db 100644 --- a/org.adempiere.base/src/org/compiere/model/MInOut.java +++ b/org.adempiere.base/src/org/compiere/model/MInOut.java @@ -1973,7 +1973,7 @@ public class MInOut extends X_M_InOut implements DocAction return null; // Business Partner needs to be linked to Org MBPartner bp = new MBPartner (getCtx(), getC_BPartner_ID(), get_TrxName()); - int counterAD_Org_ID = bp.getAD_OrgBP_ID_Int(); + int counterAD_Org_ID = bp.getAD_OrgBP_ID(); if (counterAD_Org_ID == 0) return null; diff --git a/org.adempiere.base/src/org/compiere/model/MInvoice.java b/org.adempiere.base/src/org/compiere/model/MInvoice.java index 31bf99d26e..3c60e60fb9 100644 --- a/org.adempiere.base/src/org/compiere/model/MInvoice.java +++ b/org.adempiere.base/src/org/compiere/model/MInvoice.java @@ -2205,7 +2205,7 @@ public class MInvoice extends X_C_Invoice implements DocAction return null; // Business Partner needs to be linked to Org MBPartner bp = new MBPartner (getCtx(), getC_BPartner_ID(), null); - int counterAD_Org_ID = bp.getAD_OrgBP_ID_Int(); + int counterAD_Org_ID = bp.getAD_OrgBP_ID(); if (counterAD_Org_ID == 0) return null; diff --git a/org.adempiere.base/src/org/compiere/model/MOrder.java b/org.adempiere.base/src/org/compiere/model/MOrder.java index 11a6f29677..c417e3a87b 100644 --- a/org.adempiere.base/src/org/compiere/model/MOrder.java +++ b/org.adempiere.base/src/org/compiere/model/MOrder.java @@ -2326,7 +2326,7 @@ public class MOrder extends X_C_Order implements DocAction return null; // Business Partner needs to be linked to Org MBPartner bp = new MBPartner (getCtx(), getC_BPartner_ID(), get_TrxName()); - int counterAD_Org_ID = bp.getAD_OrgBP_ID_Int(); + int counterAD_Org_ID = bp.getAD_OrgBP_ID(); if (counterAD_Org_ID == 0) return null; diff --git a/org.adempiere.base/src/org/compiere/model/MPayment.java b/org.adempiere.base/src/org/compiere/model/MPayment.java index 4f1422a260..a1af3d15d6 100644 --- a/org.adempiere.base/src/org/compiere/model/MPayment.java +++ b/org.adempiere.base/src/org/compiere/model/MPayment.java @@ -2171,7 +2171,7 @@ public class MPayment extends X_C_Payment return null; // Business Partner needs to be linked to Org MBPartner bp = new MBPartner (getCtx(), getC_BPartner_ID(), get_TrxName()); - int counterAD_Org_ID = bp.getAD_OrgBP_ID_Int(); + int counterAD_Org_ID = bp.getAD_OrgBP_ID(); if (counterAD_Org_ID == 0) return null; diff --git a/org.adempiere.base/src/org/compiere/model/MProject.java b/org.adempiere.base/src/org/compiere/model/MProject.java index cd9af41767..edff0d8438 100644 --- a/org.adempiere.base/src/org/compiere/model/MProject.java +++ b/org.adempiere.base/src/org/compiere/model/MProject.java @@ -127,36 +127,13 @@ public class MProject extends X_C_Project /** * Get Project Type as Int (is Button). * @return C_ProjectType_ID id + * @deprecated */ public int getC_ProjectType_ID_Int() { - String pj = super.getC_ProjectType_ID(); - if (pj == null) - return 0; - int C_ProjectType_ID = 0; - try - { - C_ProjectType_ID = Integer.parseInt (pj); - } - catch (Exception ex) - { - log.log(Level.SEVERE, pj, ex); - } - return C_ProjectType_ID; + return getC_ProjectType_ID(); } // getC_ProjectType_ID_Int - /** - * Set Project Type (overwrite r/o) - * @param C_ProjectType_ID id - */ - public void setC_ProjectType_ID (int C_ProjectType_ID) - { - if (C_ProjectType_ID == 0) - super.setC_ProjectType_ID (null); - else - super.set_Value("C_ProjectType_ID", C_ProjectType_ID); - } // setC_ProjectType_ID - /** * String Representation * @return info diff --git a/org.adempiere.base/src/org/compiere/model/MRMA.java b/org.adempiere.base/src/org/compiere/model/MRMA.java index 93ca4ec366..36cfabbaff 100644 --- a/org.adempiere.base/src/org/compiere/model/MRMA.java +++ b/org.adempiere.base/src/org/compiere/model/MRMA.java @@ -505,7 +505,7 @@ public class MRMA extends X_M_RMA implements DocAction return null; // Business Partner needs to be linked to Org MBPartner bp = new MBPartner (getCtx(), getC_BPartner_ID(), get_TrxName()); - int counterAD_Org_ID = bp.getAD_OrgBP_ID_Int(); + int counterAD_Org_ID = bp.getAD_OrgBP_ID(); if (counterAD_Org_ID == 0) return null; diff --git a/org.adempiere.base/src/org/compiere/model/POInfoColumn.java b/org.adempiere.base/src/org/compiere/model/POInfoColumn.java index 7b111ebce7..7123c132a5 100644 --- a/org.adempiere.base/src/org/compiere/model/POInfoColumn.java +++ b/org.adempiere.base/src/org/compiere/model/POInfoColumn.java @@ -87,6 +87,10 @@ public class POInfoColumn implements Serializable DisplayType = org.compiere.util.DisplayType.ID; ColumnClass = Integer.class; } + else if (displayType == org.compiere.util.DisplayType.Button && columnName.endsWith("_ID")) + { + ColumnClass = Integer.class; + } else ColumnClass = org.compiere.util.DisplayType.getClass(displayType, true); IsMandatory = isMandatory; diff --git a/org.adempiere.base/src/org/compiere/model/X_C_BPartner.java b/org.adempiere.base/src/org/compiere/model/X_C_BPartner.java index 512d90cecf..533d12c3be 100644 --- a/org.adempiere.base/src/org/compiere/model/X_C_BPartner.java +++ b/org.adempiere.base/src/org/compiere/model/X_C_BPartner.java @@ -33,7 +33,7 @@ public class X_C_BPartner extends PO implements I_C_BPartner, I_Persistent /** * */ - private static final long serialVersionUID = 20191121L; + private static final long serialVersionUID = 20200327L; /** Standard Constructor */ public X_C_BPartner (Properties ctx, int C_BPartner_ID, String trxName) @@ -86,8 +86,8 @@ public class X_C_BPartner extends PO implements I_C_BPartner, I_Persistent public String toString() { - StringBuffer sb = new StringBuffer ("X_C_BPartner[") - .append(get_ID()).append("]"); + StringBuilder sb = new StringBuilder ("X_C_BPartner[") + .append(get_ID()).append(",Name=").append(getName()).append("]"); return sb.toString(); } @@ -155,17 +155,23 @@ public class X_C_BPartner extends PO implements I_C_BPartner, I_Persistent @param AD_OrgBP_ID The Business Partner is another Organization for explicit Inter-Org transactions */ - public void setAD_OrgBP_ID (String AD_OrgBP_ID) + public void setAD_OrgBP_ID (int AD_OrgBP_ID) { - set_Value (COLUMNNAME_AD_OrgBP_ID, AD_OrgBP_ID); + if (AD_OrgBP_ID < 1) + set_Value (COLUMNNAME_AD_OrgBP_ID, null); + else + set_Value (COLUMNNAME_AD_OrgBP_ID, Integer.valueOf(AD_OrgBP_ID)); } /** Get Linked Organization. @return The Business Partner is another Organization for explicit Inter-Org transactions */ - public String getAD_OrgBP_ID () + public int getAD_OrgBP_ID () { - return (String)get_Value(COLUMNNAME_AD_OrgBP_ID); + Integer ii = (Integer)get_Value(COLUMNNAME_AD_OrgBP_ID); + if (ii == null) + return 0; + return ii.intValue(); } /** Set Partner Parent. diff --git a/org.adempiere.base/src/org/compiere/model/X_C_Project.java b/org.adempiere.base/src/org/compiere/model/X_C_Project.java index 8909e8eaa1..df2f04983f 100644 --- a/org.adempiere.base/src/org/compiere/model/X_C_Project.java +++ b/org.adempiere.base/src/org/compiere/model/X_C_Project.java @@ -33,7 +33,7 @@ public class X_C_Project extends PO implements I_C_Project, I_Persistent /** * */ - private static final long serialVersionUID = 20191121L; + private static final long serialVersionUID = 20200327L; /** Standard Constructor */ public X_C_Project (Properties ctx, int C_Project_ID, String trxName) @@ -451,17 +451,23 @@ public class X_C_Project extends PO implements I_C_Project, I_Persistent @param C_ProjectType_ID Type of the project */ - public void setC_ProjectType_ID (String C_ProjectType_ID) + public void setC_ProjectType_ID (int C_ProjectType_ID) { - set_Value (COLUMNNAME_C_ProjectType_ID, C_ProjectType_ID); + if (C_ProjectType_ID < 1) + set_Value (COLUMNNAME_C_ProjectType_ID, null); + else + set_Value (COLUMNNAME_C_ProjectType_ID, Integer.valueOf(C_ProjectType_ID)); } /** Get Project Type. @return Type of the project */ - public String getC_ProjectType_ID () + public int getC_ProjectType_ID () { - return (String)get_Value(COLUMNNAME_C_ProjectType_ID); + Integer ii = (Integer)get_Value(COLUMNNAME_C_ProjectType_ID); + if (ii == null) + return 0; + return ii.intValue(); } /** Set C_Project_UU.