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) {
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
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 {
//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());
}
}
}
}
// Original Tax is CR - need to correct it DR
@ -1892,16 +1911,34 @@ class Doc_AllocationTax
{
// for sales actions
if (m_IsSOTrx) {
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 {
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());
}
}
}
}
} // Discount
@ -1917,6 +1954,19 @@ class Doc_AllocationTax
if (amount.signum() != 0)
{
if (m_IsSOTrx) {
if(docBaseType.equals(MDocType.DOCBASETYPE_ARCreditMemo)) {
fact.createLine (line, m_WriteOffAccount,
as.getC_Currency_ID(), amount.negate(), null);
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,
@ -1929,6 +1979,7 @@ class Doc_AllocationTax
}
}
}
}
// Original Tax is CR - need to correct it DR
else
{
@ -1937,6 +1988,19 @@ class Doc_AllocationTax
if (amount.signum() != 0)
{
if(m_IsSOTrx) {
if(docBaseType.equals(MDocType.DOCBASETYPE_ARCreditMemo)) {
fact.createLine (line, taxAcct,
as.getC_Currency_ID(), amount.negate(), null);
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,
@ -1949,8 +2013,8 @@ class Doc_AllocationTax
}
}
}
}
} // WriteOff
} // for all lines
return true;
} // createEntries