From 267fe358df58539317b2d68a9b3292ade90720d3 Mon Sep 17 00:00:00 2001 From: Carlos Ruiz Date: Wed, 8 Apr 2015 10:15:57 -0500 Subject: [PATCH] IDEMPIERE-2565 - found transaction not rolled back when initial client setup was failing with an exception --- .../adempiere/process/InitialClientSetup.java | 54 ++++++++++--------- .../src/org/compiere/model/MLocation.java | 2 +- 2 files changed, 30 insertions(+), 26 deletions(-) diff --git a/org.adempiere.base.process/src/org/adempiere/process/InitialClientSetup.java b/org.adempiere.base.process/src/org/adempiere/process/InitialClientSetup.java index 9b9f791358..66741cf624 100644 --- a/org.adempiere.base.process/src/org/adempiere/process/InitialClientSetup.java +++ b/org.adempiere.base.process/src/org/adempiere/process/InitialClientSetup.java @@ -257,34 +257,38 @@ public class InitialClientSetup extends SvrProcess // Process MSetup ms = new MSetup(Env.getCtx(), WINDOW_THIS_PROCESS); + try { + if (! ms.createClient(p_ClientName, p_OrgValue, p_OrgName, p_AdminUserName, p_NormalUserName + , p_Phone, p_Phone2, p_Fax, p_EMail, p_TaxID, p_AdminUserEmail, p_NormalUserEmail)) { + ms.rollback(); + throw new AdempiereException("Create client failed"); + } + + addLog(ms.getInfo()); - if (! ms.createClient(p_ClientName, p_OrgValue, p_OrgName, p_AdminUserName, p_NormalUserName - , p_Phone, p_Phone2, p_Fax, p_EMail, p_TaxID, p_AdminUserEmail, p_NormalUserEmail)) { + // Generate Accounting + MCurrency currency = MCurrency.get(getCtx(), p_C_Currency_ID); + KeyNamePair currency_kp = new KeyNamePair(p_C_Currency_ID, currency.getDescription()); + if (!ms.createAccounting(currency_kp, + p_IsUseProductDimension, p_IsUseBPDimension, p_IsUseProjectDimension, p_IsUseCampaignDimension, p_IsUseSalesRegionDimension, p_IsUseActivityDimension, + coaFile, p_UseDefaultCoA, p_InactivateDefaults)) { + ms.rollback(); + throw new AdempiereException("@AccountSetupError@"); + } + + // Generate Entities + if (!ms.createEntities(p_C_Country_ID, p_CityName, p_C_Region_ID, p_C_Currency_ID, p_Postal, p_Address1)) { + ms.rollback(); + throw new AdempiereException("@AccountSetupError@"); + } + addLog(ms.getInfo()); + + // Create Print Documents + PrintUtil.setupPrintForm(ms.getAD_Client_ID()); + } catch (Exception e) { ms.rollback(); - throw new AdempiereException("Create client failed"); + throw e; } - - addLog(ms.getInfo()); - - // Generate Accounting - MCurrency currency = MCurrency.get(getCtx(), p_C_Currency_ID); - KeyNamePair currency_kp = new KeyNamePair(p_C_Currency_ID, currency.getDescription()); - if (!ms.createAccounting(currency_kp, - p_IsUseProductDimension, p_IsUseBPDimension, p_IsUseProjectDimension, p_IsUseCampaignDimension, p_IsUseSalesRegionDimension, p_IsUseActivityDimension, - coaFile, p_UseDefaultCoA, p_InactivateDefaults)) { - ms.rollback(); - throw new AdempiereException("@AccountSetupError@"); - } - - // Generate Entities - if (!ms.createEntities(p_C_Country_ID, p_CityName, p_C_Region_ID, p_C_Currency_ID, p_Postal, p_Address1)) { - ms.rollback(); - throw new AdempiereException("@AccountSetupError@"); - } - addLog(ms.getInfo()); - - // Create Print Documents - PrintUtil.setupPrintForm(ms.getAD_Client_ID()); return "@OK@"; } diff --git a/org.adempiere.base/src/org/compiere/model/MLocation.java b/org.adempiere.base/src/org/compiere/model/MLocation.java index fdfba19127..f24c2c1bae 100644 --- a/org.adempiere.base/src/org/compiere/model/MLocation.java +++ b/org.adempiere.base/src/org/compiere/model/MLocation.java @@ -465,7 +465,7 @@ public class MLocation extends X_C_Location implements Comparator if (c == null) return "CountryNotFound"; - boolean local = getC_Country_ID() == MCountry.getDefault(getCtx()).getC_Country_ID(); + boolean local = MCountry.getDefault(getCtx()) != null && getC_Country_ID() == MCountry.getDefault(getCtx()).getC_Country_ID(); String inStr = local ? c.getDisplaySequenceLocal() : c.getDisplaySequence(); StringBuilder outStr = new StringBuilder();