Refactoring

- organize imports
- delete large commented code
- improve indentation
This commit is contained in:
Carlos Ruiz 2008-10-09 23:01:24 +00:00
parent 577394612f
commit e3f0d270bb
8 changed files with 223 additions and 431 deletions

View File

@ -29,7 +29,6 @@ import java.util.logging.Level;
import org.compiere.print.ReportEngine; import org.compiere.print.ReportEngine;
import org.compiere.process.DocAction; import org.compiere.process.DocAction;
import org.compiere.process.DocumentEngine; import org.compiere.process.DocumentEngine;
import org.compiere.report.MReportTree;
import org.compiere.util.CLogger; import org.compiere.util.CLogger;
import org.compiere.util.DB; import org.compiere.util.DB;
import org.compiere.util.Env; import org.compiere.util.Env;

View File

@ -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 *
@ -16,13 +16,21 @@
*****************************************************************************/ *****************************************************************************/
package org.compiere.model; package org.compiere.model;
import java.io.*; import java.io.File;
import java.math.*; import java.math.BigDecimal;
import java.sql.*; import java.sql.PreparedStatement;
import java.util.*; import java.sql.ResultSet;
import java.util.logging.*; import java.sql.Timestamp;
import org.compiere.process.*; import java.util.ArrayList;
import org.compiere.util.*; import java.util.Properties;
import java.util.logging.Level;
import org.compiere.process.DocAction;
import org.compiere.process.DocumentEngine;
import org.compiere.util.CCache;
import org.compiere.util.DB;
import org.compiere.util.Env;
import org.compiere.util.Msg;
/** /**
* Physical Inventory Model * Physical Inventory Model
@ -57,8 +65,8 @@ public class MInventory extends X_M_Inventory implements DocAction
/** Cache */ /** Cache */
private static CCache<Integer,MInventory> s_cache = new CCache<Integer,MInventory>("M_Inventory", 5, 5); private static CCache<Integer,MInventory> s_cache = new CCache<Integer,MInventory>("M_Inventory", 5, 5);
/** /**
* Standard Constructor * Standard Constructor
* @param ctx context * @param ctx context
@ -378,7 +386,7 @@ public class MInventory extends X_M_Inventory implements DocAction
if (!DocAction.STATUS_InProgress.equals(status)) if (!DocAction.STATUS_InProgress.equals(status))
return status; return status;
} }
m_processMsg = ModelValidationEngine.get().fireDocValidate(this, ModelValidator.TIMING_BEFORE_COMPLETE); m_processMsg = ModelValidationEngine.get().fireDocValidate(this, ModelValidator.TIMING_BEFORE_COMPLETE);
if (m_processMsg != null) if (m_processMsg != null)
return DocAction.STATUS_Invalid; return DocAction.STATUS_Invalid;
@ -387,237 +395,38 @@ public class MInventory extends X_M_Inventory implements DocAction
if (!isApproved()) if (!isApproved())
approveIt(); approveIt();
log.info(toString()); log.info(toString());
//vpj-cd begin e-evolution recalculate the attribute instances and qty.
/*MInventoryLine[] linesup = getLines(false);
for (int i = 0; i < linesup.length; i++)
{
MInventoryLine line = linesup[i];
String sql1 = "Delete From M_InventoryLineMA "
+ " WHERE M_InventoryLine_ID=" +line.getM_InventoryLine_ID();
int no = DB.executeUpdate(sql1, get_TrxName());
log.info("MA deleted " + no);
StringBuffer sql = new StringBuffer(
"SELECT s.M_Product_ID, s.M_Locator_ID, s.M_AttributeSetInstance_ID,"
+ " s.QtyOnHand, p.M_AttributeSet_ID "
+ "FROM M_Product p"
+ " INNER JOIN M_Storage s ON (s.M_Product_ID=p.M_Product_ID)"
+ " INNER JOIN M_Locator l ON (s.M_Locator_ID=l.M_Locator_ID) "
+ "WHERE l.M_Warehouse_ID=?"
+ " AND p.IsActive='Y' AND p.IsStocked='Y' and p.ProductType='I'"
+ " AND s.M_Locator_ID=" +line.getM_Locator_ID()
+ " AND s.M_Product_ID=" +line.getM_Product_ID()
+ " AND s.QtyOnHand <> 0 "
);
PreparedStatement pstmt = null;
try
{
pstmt = DB.prepareStatement (sql.toString(), get_TrxName());
int index = 1;
pstmt.setInt (index++, getM_Warehouse_ID());
ResultSet rs = pstmt.executeQuery ();
while (rs.next ())
{
MInventoryLineMA maup = new MInventoryLineMA (line,
rs.getInt(3), rs.getBigDecimal(4));
if (!maup.save())
;
}
rs.close ();
pstmt.close ();
pstmt = null;
}
catch (Exception e)
{
log.log(Level.SEVERE, sql.toString(), e);
}
try
{
if (pstmt != null)
pstmt.close ();
pstmt = null;
}
catch (Exception e)
{
pstmt = null;
}
}*/
//vpj-cd e-evolution recalculate the attribute instances and qty END.
/*
//
MInventoryLine[] lines = getLines(false);
for (int i = 0; i < lines.length; i++)
{
MInventoryLine line = lines[i];
if (!line.isActive())
continue;
MTransaction trx = null;
if (line.getM_AttributeSetInstance_ID() == 0)
{
BigDecimal qtyDiff = line.getQtyInternalUse().negate();
if (qtyDiff.signum() == 0)
qtyDiff = line.getQtyCount().subtract(line.getQtyBook());
//
if (qtyDiff.signum() > 0)
{
// Storage
MStorage storage = MStorage.get(getCtx(), line.getM_Locator_ID(),
line.getM_Product_ID(), 0, get_TrxName());
if (storage == null)
storage = MStorage.getCreate(getCtx(), line.getM_Locator_ID(),
line.getM_Product_ID(), 0, get_TrxName());
BigDecimal qtyNew = storage.getQtyOnHand().add(qtyDiff);
log.fine("Diff=" + qtyDiff
+ " - OnHand=" + storage.getQtyOnHand() + "->" + qtyNew);
storage.setQtyOnHand(qtyNew);
storage.setDateLastInventory(getMovementDate());
if (!storage.save(get_TrxName()))
{
m_processMsg = "Storage not updated(1)";
return DocAction.STATUS_Invalid;
}
log.fine(storage.toString());
// Transaction
trx = new MTransaction (getCtx(), line.getAD_Org_ID(),
MTransaction.MOVEMENTTYPE_InventoryIn,
line.getM_Locator_ID(), line.getM_Product_ID(), 0,
qtyDiff, getMovementDate(), get_TrxName());
trx.setM_InventoryLine_ID(line.getM_InventoryLine_ID());
if (!trx.save())
{
m_processMsg = "Transaction not inserted(1)";
return DocAction.STATUS_Invalid;
}
}
else // negative qty
{
MInventoryLineMA mas[] = MInventoryLineMA.get(getCtx(),
line.getM_InventoryLine_ID(), get_TrxName());
for (int j = 0; j < mas.length; j++)
{
MInventoryLineMA ma = mas[j];
// Storage
MStorage storage = MStorage.get(getCtx(), line.getM_Locator_ID(),
line.getM_Product_ID(), ma.getM_AttributeSetInstance_ID(), get_TrxName());
if (storage == null)
storage = MStorage.getCreate(getCtx(), line.getM_Locator_ID(),
line.getM_Product_ID(), ma.getM_AttributeSetInstance_ID(), get_TrxName());
//
BigDecimal maxDiff = qtyDiff;
if (maxDiff.signum() < 0
&& ma.getMovementQty().compareTo(maxDiff.negate()) < 0)
maxDiff = ma.getMovementQty().negate();
BigDecimal qtyNew = ma.getMovementQty().add(maxDiff); // Storage+Diff
log.fine("MA Qty=" + ma.getMovementQty()
+ ",Diff=" + qtyDiff + "|" + maxDiff
+ " - OnHand=" + storage.getQtyOnHand() + "->" + qtyNew
+ " {" + ma.getM_AttributeSetInstance_ID() + "}");
//
storage.setQtyOnHand(qtyNew);
storage.setDateLastInventory(getMovementDate());
if (!storage.save(get_TrxName()))
{
m_processMsg = "Storage not updated (MA)";
return DocAction.STATUS_Invalid;
}
log.fine(storage.toString());
// Transaction
trx = new MTransaction (getCtx(), line.getAD_Org_ID(),
MTransaction.MOVEMENTTYPE_InventoryIn,
line.getM_Locator_ID(), line.getM_Product_ID(), ma.getM_AttributeSetInstance_ID(),
maxDiff, getMovementDate(), get_TrxName());
trx.setM_InventoryLine_ID(line.getM_InventoryLine_ID());
if (!trx.save())
{
m_processMsg = "Transaction not inserted (MA)";
return DocAction.STATUS_Invalid;
}
//
qtyDiff = qtyDiff.subtract(maxDiff);
if (qtyDiff.signum() == 0)
break;
}
} // negative qty
}
// Fallback
if (trx == null)
{
// Storage
MStorage storage = MStorage.get(getCtx(), line.getM_Locator_ID(),
line.getM_Product_ID(), line.getM_AttributeSetInstance_ID(), get_TrxName());
if (storage == null)
storage = MStorage.getCreate(getCtx(), line.getM_Locator_ID(),
line.getM_Product_ID(), line.getM_AttributeSetInstance_ID(), get_TrxName());
//
BigDecimal qtyDiff = line.getQtyInternalUse().negate();
if (Env.ZERO.compareTo(qtyDiff) == 0)
qtyDiff = line.getQtyCount().subtract(line.getQtyBook());
BigDecimal qtyNew = storage.getQtyOnHand().add(qtyDiff);
log.fine("Count=" + line.getQtyCount()
+ ",Book=" + line.getQtyBook() + ", Difference=" + qtyDiff
+ " - OnHand=" + storage.getQtyOnHand() + "->" + qtyNew);
//
storage.setQtyOnHand(qtyNew);
storage.setDateLastInventory(getMovementDate());
if (!storage.save(get_TrxName()))
{
m_processMsg = "Storage not updated(2)";
return DocAction.STATUS_Invalid;
}
log.fine(storage.toString());
// Transaction
trx = new MTransaction (getCtx(), line.getAD_Org_ID(),
MTransaction.MOVEMENTTYPE_InventoryIn,
line.getM_Locator_ID(), line.getM_Product_ID(), line.getM_AttributeSetInstance_ID(),
qtyDiff, getMovementDate(), get_TrxName());
trx.setM_InventoryLine_ID(line.getM_InventoryLine_ID());
if (!trx.save())
{
m_processMsg = "Transaction not inserted(2)";
return DocAction.STATUS_Invalid;
}
} // Fallback
*/
MInventoryLine[] lines = getLines(false); MInventoryLine[] lines = getLines(false);
for (MInventoryLine line : lines) for (MInventoryLine line : lines)
{ {
if (!line.isActive()) if (!line.isActive())
continue; continue;
MProduct product = line.getProduct(); MProduct product = line.getProduct();
//Get Quantity to Inventory Inernal Use //Get Quantity to Inventory Inernal Use
BigDecimal qtyDiff = line.getQtyInternalUse().negate(); BigDecimal qtyDiff = line.getQtyInternalUse().negate();
//If Quantity to Inventory Internal Use = Zero Then is Physical Inventory Else is Inventory Internal Use //If Quantity to Inventory Internal Use = Zero Then is Physical Inventory Else is Inventory Internal Use
if (qtyDiff.signum() == 0) if (qtyDiff.signum() == 0)
qtyDiff = line.getQtyCount().subtract(line.getQtyBook()); qtyDiff = line.getQtyCount().subtract(line.getQtyBook());
//Ignore the Material Policy when is Reverse Correction //Ignore the Material Policy when is Reverse Correction
if(!isReversal()) if(!isReversal())
checkMaterialPolicy(line, qtyDiff); checkMaterialPolicy(line, qtyDiff);
// Stock Movement - Counterpart MOrder.reserveStock // Stock Movement - Counterpart MOrder.reserveStock
if (product != null if (product != null
&& product.isStocked() ) && product.isStocked() )
{ {
log.fine("Material Transaction"); log.fine("Material Transaction");
MTransaction mtrx = null; MTransaction mtrx = null;
//If AttributeSetInstance = Zero then create new AttributeSetInstance use Inventory Line MA else use current AttributeSetInstance //If AttributeSetInstance = Zero then create new AttributeSetInstance use Inventory Line MA else use current AttributeSetInstance
if (line.getM_AttributeSetInstance_ID() == 0 || qtyDiff.compareTo(Env.ZERO) == 0) if (line.getM_AttributeSetInstance_ID() == 0 || qtyDiff.compareTo(Env.ZERO) == 0)
{ {
MInventoryLineMA mas[] = MInventoryLineMA.get(getCtx(), MInventoryLineMA mas[] = MInventoryLineMA.get(getCtx(),
line.getM_InventoryLine_ID(), get_TrxName()); line.getM_InventoryLine_ID(), get_TrxName());
for (int j = 0; j < mas.length; j++) for (int j = 0; j < mas.length; j++)
{ {
MInventoryLineMA ma = mas[j]; MInventoryLineMA ma = mas[j];
@ -625,49 +434,49 @@ public class MInventory extends X_M_Inventory implements DocAction
BigDecimal QtyNew = QtyMA.add(qtyDiff); BigDecimal QtyNew = QtyMA.add(qtyDiff);
log.fine("Diff=" + qtyDiff log.fine("Diff=" + qtyDiff
+ " - Instance OnHand=" + QtyMA + "->" + QtyNew); + " - Instance OnHand=" + QtyMA + "->" + QtyNew);
if (!MStorage.add(getCtx(), getM_Warehouse_ID(), if (!MStorage.add(getCtx(), getM_Warehouse_ID(),
line.getM_Locator_ID(), line.getM_Locator_ID(),
line.getM_Product_ID(), line.getM_Product_ID(),
ma.getM_AttributeSetInstance_ID(), 0, ma.getM_AttributeSetInstance_ID(), 0,
QtyMA.negate(), Env.ZERO, Env.ZERO, get_TrxName())) QtyMA.negate(), Env.ZERO, Env.ZERO, get_TrxName()))
{
m_processMsg = "Cannot correct Inventory (MA)";
return DocAction.STATUS_Invalid;
}
// Only Update Date Last Inventory if is a Physical Inventory
if(line.getQtyInternalUse().compareTo(Env.ZERO) == 0)
{
MStorage storage = MStorage.get(getCtx(), line.getM_Locator_ID(),
line.getM_Product_ID(), ma.getM_AttributeSetInstance_ID(), get_TrxName());
storage.setDateLastInventory(getMovementDate());
if (!storage.save(get_TrxName()))
{ {
m_processMsg = "Cannot correct Inventory (MA)"; m_processMsg = "Storage not updated(2)";
return DocAction.STATUS_Invalid;
}
// Only Update Date Last Inventory if is a Physical Inventory
if(line.getQtyInternalUse().compareTo(Env.ZERO) == 0)
{
MStorage storage = MStorage.get(getCtx(), line.getM_Locator_ID(),
line.getM_Product_ID(), ma.getM_AttributeSetInstance_ID(), get_TrxName());
storage.setDateLastInventory(getMovementDate());
if (!storage.save(get_TrxName()))
{
m_processMsg = "Storage not updated(2)";
return DocAction.STATUS_Invalid;
}
}
String m_MovementType =null;
if(QtyMA.negate().compareTo(Env.ZERO) > 0 )
m_MovementType = MTransaction.MOVEMENTTYPE_InventoryIn;
else
m_MovementType = MTransaction.MOVEMENTTYPE_InventoryOut;
// Transaction
mtrx = new MTransaction (getCtx(), line.getAD_Org_ID(), m_MovementType,
line.getM_Locator_ID(), line.getM_Product_ID(), ma.getM_AttributeSetInstance_ID(),
QtyMA.negate(), getMovementDate(), get_TrxName());
mtrx.setM_InventoryLine_ID(line.getM_InventoryLine_ID());
if (!mtrx.save())
{
m_processMsg = "Transaction not inserted(2)";
return DocAction.STATUS_Invalid; return DocAction.STATUS_Invalid;
} }
qtyDiff = QtyNew; }
String m_MovementType =null;
if(QtyMA.negate().compareTo(Env.ZERO) > 0 )
m_MovementType = MTransaction.MOVEMENTTYPE_InventoryIn;
else
m_MovementType = MTransaction.MOVEMENTTYPE_InventoryOut;
// Transaction
mtrx = new MTransaction (getCtx(), line.getAD_Org_ID(), m_MovementType,
line.getM_Locator_ID(), line.getM_Product_ID(), ma.getM_AttributeSetInstance_ID(),
QtyMA.negate(), getMovementDate(), get_TrxName());
mtrx.setM_InventoryLine_ID(line.getM_InventoryLine_ID());
if (!mtrx.save())
{
m_processMsg = "Transaction not inserted(2)";
return DocAction.STATUS_Invalid;
}
qtyDiff = QtyNew;
} }
} }
//sLine.getM_AttributeSetInstance_ID() != 0 //sLine.getM_AttributeSetInstance_ID() != 0
// Fallback // Fallback
if (mtrx == null) if (mtrx == null)
@ -679,16 +488,16 @@ public class MInventory extends X_M_Inventory implements DocAction
line.getM_AttributeSetInstance_ID(), 0, line.getM_AttributeSetInstance_ID(), 0,
qtyDiff, Env.ZERO, Env.ZERO, get_TrxName())) qtyDiff, Env.ZERO, Env.ZERO, get_TrxName()))
{ {
m_processMsg = "Cannot correct Inventory (MA)"; m_processMsg = "Cannot correct Inventory (MA)";
return DocAction.STATUS_Invalid; return DocAction.STATUS_Invalid;
} }
// Only Update Date Last Inventory if is a Physical Inventory // Only Update Date Last Inventory if is a Physical Inventory
if(line.getQtyInternalUse().compareTo(Env.ZERO) == 0) if(line.getQtyInternalUse().compareTo(Env.ZERO) == 0)
{ {
MStorage storage = MStorage.get(getCtx(), line.getM_Locator_ID(), MStorage storage = MStorage.get(getCtx(), line.getM_Locator_ID(),
line.getM_Product_ID(), line.getM_AttributeSetInstance_ID(), get_TrxName()); line.getM_Product_ID(), line.getM_AttributeSetInstance_ID(), get_TrxName());
storage.setDateLastInventory(getMovementDate()); storage.setDateLastInventory(getMovementDate());
if (!storage.save(get_TrxName())) if (!storage.save(get_TrxName()))
{ {
@ -696,7 +505,7 @@ public class MInventory extends X_M_Inventory implements DocAction
return DocAction.STATUS_Invalid; return DocAction.STATUS_Invalid;
} }
} }
String m_MovementType =null; String m_MovementType =null;
if(qtyDiff.compareTo(Env.ZERO) > 0 ) if(qtyDiff.compareTo(Env.ZERO) > 0 )
m_MovementType = MTransaction.MOVEMENTTYPE_InventoryIn; m_MovementType = MTransaction.MOVEMENTTYPE_InventoryIn;
@ -704,8 +513,8 @@ public class MInventory extends X_M_Inventory implements DocAction
m_MovementType = MTransaction.MOVEMENTTYPE_InventoryOut; m_MovementType = MTransaction.MOVEMENTTYPE_InventoryOut;
// Transaction // Transaction
mtrx = new MTransaction (getCtx(), line.getAD_Org_ID(), m_MovementType, mtrx = new MTransaction (getCtx(), line.getAD_Org_ID(), m_MovementType,
line.getM_Locator_ID(), line.getM_Product_ID(), line.getM_AttributeSetInstance_ID(), line.getM_Locator_ID(), line.getM_Product_ID(), line.getM_AttributeSetInstance_ID(),
qtyDiff, getMovementDate(), get_TrxName()); qtyDiff, getMovementDate(), get_TrxName());
mtrx.setM_InventoryLine_ID(line.getM_InventoryLine_ID()); mtrx.setM_InventoryLine_ID(line.getM_InventoryLine_ID());
if (!mtrx.save()) if (!mtrx.save())
{ {
@ -713,11 +522,11 @@ public class MInventory extends X_M_Inventory implements DocAction
return DocAction.STATUS_Invalid; return DocAction.STATUS_Invalid;
} }
} // Fallback } // Fallback
} // stock movement } // stock movement
} // for all lines } // for all lines
// User Validation // User Validation
String valid = ModelValidationEngine.get().fireDocValidate(this, ModelValidator.TIMING_AFTER_COMPLETE); String valid = ModelValidationEngine.get().fireDocValidate(this, ModelValidator.TIMING_AFTER_COMPLETE);
if (valid != null) if (valid != null)
@ -760,131 +569,86 @@ public class MInventory extends X_M_Inventory implements DocAction
int no = MInventoryLineMA.deleteInventoryMA(line.getM_InventoryLine_ID(), get_TrxName()); int no = MInventoryLineMA.deleteInventoryMA(line.getM_InventoryLine_ID(), get_TrxName());
if (no > 0) if (no > 0)
log.config("Delete old #" + no); log.config("Delete old #" + no);
// Check Line // Check Line
boolean needSave = false; boolean needSave = false;
BigDecimal qtyASI = Env.ZERO ; BigDecimal qtyASI = Env.ZERO ;
// Attribute Set Instance // Attribute Set Instance
if (line.getM_AttributeSetInstance_ID() == 0) if (line.getM_AttributeSetInstance_ID() == 0)
{
MProduct product = MProduct.get(getCtx(), line.getM_Product_ID());
if (qtyDiff.signum() > 0) // Incoming Trx
{ {
MProduct product = MProduct.get(getCtx(), line.getM_Product_ID()); MAttributeSetInstance asi = new MAttributeSetInstance(getCtx(), 0, get_TrxName());
if (qtyDiff.signum() > 0) // Incoming Trx asi.setClientOrg(getAD_Client_ID(), 0);
asi.setM_AttributeSet_ID(product.getM_AttributeSet_ID());
if (!asi.save())
{ {
MAttributeSetInstance asi = new MAttributeSetInstance(getCtx(), 0, get_TrxName()); throw new IllegalStateException("Error try create ASI Reservation");
asi.setClientOrg(getAD_Client_ID(), 0); }
asi.setM_AttributeSet_ID(product.getM_AttributeSet_ID()); if (asi.save())
if (!asi.save()) {
{ line.setM_AttributeSetInstance_ID(asi.getM_AttributeSetInstance_ID());
throw new IllegalStateException("Error try create ASI Reservation"); needSave = true;
}
if (asi.save())
{
line.setM_AttributeSetInstance_ID(asi.getM_AttributeSetInstance_ID());
needSave = true;
}
} }
else // Outgoing Trx }
{ else // Outgoing Trx
String MMPolicy = product.getMMPolicy(); {
MStorage[] storages = MStorage.getAllWithASI(getCtx(), String MMPolicy = product.getMMPolicy();
MStorage[] storages = MStorage.getAllWithASI(getCtx(),
line.getM_Product_ID(), line.getM_Locator_ID(), line.getM_Product_ID(), line.getM_Locator_ID(),
MClient.MMPOLICY_FiFo.equals(MMPolicy), get_TrxName()); MClient.MMPOLICY_FiFo.equals(MMPolicy), get_TrxName());
BigDecimal qtyToDeliver = qtyDiff.negate(); BigDecimal qtyToDeliver = qtyDiff.negate();
/*for (int ii = 0; ii < storages.length; ii++) for (MStorage storage: storages)
{
//cosume ASI Zero
if (storage.getM_AttributeSetInstance_ID() == 0)
{ {
MStorage storage = storages[ii]; qtyASI = qtyASI.add(storage.getQtyOnHand());
if (ii == 0) qtyToDeliver = qtyToDeliver.subtract(storage.getQtyOnHand());
{ continue;
if (storage.getQtyOnHand().compareTo(qtyToDeliver) >= 0) }
{
line.setM_AttributeSetInstance_ID(storage.getM_AttributeSetInstance_ID()); if (storage.getQtyOnHand().compareTo(qtyToDeliver) >= 0)
needSave = true; {
log.config("Direct - " + line); MInventoryLineMA ma = new MInventoryLineMA (line,
qtyToDeliver = Env.ZERO;
}
else
{
log.config("Split - " + line);
MInventoryLineMA ma = new MInventoryLineMA (line,
storage.getM_AttributeSetInstance_ID(),
storage.getQtyOnHand().negate());
if (!ma.save())
;
qtyToDeliver = qtyToDeliver.subtract(storage.getQtyOnHand());
log.fine("#" + ii + ": " + ma + ", QtyToDeliver=" + qtyToDeliver);
}
}
else // create addl material allocation
{
MInventoryLineMA ma = new MInventoryLineMA (line,
storage.getM_AttributeSetInstance_ID(), storage.getM_AttributeSetInstance_ID(),
qtyToDeliver.negate()); qtyToDeliver);
if (storage.getQtyOnHand().compareTo(qtyToDeliver) >= 0)
qtyToDeliver = Env.ZERO;
else
{
ma.setMovementQty(storage.getQtyOnHand().negate());
qtyToDeliver = qtyToDeliver.subtract(storage.getQtyOnHand());
}
if (!ma.save())
;
log.fine("#" + ii + ": " + ma + ", QtyToDeliver=" + qtyToDeliver);
}
if (qtyToDeliver.signum() == 0)
break;
} // for all storages
*/
for (MStorage storage: storages)
{
//cosume ASI Zero
if (storage.getM_AttributeSetInstance_ID() == 0)
{
qtyASI = qtyASI.add(storage.getQtyOnHand());
qtyToDeliver = qtyToDeliver.subtract(storage.getQtyOnHand());
continue;
}
if (storage.getQtyOnHand().compareTo(qtyToDeliver) >= 0)
{
MInventoryLineMA ma = new MInventoryLineMA (line,
storage.getM_AttributeSetInstance_ID(),
qtyToDeliver);
if (!ma.save())
{
throw new IllegalStateException("Error try create ASI Reservation");
}
qtyToDeliver = Env.ZERO;
log.fine( ma + ", QtyToDeliver=" + qtyToDeliver);
//return;
}
else
{
MInventoryLineMA ma = new MInventoryLineMA (line,
storage.getM_AttributeSetInstance_ID(),
storage.getQtyOnHand());
if (!ma.save())
{
throw new IllegalStateException("Error try create ASI Reservation");
}
qtyToDeliver = qtyToDeliver.subtract(storage.getQtyOnHand());
log.fine( ma + ", QtyToDeliver=" + qtyToDeliver);
}
}
// No AttributeSetInstance found for remainder
if (qtyToDeliver.signum() != 0 || qtyASI.signum() != 0)
{
MInventoryLineMA ma = new MInventoryLineMA (line, 0 , qtyToDeliver.add(qtyASI));
if (!ma.save()) if (!ma.save())
; {
log.fine("##: " + ma); throw new IllegalStateException("Error try create ASI Reservation");
}
qtyToDeliver = Env.ZERO;
log.fine( ma + ", QtyToDeliver=" + qtyToDeliver);
//return;
} }
} // outgoing Trx else
{
MInventoryLineMA ma = new MInventoryLineMA (line,
storage.getM_AttributeSetInstance_ID(),
storage.getQtyOnHand());
if (!ma.save())
{
throw new IllegalStateException("Error try create ASI Reservation");
}
qtyToDeliver = qtyToDeliver.subtract(storage.getQtyOnHand());
log.fine( ma + ", QtyToDeliver=" + qtyToDeliver);
}
}
// No AttributeSetInstance found for remainder
if (qtyToDeliver.signum() != 0 || qtyASI.signum() != 0)
{
MInventoryLineMA ma = new MInventoryLineMA (line, 0 , qtyToDeliver.add(qtyASI));
if (!ma.save())
;
log.fine("##: " + ma);
}
} // outgoing Trx
if (needSave && !line.save()) if (needSave && !line.save())
log.severe("NOT saved " + line); log.severe("NOT saved " + line);
} // for all lines } // for all lines
@ -980,7 +744,7 @@ public class MInventory extends X_M_Inventory implements DocAction
m_processMsg = ModelValidationEngine.get().fireDocValidate(this,ModelValidator.TIMING_BEFORE_REVERSECORRECT); m_processMsg = ModelValidationEngine.get().fireDocValidate(this,ModelValidator.TIMING_BEFORE_REVERSECORRECT);
if (m_processMsg != null) if (m_processMsg != null)
return false; return false;
MDocType dt = MDocType.get(getCtx(), getC_DocType_ID()); MDocType dt = MDocType.get(getCtx(), getC_DocType_ID());
if (!MPeriod.isOpen(getCtx(), getMovementDate(), dt.getDocBaseType())) if (!MPeriod.isOpen(getCtx(), getMovementDate(), dt.getDocBaseType()))
{ {
@ -1005,7 +769,7 @@ public class MInventory extends X_M_Inventory implements DocAction
return false; return false;
} }
reversal.setReversal(true); reversal.setReversal(true);
// Reverse Line Qty // Reverse Line Qty
MInventoryLine[] oLines = getLines(true); MInventoryLine[] oLines = getLines(true);
for (int i = 0; i < oLines.length; i++) for (int i = 0; i < oLines.length; i++)
@ -1022,23 +786,23 @@ public class MInventory extends X_M_Inventory implements DocAction
rLine.setQtyBook (oLine.getQtyCount()); // switch rLine.setQtyBook (oLine.getQtyCount()); // switch
rLine.setQtyCount (oLine.getQtyBook()); rLine.setQtyCount (oLine.getQtyBook());
rLine.setQtyInternalUse (oLine.getQtyInternalUse().negate()); rLine.setQtyInternalUse (oLine.getQtyInternalUse().negate());
if (!rLine.save()) if (!rLine.save())
{ {
m_processMsg = "Could not create Inventory Reversal Line"; m_processMsg = "Could not create Inventory Reversal Line";
return false; return false;
} }
//We need to copy MA //We need to copy MA
if (rLine.getM_AttributeSetInstance_ID() == 0) if (rLine.getM_AttributeSetInstance_ID() == 0)
{ {
MInventoryLineMA mas[] = MInventoryLineMA.get(getCtx(), MInventoryLineMA mas[] = MInventoryLineMA.get(getCtx(),
oLines[i].getM_InventoryLine_ID(), get_TrxName()); oLines[i].getM_InventoryLine_ID(), get_TrxName());
for (int j = 0; j < mas.length; j++) for (int j = 0; j < mas.length; j++)
{ {
MInventoryLineMA ma = new MInventoryLineMA (rLine, MInventoryLineMA ma = new MInventoryLineMA (rLine,
mas[j].getM_AttributeSetInstance_ID(), mas[j].getM_AttributeSetInstance_ID(),
mas[j].getMovementQty().negate()); mas[j].getMovementQty().negate());
if (!ma.save()) if (!ma.save())
; ;
} }
@ -1055,7 +819,7 @@ public class MInventory extends X_M_Inventory implements DocAction
reversal.setDocAction(DOCACTION_None); reversal.setDocAction(DOCACTION_None);
reversal.save(); reversal.save();
m_processMsg = reversal.getDocumentNo(); m_processMsg = reversal.getDocumentNo();
// Update Reversed (this) // Update Reversed (this)
addDescription("(" + reversal.getDocumentNo() + "<-)"); addDescription("(" + reversal.getDocumentNo() + "<-)");
// After reverseCorrect // After reverseCorrect
@ -1067,9 +831,9 @@ public class MInventory extends X_M_Inventory implements DocAction
setReversal_ID(reversal.getM_Inventory_ID()); setReversal_ID(reversal.getM_Inventory_ID());
setDocStatus(DOCSTATUS_Reversed); // may come from void setDocStatus(DOCSTATUS_Reversed); // may come from void
setDocAction(DOCACTION_None); setDocAction(DOCACTION_None);
return true; return true;
} // reverseCorrectionIt } // reverseCorrectIt
/** /**
* Reverse Accrual * Reverse Accrual

View File

@ -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 *
@ -16,12 +16,16 @@
*****************************************************************************/ *****************************************************************************/
package org.compiere.model; package org.compiere.model;
import java.math.*; import java.math.BigDecimal;
import java.sql.*; import java.sql.PreparedStatement;
import java.util.*; import java.sql.ResultSet;
import java.util.logging.*; import java.util.Properties;
import java.util.logging.Level;
import org.compiere.util.*; import org.compiere.util.CLogger;
import org.compiere.util.DB;
import org.compiere.util.Env;
import org.compiere.util.Msg;
/** /**
* Physical Inventory Line Model * Physical Inventory Line Model

View File

@ -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 *
@ -16,11 +16,15 @@
*****************************************************************************/ *****************************************************************************/
package org.compiere.model; package org.compiere.model;
import java.math.*; import java.math.BigDecimal;
import java.sql.*; import java.sql.PreparedStatement;
import java.util.*; import java.sql.ResultSet;
import java.util.logging.*; import java.util.ArrayList;
import org.compiere.util.*; import java.util.Properties;
import java.util.logging.Level;
import org.compiere.util.CLogger;
import org.compiere.util.DB;
/** /**

View File

@ -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 *
@ -16,10 +16,15 @@
*****************************************************************************/ *****************************************************************************/
package org.compiere.model; package org.compiere.model;
import java.sql.*; import java.sql.PreparedStatement;
import java.util.*; import java.sql.ResultSet;
import java.util.logging.*; import java.sql.SQLException;
import org.compiere.util.*; import java.util.Properties;
import java.util.logging.Level;
import org.compiere.util.CCache;
import org.compiere.util.CLogger;
import org.compiere.util.DB;
/** /**
* Warehouse Locator Object * Warehouse Locator Object

View File

@ -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 *
@ -16,15 +16,23 @@
*****************************************************************************/ *****************************************************************************/
package org.compiere.model; package org.compiere.model;
import java.io.*; import java.io.File;
import java.math.*; import java.math.BigDecimal;
import java.sql.*; import java.sql.PreparedStatement;
import java.util.*; import java.sql.ResultSet;
import java.util.logging.*; import java.sql.Timestamp;
import org.compiere.process.*; import java.util.ArrayList;
import org.compiere.util.*; import java.util.List;
import java.util.Properties;
import java.util.logging.Level;
import org.eevolution.model.*; import org.compiere.process.DocAction;
import org.compiere.process.DocumentEngine;
import org.compiere.util.DB;
import org.compiere.util.Env;
import org.compiere.util.Msg;
import org.eevolution.model.MDDOrder;
import org.eevolution.model.MDDOrderLine;
/** /**
* Inventory Movement Model * Inventory Movement Model
* *
@ -439,7 +447,7 @@ public class MMovement extends X_M_Movement implements DocAction
line.getM_Product_ID(), ma.getM_AttributeSetInstance_ID(), get_TrxName()); line.getM_Product_ID(), ma.getM_AttributeSetInstance_ID(), get_TrxName());
//*/ //*/
MLocator locatorTo = new MLocator (getCtx(), line.getM_LocatorTo_ID(), get_TrxName()); // MLocator locatorTo = new MLocator (getCtx(), line.getM_LocatorTo_ID(), get_TrxName());
//Update Storage //Update Storage
if (!MStorage.add(getCtx(),locator.getM_Warehouse_ID(), if (!MStorage.add(getCtx(),locator.getM_Warehouse_ID(),
line.getM_LocatorTo_ID(), line.getM_LocatorTo_ID(),
@ -530,7 +538,7 @@ public class MMovement extends X_M_Movement implements DocAction
return DocAction.STATUS_Invalid; return DocAction.STATUS_Invalid;
} }
MLocator locatorTo = new MLocator (getCtx(), line.getM_LocatorTo_ID(), get_TrxName()); // MLocator locatorTo = new MLocator (getCtx(), line.getM_LocatorTo_ID(), get_TrxName());
//Update Storage //Update Storage
if (!MStorage.add(getCtx(),locator.getM_Warehouse_ID(), if (!MStorage.add(getCtx(),locator.getM_Warehouse_ID(),
line.getM_LocatorTo_ID(), line.getM_LocatorTo_ID(),

View File

@ -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 *
@ -16,11 +16,19 @@
*****************************************************************************/ *****************************************************************************/
package org.compiere.model; package org.compiere.model;
import java.math.*; import java.math.BigDecimal;
import java.sql.*; import java.sql.PreparedStatement;
import java.util.*; import java.sql.ResultSet;
import java.util.logging.*; import java.sql.SQLException;
import org.compiere.util.*; import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Properties;
import java.util.logging.Level;
import org.compiere.util.CLogMgt;
import org.compiere.util.CLogger;
import org.compiere.util.DB;
import org.compiere.util.Env;
/** /**
* Inventory Storage Model * Inventory Storage Model

View File

@ -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 *