IDEMPIERE-4828-posting of Allocation with a AR Credit Memos with disc… (#745)

* IDEMPIERE-4828-posting of Allocation with a AR Credit Memos with discount, the tax-correction has the wrong sign

* IDEMPIERE-4828 - posting of Allocation with a AR Credit Memos with discount, the tax-correction has the wrong sign

check for DocBaseType
This commit is contained in:
Patric Massing 2021-07-05 21:02:44 +02:00 committed by GitHub
parent 93bc73c257
commit bb2bbc710c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 1488 additions and 33 deletions

View File

@ -32,6 +32,7 @@ import org.compiere.model.MAllocationHdr;
import org.compiere.model.MAllocationLine;
import org.compiere.model.MCashLine;
import org.compiere.model.MConversionRate;
import org.compiere.model.MDocType;
import org.compiere.model.MFactAcct;
import org.compiere.model.MInvoice;
import org.compiere.model.MInvoiceLine;
@ -1856,6 +1857,9 @@ class Doc_AllocationTax
return false;
}
Doc doc = DocManager.getDocument(as, MInvoice.Table_ID, factAcct.getRecord_ID(), line.getPO().get_TrxName());
MDocType dt = new MDocType(Env.getCtx(), (doc!=null)?doc.getC_DocType_ID():-1, line.getPO().get_TrxName());
String docBaseType=(dt.getC_DocType_ID()>0)?dt.getDocBaseType():"";
// Discount Amount
if (m_DiscountAmt.signum() != 0)
@ -1865,22 +1869,37 @@ class Doc_AllocationTax
{
BigDecimal amount = calcAmount(factAcct.getAmtSourceDr(),
total, m_DiscountAmt, precision);
if (amount.signum() != 0)
{
//for sales actions
if (m_IsSOTrx) {
fact.createLine (line, m_DiscountAccount,
as.getC_Currency_ID(), amount, null);
fact.createLine (line, taxAcct,
as.getC_Currency_ID(), null, amount);
if(docBaseType.equals(MDocType.DOCBASETYPE_ARCreditMemo)) {
fact.createLine (line, m_DiscountAccount,
as.getC_Currency_ID(), amount.negate(), null);
fact.createLine (line, taxAcct,
as.getC_Currency_ID(), null, amount.negate());
}else {
fact.createLine (line, m_DiscountAccount,
as.getC_Currency_ID(), amount, null);
fact.createLine (line, taxAcct,
as.getC_Currency_ID(), null, amount);
}
} else {
//for purchase actions
fact.createLine (line, m_DiscountAccount,
as.getC_Currency_ID(), amount.negate(), null);
fact.createLine (line, taxAcct,
as.getC_Currency_ID(), null, amount.negate());
if(docBaseType.equals(MDocType.DOCBASETYPE_APCreditMemo)) {
fact.createLine (line, m_DiscountAccount,
as.getC_Currency_ID(), amount, null);
fact.createLine (line, taxAcct,
as.getC_Currency_ID(), null, amount);
} else {
fact.createLine (line, m_DiscountAccount,
as.getC_Currency_ID(), amount.negate(), null);
fact.createLine (line, taxAcct,
as.getC_Currency_ID(), null, amount.negate());
}
}
}
}
// Original Tax is CR - need to correct it DR
@ -1892,15 +1911,33 @@ class Doc_AllocationTax
{
// for sales actions
if (m_IsSOTrx) {
fact.createLine (line, taxAcct,
as.getC_Currency_ID(), amount, null);
fact.createLine (line, m_DiscountAccount,
as.getC_Currency_ID(), null, amount);
if(docBaseType.equals(MDocType.DOCBASETYPE_ARCreditMemo)) {
fact.createLine (line, taxAcct,
as.getC_Currency_ID(), amount.negate(), null);
fact.createLine (line, m_DiscountAccount,
as.getC_Currency_ID(), null, amount.negate());
}else {
fact.createLine (line, taxAcct,
as.getC_Currency_ID(), amount, null);
fact.createLine (line, m_DiscountAccount,
as.getC_Currency_ID(), null, amount);
}
} else {
fact.createLine (line, taxAcct,
as.getC_Currency_ID(), amount.negate(), null);
fact.createLine (line, m_DiscountAccount,
as.getC_Currency_ID(), null, amount.negate());
if(docBaseType.equals(MDocType.DOCBASETYPE_APCreditMemo)) {
fact.createLine (line, taxAcct,
as.getC_Currency_ID(), amount, null);
fact.createLine (line, m_DiscountAccount,
as.getC_Currency_ID(), null, amount);
}else {
fact.createLine (line, taxAcct,
as.getC_Currency_ID(), amount.negate(), null);
fact.createLine (line, m_DiscountAccount,
as.getC_Currency_ID(), null, amount.negate());
}
}
}
}
@ -1917,15 +1954,29 @@ class Doc_AllocationTax
if (amount.signum() != 0)
{
if (m_IsSOTrx) {
fact.createLine (line, m_WriteOffAccount,
as.getC_Currency_ID(), amount, null);
fact.createLine (line, taxAcct,
as.getC_Currency_ID(), null, amount);
} else {
fact.createLine (line, m_WriteOffAccount,
if(docBaseType.equals(MDocType.DOCBASETYPE_ARCreditMemo)) {
fact.createLine (line, m_WriteOffAccount,
as.getC_Currency_ID(), amount.negate(), null);
fact.createLine (line, taxAcct,
fact.createLine (line, taxAcct,
as.getC_Currency_ID(), null, amount.negate());
} else {
fact.createLine (line, m_WriteOffAccount,
as.getC_Currency_ID(), amount, null);
fact.createLine (line, taxAcct,
as.getC_Currency_ID(), null, amount);
}
} else {
if(docBaseType.equals(MDocType.DOCBASETYPE_APCreditMemo)) {
fact.createLine (line, m_WriteOffAccount,
as.getC_Currency_ID(), amount, null);
fact.createLine (line, taxAcct,
as.getC_Currency_ID(), null, amount);
} else {
fact.createLine (line, m_WriteOffAccount,
as.getC_Currency_ID(), amount.negate(), null);
fact.createLine (line, taxAcct,
as.getC_Currency_ID(), null, amount.negate());
}
}
}
}
@ -1937,20 +1988,33 @@ class Doc_AllocationTax
if (amount.signum() != 0)
{
if(m_IsSOTrx) {
fact.createLine (line, taxAcct,
as.getC_Currency_ID(), amount, null);
fact.createLine (line, m_WriteOffAccount,
as.getC_Currency_ID(), null, amount);
} else {
fact.createLine (line, taxAcct,
if(docBaseType.equals(MDocType.DOCBASETYPE_ARCreditMemo)) {
fact.createLine (line, taxAcct,
as.getC_Currency_ID(), amount.negate(), null);
fact.createLine (line, m_WriteOffAccount,
fact.createLine (line, m_WriteOffAccount,
as.getC_Currency_ID(), null, amount.negate());
} else {
fact.createLine (line, taxAcct,
as.getC_Currency_ID(), amount, null);
fact.createLine (line, m_WriteOffAccount,
as.getC_Currency_ID(), null, amount);
}
} else {
if(docBaseType.equals(MDocType.DOCBASETYPE_APCreditMemo)) {
fact.createLine (line, taxAcct,
as.getC_Currency_ID(), amount, null);
fact.createLine (line, m_WriteOffAccount,
as.getC_Currency_ID(), null, amount);
} else {
fact.createLine (line, taxAcct,
as.getC_Currency_ID(), amount.negate(), null);
fact.createLine (line, m_WriteOffAccount,
as.getC_Currency_ID(), null, amount.negate());
}
}
}
}
} // WriteOff
} // for all lines
return true;
} // createEntries