IDEMPIERE-1099 - Process/Form Generate Charges should include account key in charge name

This commit is contained in:
dantam 2014-09-05 16:30:05 +02:00
parent c607a29f31
commit d67d3efc73
1 changed files with 22 additions and 18 deletions

View File

@ -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(),