From 7775f04a14c538546f4a5bbbc47588309b54137a Mon Sep 17 00:00:00 2001 From: Dirk Niemeyer Date: Mon, 6 Aug 2012 16:37:43 +0200 Subject: [PATCH] Bring in Manufacturing Light code from Adaxa / Paul Bowden Merge Production line MA fix. Fixes #93. changeset 6228 6b74072a4797 --- .../compiere/process/ProductionProcess.java | 3 -- .../org/compiere/model/MProductionLine.java | 36 ++++++++----------- .../org/compiere/model/MProductionLineMA.java | 16 +++++++++ 3 files changed, 31 insertions(+), 24 deletions(-) diff --git a/org.adempiere.base.process/src/org/compiere/process/ProductionProcess.java b/org.adempiere.base.process/src/org/compiere/process/ProductionProcess.java index 322c553caa..2c7ad887e5 100644 --- a/org.adempiere.base.process/src/org/compiere/process/ProductionProcess.java +++ b/org.adempiere.base.process/src/org/compiere/process/ProductionProcess.java @@ -31,7 +31,6 @@ public class ProductionProcess extends SvrProcess { protected void prepare() { - log.severe("In prepare method"); ProcessInfoParameter[] para = getParameter(); for (int i = 0; i < para.length; i++) { @@ -72,7 +71,6 @@ public class ProductionProcess extends SvrProcess { int processed = 0; m_production.setMovementDate(p_MovementDate); - System.err.println(m_production.getMovementDate()); MProductionLine[] lines = m_production.getLines(); StringBuffer errors = new StringBuffer(); for ( int i = 0; i 0 ) { MProductionLineMA lineMA = new MProductionLineMA( this, @@ -129,8 +129,6 @@ public class MProductionLine extends X_M_ProductionLine { MStorage[] storages = MStorage.getAll( getCtx(), getM_Product_ID(), getM_Locator_ID(), get_TrxName()); - - MProductionLineMA lineMA = null; MTransaction matTrx = null; BigDecimal qtyToMove = getMovementQty().negate(); @@ -152,16 +150,15 @@ public class MProductionLine extends X_M_ProductionLine { if (slASIString == null) slASIString = ""; - log.log(Level.WARNING,"slASI-Description =" + slASIString); + log.log(Level.FINEST,"slASI-Description =" + slASIString); if ( slASIString.compareTo(asiString) == 0 || asi.getM_AttributeSet_ID() == 0 ) //storage matches specified ASI or is a costing asi (inc. 0) // This process will move negative stock on hand quantities { - lineMA = new MProductionLineMA( this, - storages[sl].getM_AttributeSetInstance_ID(), - lineQty.negate()); + lineMA = MProductionLineMA.get(this,storages[sl].getM_AttributeSetInstance_ID()); + lineMA.setMovementQty(lineMA.getMovementQty().add(lineQty.negate())); if ( !lineMA.save(get_TrxName()) ) { log.log(Level.SEVERE, "Could not save MA for " + toString()); errorString.append("Could not save MA for " + toString() + "\n" ); @@ -185,9 +182,7 @@ public class MProductionLine extends X_M_ProductionLine { errorString.append("Could not update storage for " + toString() + "\n"); } qtyToMove = qtyToMove.subtract(lineQty); - System.err.println("Qty Moved = " + lineQty); - log.log(Level.WARNING, "Qty moved = " + lineQty ); - log.log(Level.WARNING, getLine() + " Qty to move: " + qtyToMove ); + log.log(Level.FINE, getLine() + " Qty moved = " + lineQty + ", Remaining = " + qtyToMove ); } } @@ -206,13 +201,11 @@ public class MProductionLine extends X_M_ProductionLine { } else { - MProduct product = new MProduct(Env.getCtx(), getM_Product_ID(), get_TrxName()); - int defaultLocator = product.getM_Locator_ID(); - MStorage storage = MStorage.get(Env.getCtx(), defaultLocator, getM_Product_ID(), 0, get_TrxName()); + MStorage storage = MStorage.get(Env.getCtx(), getM_Locator_ID(), getM_Product_ID(), 0, get_TrxName()); if (storage == null) { storage = new MStorage(Env.getCtx(), 0, get_TrxName()); - storage.setM_Locator_ID(defaultLocator); + storage.setM_Locator_ID(getM_Locator_ID()); storage.setM_Product_ID(getM_Product_ID()); storage.setM_AttributeSetInstance_ID(0); storage.save(); @@ -226,16 +219,19 @@ public class MProductionLine extends X_M_ProductionLine { if (slASIString == null) slASIString = ""; - log.log(Level.WARNING,"slASI-Description =" + slASIString); + log.log(Level.FINEST,"slASI-Description =" + slASIString); if ( slASIString.compareTo(asiString) == 0 || asi.getM_AttributeSet_ID() == 0 ) //storage matches specified ASI or is a costing asi (inc. 0) // This process will move negative stock on hand quantities { - lineMA = new MProductionLineMA( this, - storage.getM_AttributeSetInstance_ID(), - lineQty.negate()); + //lineMA = new MProductionLineMA( this, + // storage.getM_AttributeSetInstance_ID(), + // lineQty.negate()); + lineMA = MProductionLineMA.get(this,storage.getM_AttributeSetInstance_ID()); + lineMA.setMovementQty(lineMA.getMovementQty().add(lineQty.negate())); + if ( !lineMA.save(get_TrxName()) ) { log.log(Level.SEVERE, "Could not save MA for " + toString()); errorString.append("Could not save MA for " + toString() + "\n" ); @@ -259,9 +255,7 @@ public class MProductionLine extends X_M_ProductionLine { errorString.append("Could not update storage for " + toString() + "\n"); } qtyToMove = qtyToMove.subtract(lineQty); - System.err.println("Qty Moved = " + lineQty); - log.log(Level.WARNING, "Qty moved = " + lineQty ); - log.log(Level.WARNING, getLine() + " Qty to move: " + qtyToMove ); + log.log(Level.FINE, getLine() + " Qty moved = " + lineQty + ", Remaining = " + qtyToMove ); } } diff --git a/org.adempiere.base/src/org/compiere/model/MProductionLineMA.java b/org.adempiere.base/src/org/compiere/model/MProductionLineMA.java index 3557f4ce1b..f452745af1 100644 --- a/org.adempiere.base/src/org/compiere/model/MProductionLineMA.java +++ b/org.adempiere.base/src/org/compiere/model/MProductionLineMA.java @@ -5,6 +5,7 @@ import java.sql.ResultSet; import java.util.Properties; import org.compiere.model.X_M_ProductionLineMA; +import org.compiere.util.Env; public class MProductionLineMA extends X_M_ProductionLineMA { @@ -40,5 +41,20 @@ public class MProductionLineMA extends X_M_ProductionLineMA { setMovementQty(qty); } + + public static MProductionLineMA get( MProductionLine parent, int asi ) { + + String where = " M_ProductionLine_ID = ? AND M_AttributeSetInstance_ID = ? "; + + MProductionLineMA lineMA = MTable.get(parent.getCtx(), MProductionLineMA.Table_Name).createQuery(where, parent.get_TrxName()) + .setParameters(parent.getM_ProductionLine_ID(), asi).firstOnly(); + + if (lineMA != null) + return lineMA; + else + return new MProductionLineMA( parent, + asi, + Env.ZERO); + } }