Commit a0cdfc9f authored by Andy Armaignac's avatar Andy Armaignac
Browse files

Fixes issue 41749:Fix backdated transaction is not fixing all backdated trx

When the fix backdated transaction process is executed in a costing rule to enable
backdated corrections the process is not adjusting all existing backdated transactions
because the method isNeededBackdatedCostAdjustment from CostAdjustmentUtils is
not returning value when an old transaction already calculated is passed as parameter if was
processed after last transaction and the old transaction movement date is before

Now the process create an ajustment if the transaction movement date is before previous
adjusted transaction movement date
parent 059ab620
......@@ -95,7 +95,7 @@ public class AverageCostAdjustment extends CostingAlgorithmAdjustmentImp {
CostAdjustmentLine baseCAL = getCostAdjLine();
for (CostAdjustmentLine costAdjLine : getTrxAdjustmentLines(basetrx)) {
BigDecimal adjustmentAmt = costAdjLine.getAdjustmentAmount();
if (!strCostCurrencyId.equals(costAdjLine.getCurrency().getId())) {
if (!strCostCurrencyId.equals(costAdjLine.getCurrency().getId()) && adjustmentAmt != null) {
adjustmentAmt = FinancialUtils.getConvertedAmount(adjustmentAmt, costAdjLine.getCurrency(),
getCostCurrency(), costAdjLine.getAccountingDate(), getCostOrg(),
FinancialUtils.PRECISION_STANDARD);
......@@ -105,6 +105,14 @@ public class AverageCostAdjustment extends CostingAlgorithmAdjustmentImp {
if (costAdjLine.isSource() && !costAdjLine.isRelatedTransactionAdjusted()
&& !costAdjLine.getId().equals(strCostAdjLineId)) {
searchRelatedTransactionCosts(costAdjLine);
if (adjustmentAmt == null) {
adjustmentAmt = costAdjLine.getAdjustmentAmount();
if (!strCostCurrencyId.equals(costAdjLine.getCurrency().getId())) {
adjustmentAmt = FinancialUtils.getConvertedAmount(adjustmentAmt,
costAdjLine.getCurrency(), getCostCurrency(), costAdjLine.getAccountingDate(),
getCostOrg(), FinancialUtils.PRECISION_STANDARD);
}
}
}
costAdjLine.setRelatedTransactionAdjusted(Boolean.TRUE);
......@@ -260,7 +268,7 @@ public class AverageCostAdjustment extends CostingAlgorithmAdjustmentImp {
List<CostAdjustmentLine> existingAdjLines = getTrxAdjustmentLines(trx);
for (CostAdjustmentLine existingCAL : existingAdjLines) {
BigDecimal adjustmentAmt = existingCAL.getAdjustmentAmount();
if (!strCurrentCurId.equals(existingCAL.getCurrency().getId())) {
if (!strCurrentCurId.equals(existingCAL.getCurrency().getId()) && adjustmentAmt != null) {
Currency curCurrency = OBDal.getInstance().get(Currency.class, strCurrentCurId);
adjustmentAmt = FinancialUtils.getConvertedAmount(adjustmentAmt,
existingCAL.getCurrency(), curCurrency, existingCAL.getAccountingDate(),
......@@ -269,6 +277,15 @@ public class AverageCostAdjustment extends CostingAlgorithmAdjustmentImp {
if (isFromThisCostAdjustment(existingCAL)) {
if (existingCAL.isSource() && !existingCAL.isRelatedTransactionAdjusted()) {
searchRelatedTransactionCosts(existingCAL);
if (adjustmentAmt == null) {
adjustmentAmt = existingCAL.getAdjustmentAmount();
if (!strCurrentCurId.equals(existingCAL.getCurrency().getId())) {
Currency curCurrency = OBDal.getInstance().get(Currency.class, strCurrentCurId);
adjustmentAmt = FinancialUtils.getConvertedAmount(adjustmentAmt,
existingCAL.getCurrency(), curCurrency, existingCAL.getAccountingDate(),
getCostOrg(), FinancialUtils.PRECISION_STANDARD);
}
}
}
if (existingCAL.getTransactionCostList().isEmpty()) {
trxAdjAmt = trxAdjAmt.add(adjustmentAmt);
......
......@@ -19,6 +19,7 @@
package org.openbravo.costing;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Map;
import java.util.Set;
......@@ -95,10 +96,11 @@ public class FixBackdatedTransactionsProcess extends BaseProcessActionHandler {
rule.getEndingDate());
int i = 0;
try {
SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy");
Date lastMovementDate = dateFormat.parse("01-01-1900");
while (transactions.next()) {
MaterialTransaction trx = (MaterialTransaction) transactions.get()[0];
if (CostAdjustmentUtils.isNeededBackdatedCostAdjustment(trx,
rule.isWarehouseDimension(), CostingUtils.getCostingRuleStartingDate(rule))) {
if (trx.getMovementDate().compareTo(lastMovementDate) < 0) {
createCostAdjustmenHeader(rule.getOrganization());
final CostAdjustmentLineParameters lineParameters = new CostAdjustmentLineParameters(
trx, null, costAdjHeader);
......@@ -112,6 +114,8 @@ public class FixBackdatedTransactionsProcess extends BaseProcessActionHandler {
// Reload rule after clear session.
rule = OBDal.getInstance().get(CostingRule.class, ruleId);
}
} else {
lastMovementDate = trx.getMovementDate();
}
}
} finally {
......@@ -192,7 +196,7 @@ public class FixBackdatedTransactionsProcess extends BaseProcessActionHandler {
select.append(
" and trx." + MaterialTransaction.PROPERTY_TRANSACTIONPROCESSDATE + " < (:endDate)");
}
select.append(" order by trx." + MaterialTransaction.PROPERTY_MOVEMENTDATE);
select.append(" order by trx." + MaterialTransaction.PROPERTY_TRANSACTIONPROCESSDATE);
Query<MaterialTransaction> stockLinesQry = OBDal.getInstance()
.getSession()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment