IDEMPIERE-3082 Production posting not balanced when serializing finished product

This commit is contained in:
Carlos Ruiz 2016-04-21 19:13:27 -07:00
parent 3379872f0a
commit 7bf6ef3296
2 changed files with 26 additions and 7 deletions

View File

@ -196,7 +196,7 @@ public class InventoryCountCreate extends SvrProcess
.append(" AND COALESCE(il.M_AttributeSetInstance_ID,0)=COALESCE(s.M_AttributeSetInstance_ID,0))");
// + " AND il.M_AttributeSetInstance_ID=s.M_AttributeSetInstance_ID)");
//
sql.append(" ORDER BY l.Value, p.Value, s.QtyOnHand DESC"); // Locator/Product
sql.append(" ORDER BY l.Value, p.Value, s.M_AttributeSetInstance_ID, s.DateMaterialPolicy, s.QtyOnHand DESC"); // Locator/Product
//
int count = 0;
PreparedStatement pstmt = null;
@ -279,14 +279,15 @@ public class InventoryCountCreate extends SvrProcess
{
if (QtyOnHand.signum() == 0)
M_AttributeSetInstance_ID = 0;
// TODO???? This is not working --- must create one line and multiple MA
if (m_line != null
&& m_line.getM_Locator_ID() == M_Locator_ID
&& m_line.getM_Product_ID() == M_Product_ID)
{
if (QtyOnHand.signum() == 0)
return 0;
// Same ASI (usually 0)
// Same ASI and Date
if (m_line.getM_AttributeSetInstance_ID() == M_AttributeSetInstance_ID && ((dateMPolicy==null && oldDateMPolicy==null) || (dateMPolicy!=null && dateMPolicy.equals(oldDateMPolicy)) || (oldDateMPolicy!=null && oldDateMPolicy.equals(dateMPolicy))))
{
m_line.setQtyBook(m_line.getQtyBook().add(QtyOnHand));
@ -316,7 +317,7 @@ public class InventoryCountCreate extends SvrProcess
}
// new line
m_line = new MInventoryLine (m_inventory, M_Locator_ID,
M_Product_ID, M_AttributeSetInstance_ID,
M_Product_ID, 0,
QtyOnHand, QtyOnHand); // book/count
oldDateMPolicy = dateMPolicy;

View File

@ -68,6 +68,7 @@ public class Doc_Production extends Doc
return null;
} // loadDocumentDetails
private BigDecimal m_qtyProduced;
/**
* Load Invoice Line
* @param prod production
@ -76,6 +77,7 @@ public class Doc_Production extends Doc
private DocLine[] loadLines(X_M_Production prod)
{
ArrayList<DocLine> list = new ArrayList<DocLine>();
m_qtyProduced = Env.ZERO;
String sqlPL = null;
if (prod.isUseProductionPlan()){
// Production
@ -115,6 +117,9 @@ public class Doc_Production extends Doc
docLine.setProductionBOM(line.getM_Product_ID() == line.getM_ProductionPlan().getM_Product_ID());
else
docLine.setProductionBOM(line.getM_Product_ID() == prod.getM_Product_ID());
if (docLine.isProductionBOM()) {
m_qtyProduced = m_qtyProduced.add(line.getMovementQty());
}
//
if (log.isLoggable(Level.FINE)) log.fine(docLine.toString());
list.add (docLine);
@ -195,9 +200,22 @@ public class Doc_Production extends Doc
if (!parentBomPro.equals(parentEndPro))
continue;
//pb changed this 20/10/06
if (!line0.isProductionBOM())
bomCost = bomCost.add(line0.getProductCosts(as, line.getAD_Org_ID(), false).setScale(2,BigDecimal.ROUND_HALF_UP));
if (!line0.isProductionBOM()) {
// get cost of children
MCostDetail cd0 = MCostDetail.get (as.getCtx(), "M_ProductionLine_ID=?",
line0.get_ID(), line0.getM_AttributeSetInstance_ID(), as.getC_AcctSchema_ID(), getTrxName());
BigDecimal costs0;
if (cd0 != null) {
costs0 = cd0.getAmt();
} else {
costs0 = line0.getProductCosts(as, line0.getAD_Org_ID(), false);
}
bomCost = bomCost.add(costs0.setScale(2,BigDecimal.ROUND_HALF_UP));
}
}
if (line.getQty().compareTo(m_qtyProduced) != 0) {
BigDecimal factor = line.getQty().divide(m_qtyProduced, 12, BigDecimal.ROUND_HALF_UP);
bomCost = bomCost.multiply(factor).setScale(2,BigDecimal.ROUND_HALF_UP);
}
int precision = as.getStdPrecision();
BigDecimal variance = (costs.setScale(precision, BigDecimal.ROUND_HALF_UP)).subtract(bomCost.negate());