From d67d3efc7366c705fee8266de217b577d0721db2 Mon Sep 17 00:00:00 2001 From: dantam Date: Fri, 5 Sep 2014 16:30:05 +0200 Subject: [PATCH] IDEMPIERE-1099 - Process/Form Generate Charges should include account key in charge name --- .../src/org/compiere/apps/form/Charge.java | 40 ++++++++++--------- 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/org.adempiere.ui/src/org/compiere/apps/form/Charge.java b/org.adempiere.ui/src/org/compiere/apps/form/Charge.java index f035cf204d..3e0d686df5 100644 --- a/org.adempiere.ui/src/org/compiere/apps/form/Charge.java +++ b/org.adempiere.ui/src/org/compiere/apps/form/Charge.java @@ -16,9 +16,12 @@ package org.compiere.apps.form; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; +import java.util.Properties; import java.util.Vector; import java.util.logging.Level; +import javax.security.auth.login.AccountException; + import org.compiere.minigrid.IMiniTable; import org.compiere.model.MAccount; import org.compiere.model.MAcctSchema; @@ -232,29 +235,30 @@ public class Charge MCharge charge; MAccount account; - if (log.isLoggable(Level.CONFIG)) log.config(name + " - "); - // Charge - charge = new MCharge(Env.getCtx(), 0, null); - charge.setName(name); - charge.setC_TaxCategory_ID(m_C_TaxCategory_ID); - if (!charge.save()) - { - log.log(Level.SEVERE, name + " not created"); - return 0; - } - refreshAccountSchema(); if (!isAccountSchemaValid()) { return 0; } - + // Target Account - account = getAccount(elementValueId, charge); + account = getAccount(elementValueId); if (account == null) { return 0; } + + if (log.isLoggable(Level.CONFIG)) log.config(name + " - "); + // Charge + charge = new MCharge(Env.getCtx(), 0, null); + // IDEMPIERE-1099 - Key must be included in name to avoid name crashes in account schema. + charge.setName(account.getAccount().getValue() + " " + name); + charge.setC_TaxCategory_ID(m_C_TaxCategory_ID); + if (!charge.save()) + { + log.log(Level.SEVERE, name + " not created"); + return 0; + } updateAccount(charge, account); @@ -338,15 +342,15 @@ public class Charge * Gets the account for the specified charge and element value. * The account is created if it doesn't already exist. * @param elementValueId identifier for the element value - * @param charge charge * @return the account */ - private MAccount getAccount(int elementValueId, MCharge charge) + private MAccount getAccount(int elementValueId) { + Properties ctx = Env.getCtx(); MAccount defaultAccount = MAccount.getDefault(m_acctSchema, true); // optional null - MAccount account = MAccount.get(Env.getCtx(), - charge.getAD_Client_ID(), - charge.getAD_Org_ID(), + MAccount account = MAccount.get(ctx, + Env.getAD_Client_ID(ctx), + Env.getAD_Org_ID(ctx), m_acctSchema.getC_AcctSchema_ID(), elementValueId, defaultAccount.getC_SubAcct_ID(),