hg merge release-6.2 (merge release6.2 into default)

This commit is contained in:
Carlos Ruiz 2019-10-22 14:20:48 +02:00
commit 34b0609f1a
2 changed files with 17 additions and 25 deletions

View File

@ -20,6 +20,7 @@ import java.math.BigDecimal;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.Map;
import java.util.logging.Level; import java.util.logging.Level;
import org.compiere.model.MAccount; import org.compiere.model.MAccount;
@ -335,20 +336,8 @@ public final class Fact
*/ */
public boolean isSegmentBalanced() public boolean isSegmentBalanced()
{ {
//AZ Goodwill
// Multi-Currency documents are source balanced by definition
// No lines -> balanced // No lines -> balanced
if (m_lines.size() == 0 || m_doc.isMultiCurrency()) if (m_lines.size() == 0)
return true;
// If there is more than 1 currency in fact lines, it is a multi currency doc
ArrayList<Integer> list = new ArrayList<Integer>();
for (int i = 0; i < m_lines.size(); i++){
FactLine line = (FactLine)m_lines.get(i);
if (line.getC_Currency_ID() > 0 && !list.contains(line.getC_Currency_ID()))
list.add(line.getC_Currency_ID());
}
if (list.size() > 1 )
return true; return true;
MAcctSchemaElement[] elements = m_acctSchema.getAcctSchemaElements(); MAcctSchemaElement[] elements = m_acctSchema.getAcctSchemaElements();
@ -374,7 +363,7 @@ public final class Fact
if (segmentType.equals(MAcctSchemaElement.ELEMENTTYPE_Organization)) if (segmentType.equals(MAcctSchemaElement.ELEMENTTYPE_Organization))
{ {
HashMap<Integer,BigDecimal> map = new HashMap<Integer,BigDecimal>(); HashMap<Integer,BigDecimal> map = new HashMap<Integer,BigDecimal>();
// Add up values by key // Add up values by organization
for (int i = 0; i < m_lines.size(); i++) for (int i = 0; i < m_lines.size(); i++)
{ {
FactLine line = (FactLine)m_lines.get(i); FactLine line = (FactLine)m_lines.get(i);
@ -384,21 +373,24 @@ public final class Fact
if (oldBal != null) if (oldBal != null)
bal = bal.add(oldBal); bal = bal.add(oldBal);
map.put(key, bal); map.put(key, bal);
// System.out.println("Add Key=" + key + ", Bal=" + bal + " <- " + line);
} }
// check if all keys are zero
Iterator<BigDecimal> values = map.values().iterator(); // check if there are not balance entries involving multiple organizations
while (values.hasNext()) Map<Integer, BigDecimal> notBalance = new HashMap<>();
for(Map.Entry<Integer, BigDecimal> entry : map.entrySet())
{ {
BigDecimal bal = values.next(); BigDecimal bal = entry.getValue();
if (bal.signum() != 0) if (bal.signum() != 0)
{ {
map.clear(); notBalance.put(entry.getKey(), entry.getValue());
log.warning ("(" + segmentType + ") NO - " + toString() + ", Balance=" + bal); }
}
if (notBalance.size() > 1)
{
return false; return false;
} }
}
map.clear();
if (log.isLoggable(Level.FINER)) log.finer("(" + segmentType + ") - " + toString()); if (log.isLoggable(Level.FINER)) log.finer("(" + segmentType + ") - " + toString());
return true; return true;
} }

View File

@ -56,7 +56,7 @@ public class MRegion extends X_C_Region
*/ */
private static void loadAllRegions (Properties ctx) private static void loadAllRegions (Properties ctx)
{ {
s_regions = new CCache<String,MRegion>(Table_Name, 100); s_regions.clear();
String sql = "SELECT * FROM C_Region WHERE IsActive='Y'"; String sql = "SELECT * FROM C_Region WHERE IsActive='Y'";
Statement stmt = null; Statement stmt = null;
ResultSet rs = null; ResultSet rs = null;
@ -161,7 +161,7 @@ public class MRegion extends X_C_Region
} // getRegions } // getRegions
/** Region Cache */ /** Region Cache */
private static CCache<String,MRegion> s_regions = null; private static CCache<String,MRegion> s_regions = new CCache<String,MRegion>(Table_Name, Table_Name, 100, 0, false, 0);
/** Default Region */ /** Default Region */
private static MRegion s_default = null; private static MRegion s_default = null;
/** Static Logger */ /** Static Logger */