Fix [ 1938912 ] Problem detected with clearing account and interorg posting

https://sourceforge.net/tracker/?func=detail&atid=879332&aid=1938912&group_id=176962
This commit is contained in:
Carlos Ruiz 2008-04-10 01:08:02 +00:00
parent 82a7e72261
commit d52ef4b32e
3 changed files with 110 additions and 4 deletions

View File

@ -24,6 +24,7 @@ import java.util.logging.Level;
import org.compiere.model.MAccount; import org.compiere.model.MAccount;
import org.compiere.model.MAcctSchema; import org.compiere.model.MAcctSchema;
import org.compiere.model.MAcctSchemaElement;
import org.compiere.model.MAllocationHdr; import org.compiere.model.MAllocationHdr;
import org.compiere.model.MAllocationLine; import org.compiere.model.MAllocationLine;
import org.compiere.model.MCashLine; import org.compiere.model.MCashLine;
@ -31,6 +32,7 @@ import org.compiere.model.MConversionRate;
import org.compiere.model.MFactAcct; import org.compiere.model.MFactAcct;
import org.compiere.model.MInvoice; import org.compiere.model.MInvoice;
import org.compiere.model.MInvoiceLine; import org.compiere.model.MInvoiceLine;
import org.compiere.model.MOrder;
import org.compiere.model.MPayment; import org.compiere.model.MPayment;
import org.compiere.util.CLogger; import org.compiere.util.CLogger;
import org.compiere.util.DB; import org.compiere.util.DB;
@ -173,6 +175,7 @@ public class Doc_Allocation extends Doc
// create Fact Header // create Fact Header
Fact fact = new Fact(this, as, Fact.POST_Actual); Fact fact = new Fact(this, as, Fact.POST_Actual);
Fact factForRGL = new Fact(this, as, Fact.POST_Actual); // dummy fact (not posted) to calculate Realized Gain & Loss Fact factForRGL = new Fact(this, as, Fact.POST_Actual); // dummy fact (not posted) to calculate Realized Gain & Loss
boolean isInterOrg = isInterOrg(as);
for (int i = 0; i < p_lines.length; i++) for (int i = 0; i < p_lines.length; i++)
{ {
@ -239,7 +242,7 @@ public class Doc_Allocation extends Doc
acct_unallocated_cash = getCashAcct(as, line.getC_CashLine_ID()); acct_unallocated_cash = getCashAcct(as, line.getC_CashLine_ID());
MAccount acct_receivable = getAccount(Doc.ACCTTYPE_C_Receivable, as); MAccount acct_receivable = getAccount(Doc.ACCTTYPE_C_Receivable, as);
if ((!as.isPostIfClearingEqual()) && acct_unallocated_cash != null && acct_unallocated_cash.equals(acct_receivable)) { if ((!as.isPostIfClearingEqual()) && acct_unallocated_cash != null && acct_unallocated_cash.equals(acct_receivable) && (!isInterOrg)) {
// if not using clearing accounts, then don't post amtsource // if not using clearing accounts, then don't post amtsource
// change the allocationsource to be writeoff + discount // change the allocationsource to be writeoff + discount
@ -329,7 +332,7 @@ public class Doc_Allocation extends Doc
// Save original allocation source for realized gain & loss purposes // Save original allocation source for realized gain & loss purposes
allocationSourceForRGL = allocationSourceForRGL.negate(); allocationSourceForRGL = allocationSourceForRGL.negate();
if ((!as.isPostIfClearingEqual()) && acct_payment_select != null && acct_payment_select.equals(acct_liability)) { if ((!as.isPostIfClearingEqual()) && acct_payment_select != null && acct_payment_select.equals(acct_liability) && (!isInterOrg)) {
// if not using clearing accounts, then don't post amtsource // if not using clearing accounts, then don't post amtsource
// change the allocationsource to be writeoff + discount // change the allocationsource to be writeoff + discount
@ -433,7 +436,7 @@ public class Doc_Allocation extends Doc
} // for all lines } // for all lines
// FR [ 1840016 ] Avoid usage of clearing accounts - subject to C_AcctSchema.IsPostIfClearingEqual // FR [ 1840016 ] Avoid usage of clearing accounts - subject to C_AcctSchema.IsPostIfClearingEqual
if ( ( ! as.isPostIfClearingEqual() ) && p_lines.length > 0) { if ( (!as.isPostIfClearingEqual()) && p_lines.length > 0 && (!isInterOrg)) {
boolean allEquals = true; boolean allEquals = true;
// more than one line (i.e. crossing one payment+ with a payment-, or an invoice against a credit memo) // more than one line (i.e. crossing one payment+ with a payment-, or an invoice against a credit memo)
// verify if the sum of all facts is zero net // verify if the sum of all facts is zero net
@ -464,6 +467,61 @@ public class Doc_Allocation extends Doc
return m_facts; return m_facts;
} // createFact } // createFact
/** Verify if the posting involves two or more organizations
@return true if there are more than one org involved on the posting
*/
private boolean isInterOrg(MAcctSchema as) {
MAcctSchemaElement elementorg = as.getAcctSchemaElement(MAcctSchemaElement.ELEMENTTYPE_Organization);
if (elementorg == null || !elementorg.isBalanced()) {
// no org element or not need to be balanced
return false;
}
if (p_lines.length <= 0) {
// no lines
return false;
}
int startorg = p_lines[0].getAD_Org_ID();
// validate if the allocation involves more than one org
for (int i = 0; i < p_lines.length; i++) {
DocLine_Allocation line = (DocLine_Allocation)p_lines[i];
int orgpayment = startorg;
MPayment payment = null;
if (line.getC_Payment_ID() != 0) {
payment = new MPayment (getCtx(), line.getC_Payment_ID(), getTrxName());
orgpayment = payment.getAD_Org_ID();
}
int orginvoice = startorg;
MInvoice invoice = null;
if (line.getC_Invoice_ID() != 0) {
invoice = new MInvoice (getCtx(), line.getC_Invoice_ID(), getTrxName());
orginvoice = invoice.getAD_Org_ID();
}
int orgcashline = startorg;
MCashLine cashline = null;
if (line.getC_CashLine_ID() != 0) {
cashline = new MCashLine (getCtx(), line.getC_CashLine_ID(), getTrxName());
orgcashline = cashline.getAD_Org_ID();
}
int orgorder = startorg;
MOrder order = null;
if (line.getC_Order_ID() != 0) {
order = new MOrder (getCtx(), line.getC_Order_ID(), getTrxName());
orgorder = order.getAD_Org_ID();
}
if ( line.getAD_Org_ID() != startorg
|| orgpayment != startorg
|| orginvoice != startorg
|| orgcashline != startorg
|| orgorder != startorg)
return true;
}
return false;
}
/** /**
* Compare the dimension ID's from two factlines * Compare the dimension ID's from two factlines
* @param allEquals * @param allEquals

View File

@ -151,6 +151,7 @@ public class Doc_Bank extends Doc
{ {
// create Fact Header // create Fact Header
Fact fact = new Fact(this, as, Fact.POST_Actual); Fact fact = new Fact(this, as, Fact.POST_Actual);
// boolean isInterOrg = isInterOrg(as);
// Header -- there may be different currency amounts // Header -- there may be different currency amounts
@ -169,6 +170,8 @@ public class Doc_Bank extends Doc
MAccount acct_bank_asset = getAccount(Doc.ACCTTYPE_BankAsset, as); MAccount acct_bank_asset = getAccount(Doc.ACCTTYPE_BankAsset, as);
MAccount acct_bank_in_transit = getAccount(Doc.ACCTTYPE_BankInTransit, as); MAccount acct_bank_in_transit = getAccount(Doc.ACCTTYPE_BankInTransit, as);
// if ((!as.isPostIfClearingEqual()) && acct_bank_asset.equals(acct_bank_in_transit) && (!isInterOrg)) {
// don't validate interorg on banks for this - normally banks are balanced by orgs
if ((!as.isPostIfClearingEqual()) && acct_bank_asset.equals(acct_bank_in_transit)) { if ((!as.isPostIfClearingEqual()) && acct_bank_asset.equals(acct_bank_in_transit)) {
// Not using clearing accounts // Not using clearing accounts
// just post the difference (if any) // just post the difference (if any)
@ -250,6 +253,33 @@ public class Doc_Bank extends Doc
return facts; return facts;
} // createFact } // createFact
/** Verify if the posting involves two or more organizations
@return true if there are more than one org involved on the posting
private boolean isInterOrg(MAcctSchema as) {
MAcctSchemaElement elementorg = as.getAcctSchemaElement(MAcctSchemaElement.ELEMENTTYPE_Organization);
if (elementorg == null || !elementorg.isBalanced()) {
// no org element or not need to be balanced
return false;
}
if (p_lines.length <= 0) {
// no lines
return false;
}
int startorg = getBank_Org_ID();
if (startorg == 0)
startorg = p_lines[0].getAD_Org_ID();
// validate if the allocation involves more than one org
for (int i = 0; i < p_lines.length; i++) {
if (p_lines[i].getAD_Org_ID() != startorg)
return true;
}
return false;
}
*/
/** /**
* Get AD_Org_ID from Bank Account * Get AD_Org_ID from Bank Account
* @return AD_Org_ID or 0 * @return AD_Org_ID or 0

View File

@ -129,6 +129,7 @@ public class Doc_MatchInv extends Doc
// create Fact Header // create Fact Header
Fact fact = new Fact(this, as, Fact.POST_Actual); Fact fact = new Fact(this, as, Fact.POST_Actual);
setC_Currency_ID (as.getC_Currency_ID()); setC_Currency_ID (as.getC_Currency_ID());
boolean isInterOrg = isInterOrg(as);
/** Needs to be handeled in PO Matching as no Receipt info /** Needs to be handeled in PO Matching as no Receipt info
if (m_pc.isService()) if (m_pc.isService())
@ -232,7 +233,7 @@ public class Doc_MatchInv extends Doc
MAccount acct_db = dr.getAccount(); // not_invoiced_receipts MAccount acct_db = dr.getAccount(); // not_invoiced_receipts
MAccount acct_cr = cr.getAccount(); // inventory_clearing MAccount acct_cr = cr.getAccount(); // inventory_clearing
if ((!as.isPostIfClearingEqual()) && acct_db.equals(acct_cr)) { if ((!as.isPostIfClearingEqual()) && acct_db.equals(acct_cr) && (!isInterOrg)) {
BigDecimal debit = dr.getAmtSourceDr(); BigDecimal debit = dr.getAmtSourceDr();
BigDecimal credit = cr.getAmtSourceCr(); BigDecimal credit = cr.getAmtSourceCr();
@ -328,6 +329,23 @@ public class Doc_MatchInv extends Doc
return facts; return facts;
} // createFact } // createFact
/** Verify if the posting involves two or more organizations
@return true if there are more than one org involved on the posting
*/
private boolean isInterOrg(MAcctSchema as) {
MAcctSchemaElement elementorg = as.getAcctSchemaElement(MAcctSchemaElement.ELEMENTTYPE_Organization);
if (elementorg == null || !elementorg.isBalanced()) {
// no org element or not need to be balanced
return false;
}
// verify if org of receipt line is different from org of invoice line
if (m_receiptLine != null && m_invoiceLine != null && m_receiptLine.getAD_Org_ID() != m_invoiceLine.getAD_Org_ID())
return true;
return false;
}
/** /**
* Update Product Info (old). * Update Product Info (old).
* - Costing (CostStandardCumQty, CostStandardCumAmt, CostAverageCumQty, CostAverageCumAmt) * - Costing (CostStandardCumQty, CostStandardCumAmt, CostAverageCumQty, CostAverageCumAmt)