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
|
// 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);
|
MDistributionLine[] lines = distribution.getLines(false);
|
||||||
for (int j = 0; j < lines.length; j++)
|
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());
|
factLine.setAmtSource(dLine.getC_Currency_ID(), null, dl.getAmt().abs());
|
||||||
else
|
else
|
||||||
factLine.setAmtSource(dLine.getC_Currency_ID(), dl.getAmt(), null);
|
factLine.setAmtSource(dLine.getC_Currency_ID(), dl.getAmt(), null);
|
||||||
|
factLine.setQty(dl.getQty());
|
||||||
// Convert
|
// Convert
|
||||||
factLine.convert();
|
factLine.convert();
|
||||||
//
|
//
|
||||||
|
|
|
@ -106,6 +106,7 @@ public final class FactLine extends X_Fact_Acct
|
||||||
reversal.setPostingType(getPostingType());
|
reversal.setPostingType(getPostingType());
|
||||||
//
|
//
|
||||||
reversal.setAmtSource(getC_Currency_ID(), getAmtSourceDr().negate(), getAmtSourceCr().negate());
|
reversal.setAmtSource(getC_Currency_ID(), getAmtSourceDr().negate(), getAmtSourceCr().negate());
|
||||||
|
reversal.setQty(getQty().negate());
|
||||||
reversal.convert();
|
reversal.convert();
|
||||||
reversal.setDescription(description);
|
reversal.setDescription(description);
|
||||||
return reversal;
|
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. *
|
* Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved. *
|
||||||
* This program is free software; you can redistribute it and/or modify it *
|
* 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 *
|
* 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
|
* Distribute Amount to Lines
|
||||||
* @param acct account
|
* @param acct account
|
||||||
* @param Amt amount
|
* @param Amt amount
|
||||||
|
* @param Qty
|
||||||
* @param C_Currency_ID currency
|
* @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);
|
getLines(false);
|
||||||
int precision = MCurrency.getStdPrecision(getCtx(), C_Currency_ID);
|
int precision = MCurrency.getStdPrecision(getCtx(), C_Currency_ID);
|
||||||
// First Round
|
// First Round
|
||||||
BigDecimal total = Env.ZERO;
|
BigDecimal total = Env.ZERO;
|
||||||
|
BigDecimal totalQty = Env.ZERO;
|
||||||
int indexBiggest = -1;
|
int indexBiggest = -1;
|
||||||
int indexZeroPercent = -1;
|
int indexZeroPercent = -1;
|
||||||
for (int i = 0; i < m_lines.length; i++)
|
for (int i = 0; i < m_lines.length; i++)
|
||||||
|
@ -374,7 +376,10 @@ public class MDistribution extends X_GL_Distribution
|
||||||
dl.setAccount(acct);
|
dl.setAccount(acct);
|
||||||
// Calculate Amount
|
// Calculate Amount
|
||||||
dl.calculateAmt (Amt, precision);
|
dl.calculateAmt (Amt, precision);
|
||||||
|
// Calculate Quantity
|
||||||
|
dl.calculateQty (Qty);
|
||||||
total = total.add(dl.getAmt());
|
total = total.add(dl.getAmt());
|
||||||
|
totalQty = totalQty.add(dl.getQty());
|
||||||
// log.fine("distribute - Line=" + dl.getLine() + " - " + dl.getPercent() + "% " + dl.getAmt() + " - Total=" + total);
|
// log.fine("distribute - Line=" + dl.getLine() + " - " + dl.getPercent() + "% " + dl.getAmt() + " - Total=" + total);
|
||||||
// Remainder
|
// Remainder
|
||||||
if (dl.getPercent().compareTo(Env.ZERO) == 0)
|
if (dl.getPercent().compareTo(Env.ZERO) == 0)
|
||||||
|
@ -404,6 +409,23 @@ public class MDistribution extends X_GL_Distribution
|
||||||
else
|
else
|
||||||
log.warning("distribute - Remaining Difference=" + difference);
|
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())
|
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. *
|
* Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved. *
|
||||||
* This program is free software; you can redistribute it and/or modify it *
|
* 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 *
|
* 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
|
* Standard Constructor
|
||||||
|
@ -84,6 +84,8 @@ public class MDistributionLine extends X_GL_DistributionLine
|
||||||
private MDistribution m_parent = null;
|
private MDistribution m_parent = null;
|
||||||
/** The Amount */
|
/** The Amount */
|
||||||
private BigDecimal m_amt = null;
|
private BigDecimal m_amt = null;
|
||||||
|
/** The Quantity */
|
||||||
|
private BigDecimal m_qty = null;
|
||||||
/** The Base Account */
|
/** The Base Account */
|
||||||
private MAccount m_account = null;
|
private MAccount m_account = null;
|
||||||
|
|
||||||
|
@ -164,6 +166,24 @@ public class MDistributionLine extends X_GL_DistributionLine
|
||||||
m_amt = amt;
|
m_amt = amt;
|
||||||
} // setAmt
|
} // 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
|
* Set Distribution Amount
|
||||||
* @param amt The amt to set to be multiplied by percent.
|
* @param amt The amt to set to be multiplied by percent.
|
||||||
|
@ -175,7 +195,16 @@ public class MDistributionLine extends X_GL_DistributionLine
|
||||||
m_amt = m_amt.divide(Env.ONEHUNDRED, precision, BigDecimal.ROUND_HALF_UP);
|
m_amt = m_amt.divide(Env.ONEHUNDRED, precision, BigDecimal.ROUND_HALF_UP);
|
||||||
} // setAmt
|
} // 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
|
||||||
|
|
||||||
|
|
||||||
/**************************************************************************
|
/**************************************************************************
|
||||||
* Before Save
|
* Before Save
|
||||||
|
|
Loading…
Reference in New Issue