BF [2794181] - GL Distribution is not distributing product quantities
https://sourceforge.net/tracker/index.php?func=detail&aid=2794181&group_id=176962&atid=879332
This commit is contained in:
parent
682dd0cca4
commit
8e9f588f3c
|
@ -720,7 +720,7 @@ public final class Fact
|
|||
}
|
||||
|
||||
// Prepare
|
||||
distribution.distribute(dLine.getAccount(), dLine.getSourceBalance(), dLine.getC_Currency_ID());
|
||||
distribution.distribute(dLine.getAccount(), dLine.getSourceBalance(), dLine.getQty(), dLine.getC_Currency_ID());
|
||||
MDistributionLine[] lines = distribution.getLines(false);
|
||||
for (int j = 0; j < lines.length; j++)
|
||||
{
|
||||
|
@ -740,6 +740,7 @@ public final class Fact
|
|||
factLine.setAmtSource(dLine.getC_Currency_ID(), null, dl.getAmt().abs());
|
||||
else
|
||||
factLine.setAmtSource(dLine.getC_Currency_ID(), dl.getAmt(), null);
|
||||
factLine.setQty(dl.getQty());
|
||||
// Convert
|
||||
factLine.convert();
|
||||
//
|
||||
|
|
|
@ -106,6 +106,7 @@ public final class FactLine extends X_Fact_Acct
|
|||
reversal.setPostingType(getPostingType());
|
||||
//
|
||||
reversal.setAmtSource(getC_Currency_ID(), getAmtSourceDr().negate(), getAmtSourceCr().negate());
|
||||
reversal.setQty(getQty().negate());
|
||||
reversal.convert();
|
||||
reversal.setDescription(description);
|
||||
return reversal;
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/******************************************************************************
|
||||
* Product: Adempiere ERP & CRM Smart Business Solution *
|
||||
* Product: Adempiere ERP & CRM Smart Business Solution *
|
||||
* Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved. *
|
||||
* This program is free software; you can redistribute it and/or modify it *
|
||||
* under the terms version 2 of the GNU General Public License as published *
|
||||
|
@ -40,7 +40,7 @@ public class MDistribution extends X_GL_Distribution
|
|||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = -7136322027476009173L;
|
||||
private static final long serialVersionUID = -906547096682610205L;
|
||||
|
||||
|
||||
/**
|
||||
|
@ -355,15 +355,17 @@ public class MDistribution extends X_GL_Distribution
|
|||
* Distribute Amount to Lines
|
||||
* @param acct account
|
||||
* @param Amt amount
|
||||
* @param Qty
|
||||
* @param C_Currency_ID currency
|
||||
*/
|
||||
public void distribute (MAccount acct, BigDecimal Amt, int C_Currency_ID)
|
||||
public void distribute (MAccount acct, BigDecimal Amt, BigDecimal Qty, int C_Currency_ID)
|
||||
{
|
||||
log.info("distribute - Amt=" + Amt + " - " + acct);
|
||||
log.info("distribute - Amt=" + Amt + " - Qty=" + Qty + " - " + acct);
|
||||
getLines(false);
|
||||
int precision = MCurrency.getStdPrecision(getCtx(), C_Currency_ID);
|
||||
// First Round
|
||||
BigDecimal total = Env.ZERO;
|
||||
BigDecimal totalQty = Env.ZERO;
|
||||
int indexBiggest = -1;
|
||||
int indexZeroPercent = -1;
|
||||
for (int i = 0; i < m_lines.length; i++)
|
||||
|
@ -374,7 +376,10 @@ public class MDistribution extends X_GL_Distribution
|
|||
dl.setAccount(acct);
|
||||
// Calculate Amount
|
||||
dl.calculateAmt (Amt, precision);
|
||||
// Calculate Quantity
|
||||
dl.calculateQty (Qty);
|
||||
total = total.add(dl.getAmt());
|
||||
totalQty = totalQty.add(dl.getQty());
|
||||
// log.fine("distribute - Line=" + dl.getLine() + " - " + dl.getPercent() + "% " + dl.getAmt() + " - Total=" + total);
|
||||
// Remainder
|
||||
if (dl.getPercent().compareTo(Env.ZERO) == 0)
|
||||
|
@ -404,6 +409,23 @@ public class MDistribution extends X_GL_Distribution
|
|||
else
|
||||
log.warning("distribute - Remaining Difference=" + difference);
|
||||
}
|
||||
// Adjust Remainder
|
||||
BigDecimal differenceQty = Qty.subtract(totalQty);
|
||||
if (differenceQty.compareTo(Env.ZERO) != 0)
|
||||
{
|
||||
if (indexZeroPercent != -1)
|
||||
{
|
||||
// log.fine("distribute - Difference=" + difference + " - 0%Line=" + m_lines[indexZeroPercent]);
|
||||
m_lines[indexZeroPercent].setQty (differenceQty);
|
||||
}
|
||||
else if (indexBiggest != -1)
|
||||
{
|
||||
// log.fine("distribute - Difference=" + difference + " - MaxLine=" + m_lines[indexBiggest] + " - " + m_lines[indexBiggest].getAmt());
|
||||
m_lines[indexBiggest].setQty (m_lines[indexBiggest].getQty().add(differenceQty));
|
||||
}
|
||||
else
|
||||
log.warning("distribute - Remaining Qty Difference=" + differenceQty);
|
||||
}
|
||||
//
|
||||
if (CLogMgt.isLevelFinest())
|
||||
{
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/******************************************************************************
|
||||
* Product: Adempiere ERP & CRM Smart Business Solution *
|
||||
* Product: Adempiere ERP & CRM Smart Business Solution *
|
||||
* Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved. *
|
||||
* This program is free software; you can redistribute it and/or modify it *
|
||||
* under the terms version 2 of the GNU General Public License as published *
|
||||
|
@ -35,7 +35,7 @@ public class MDistributionLine extends X_GL_DistributionLine
|
|||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = -8967296538546883724L;
|
||||
private static final long serialVersionUID = 6148743556518054326L;
|
||||
|
||||
/**
|
||||
* Standard Constructor
|
||||
|
@ -84,6 +84,8 @@ public class MDistributionLine extends X_GL_DistributionLine
|
|||
private MDistribution m_parent = null;
|
||||
/** The Amount */
|
||||
private BigDecimal m_amt = null;
|
||||
/** The Quantity */
|
||||
private BigDecimal m_qty = null;
|
||||
/** The Base Account */
|
||||
private MAccount m_account = null;
|
||||
|
||||
|
@ -164,6 +166,24 @@ public class MDistributionLine extends X_GL_DistributionLine
|
|||
m_amt = amt;
|
||||
} // setAmt
|
||||
|
||||
/**************************************************************************
|
||||
* Get Distribution Quantity
|
||||
* @return Returns the qty.
|
||||
*/
|
||||
public BigDecimal getQty ()
|
||||
{
|
||||
return m_qty;
|
||||
} // getQty
|
||||
|
||||
/**
|
||||
* Set Distribution Quantity
|
||||
* @param qty The qty to set.
|
||||
*/
|
||||
public void setQty (BigDecimal qty)
|
||||
{
|
||||
m_qty = qty;
|
||||
} // setQty
|
||||
|
||||
/**
|
||||
* Set Distribution Amount
|
||||
* @param amt The amt to set to be multiplied by percent.
|
||||
|
@ -175,6 +195,15 @@ public class MDistributionLine extends X_GL_DistributionLine
|
|||
m_amt = m_amt.divide(Env.ONEHUNDRED, precision, BigDecimal.ROUND_HALF_UP);
|
||||
} // setAmt
|
||||
|
||||
/**
|
||||
* Set Distribution Quantity
|
||||
* @param qty The qty to set to be multiplied by percent.
|
||||
*/
|
||||
public void calculateQty (BigDecimal qty)
|
||||
{
|
||||
m_qty = qty.multiply(getPercent());
|
||||
m_qty = m_qty.divide(Env.ONEHUNDRED, BigDecimal.ROUND_HALF_UP);
|
||||
} // setAmt
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
|
|
Loading…
Reference in New Issue