diff --git a/migration/iD10/oracle/202210111536_IDEMPIERE-5447.sql b/migration/iD10/oracle/202210111536_IDEMPIERE-5447.sql new file mode 100644 index 0000000000..bdc7444344 --- /dev/null +++ b/migration/iD10/oracle/202210111536_IDEMPIERE-5447.sql @@ -0,0 +1,10 @@ +-- IDEMPIERE-5447 Add unit test for Merge form +SELECT register_migration_script('202210111536_IDEMPIERE-5447.sql') FROM dual; + +SET SQLBLANKLINES ON +SET DEFINE OFF + +-- Oct 11, 2022, 3:36:36 PM CEST +UPDATE AD_Menu SET PredefinedContextVariables='IgnoreIsSOTrxInBPInfo=Y',Updated=TO_TIMESTAMP('2022-10-11 15:36:36','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Menu_ID=397 +; + diff --git a/migration/iD10/postgresql/202210111536_IDEMPIERE-5447.sql b/migration/iD10/postgresql/202210111536_IDEMPIERE-5447.sql new file mode 100644 index 0000000000..8ad357683b --- /dev/null +++ b/migration/iD10/postgresql/202210111536_IDEMPIERE-5447.sql @@ -0,0 +1,7 @@ +-- IDEMPIERE-5447 Add unit test for Merge form +SELECT register_migration_script('202210111536_IDEMPIERE-5447.sql') FROM dual; + +-- Oct 11, 2022, 3:36:36 PM CEST +UPDATE AD_Menu SET PredefinedContextVariables='IgnoreIsSOTrxInBPInfo=Y',Updated=TO_TIMESTAMP('2022-10-11 15:36:36','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Menu_ID=397 +; + diff --git a/org.adempiere.base/src/org/compiere/model/MBPartner.java b/org.adempiere.base/src/org/compiere/model/MBPartner.java index dca783c33c..0c32503acd 100644 --- a/org.adempiere.base/src/org/compiere/model/MBPartner.java +++ b/org.adempiere.base/src/org/compiere/model/MBPartner.java @@ -625,7 +625,7 @@ public class MBPartner extends X_C_BPartner implements ImmutablePOSupport } // getAD_OrgBP_ID_Int /** - * Get Primary C_BPartner_Location_ID + * Get Primary C_BPartner_Location_ID (BillTo or First) * @return C_BPartner_Location_ID */ public int getPrimaryC_BPartner_Location_ID() @@ -651,7 +651,7 @@ public class MBPartner extends X_C_BPartner implements ImmutablePOSupport } // getPrimaryC_BPartner_Location_ID /** - * Get Primary C_BPartner_Location + * Get Primary C_BPartner_Location (BillTo or First) * @return C_BPartner_Location */ public MBPartnerLocation getPrimaryC_BPartner_Location() diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/form/WMerge.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/form/WMerge.java index aa7be86680..ba9c30dfac 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/form/WMerge.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/form/WMerge.java @@ -235,8 +235,9 @@ public class WMerge extends Merge implements IFormController, EventListener 0) + pp1.deleteEx(true); + if (pp2 != null && pp2.get_ID() > 0) + pp2.deleteEx(true); + if (ol1 != null && ol1.get_ID() > 0) + ol1.deleteEx(true); + if (ol2 != null && ol2.get_ID() > 0) + ol2.deleteEx(true); + if (order1 != null && order1.get_ID() > 0) + order1.deleteEx(true); + if (order2 != null && order2.get_ID() > 0) + order2.deleteEx(true); + if (p1 != null && p1.get_ID() > 0) + p1.deleteEx(true); + if (p2 != null && p2.get_ID() > 0) + p2.deleteEx(true); + } + } + + @Test + public void testMergeBPartner() { + MBPartner bp1 = null; + MBPartner bp2 = null; + MOrder o1 = null; + MOrder o2 = null; + try { + MBPartner jb = MBPartner.get(Env.getCtx(), DictionaryIDs.C_BPartner.JOE_BLOCK.id); + MBPartnerLocation bpl = jb.getPrimaryC_BPartner_Location(); + MLocation loc = new MLocation(Env.getCtx(), bpl.getC_Location_ID(), null); + + bp1 = new MBPartner(Env.getCtx(), 0, null); + bp1.setName("testMergeBPartner1"); + bp1.setIsCustomer(true); + bp1.setC_BP_Group_ID(jb.getC_BP_Group_ID()); + bp1.saveEx(); + MLocation loc1 = new MLocation(Env.getCtx(), 0, null); + PO.copyValues(loc, loc1); + loc1.saveEx(); + MBPartnerLocation bpl1 = new MBPartnerLocation(bp1); + bpl1.setC_Location_ID(loc1.get_ID()); + bpl1.setIsShipTo(true); + bpl1.setIsBillTo(true); + bpl1.saveEx(); + + bp2 = new MBPartner(Env.getCtx(), 0, null); + bp2.setName("testMergeBPartner2"); + bp2.setIsCustomer(true); + bp2.setC_BP_Group_ID(bp1.getC_BP_Group_ID()); + bp2.saveEx(); + MLocation loc2 = new MLocation(Env.getCtx(), 0, null); + PO.copyValues(loc, loc2); + loc2.saveEx(); + MBPartnerLocation bpl2 = new MBPartnerLocation(bp2); + bpl2.setC_Location_ID(loc2.get_ID()); + bpl2.setIsShipTo(true); + bpl2.setIsBillTo(true); + bpl2.saveEx(); + + o1 = new MOrder(Env.getCtx(), 0, null); + o1.setIsSOTrx(true); + o1.setC_DocTypeTarget_ID(); + o1.setBPartner(bp1); + o1.saveEx(); + + o2 = new MOrder(Env.getCtx(), 0, null); + o2.setIsSOTrx(true); + o2.setC_DocTypeTarget_ID(); + o2.setBPartner(bp2); + o2.saveEx(); + + Merge merge = new Merge(); + boolean ok = merge.merge(Merge.C_BPARTNER_ID, bp1.get_ID(), bp2.get_ID()); + assertTrue(ok, "Merge fail"); + o1.load(null); + assertEquals(bp2.get_ID(), o1.getC_BPartner_ID(), "Unexpected order line C_BPartner_ID after merge"); + o2.load(null); + assertEquals(bp2.get_ID(), o2.getC_BPartner_ID(), "Unexpected order line C_BPartner_ID after merge"); + bp1.load(null); + assertEquals(0, bp1.get_ID(), "BPartner not deleted after merge"); + } finally { + if (o1 != null && o1.get_ID() > 0) + o1.deleteEx(true); + if (o2 != null && o2.get_ID() > 0) + o2.deleteEx(true); + if (bp1 != null && bp1.get_ID() > 0) + bp1.deleteEx(true); + if (bp2 != null && bp2.get_ID() > 0) + bp2.deleteEx(true); + } + } + + @Test + public void testMergeUser() { + MUser u1 = null; + MUser u2 = null; + MUserDefWin udw = null; + + try { + u1 = new MUser(Env.getCtx(), 0, null); + u1.setName("testMergeUser1"); + u1.saveEx(); + + u2 = new MUser(Env.getCtx(), 0, null); + u2.setName("testMergeUser2"); + u2.saveEx(); + + udw = new MUserDefWin(Env.getCtx(), 0, null); + udw.setAD_User_ID(u1.get_ID()); + udw.setAD_Window_ID(SystemIDs.WINDOW_SALES_ORDER); + udw.saveEx(); + + Merge merge = new Merge(); + boolean ok = merge.merge(Merge.AD_USER_ID, u1.get_ID(), u2.get_ID()); + assertTrue(ok, "Merge fail"); + + u1.load(null); + assertEquals(0, u1.get_ID(), "User not deleted after merge"); + udw.load(null); + assertEquals(u2.get_ID(), udw.getAD_User_ID(), "Unexpected MUserDefWin.AD_User_ID after merge"); + } finally { + if (udw != null && udw.get_ID() > 0) + udw.deleteEx(true); + if (u1 != null && u1.get_ID() > 0) + u1.deleteEx(true); + if (u2 != null && u2.get_ID() > 0) + u2.deleteEx(true); + } + } +}