IDEMPIERE-3305 Material Policy Date for products with and without ASI. Use MovementDate or MStorageOnHand.datempolicy instead of M_AttributeSetInstance.Created

This commit is contained in:
Heng Sin Low 2017-03-16 21:16:53 +08:00
parent a5e7802795
commit 3309d9a157
11 changed files with 52 additions and 72 deletions

View File

@ -21,7 +21,6 @@ import java.sql.Timestamp;
import java.util.List; import java.util.List;
import java.util.logging.Level; import java.util.logging.Level;
import org.compiere.model.MAttributeSetInstance;
import org.compiere.model.MClient; import org.compiere.model.MClient;
import org.compiere.model.MLocator; import org.compiere.model.MLocator;
import org.compiere.model.MProduct; import org.compiere.model.MProduct;
@ -158,10 +157,9 @@ public class M_Production_Run extends SvrProcess {
Timestamp dateMPolicy = production.getMovementDate(); Timestamp dateMPolicy = production.getMovementDate();
if(pline.getM_AttributeSetInstance_ID()>0){ if(pline.getM_AttributeSetInstance_ID()>0){
if(pline.getM_AttributeSetInstance_ID()>0){ Timestamp t = MStorageOnHand.getDateMaterialPolicy(pline.getM_Product_ID(), pline.getM_AttributeSetInstance_ID(), get_TrxName());
MAttributeSetInstance asi = new MAttributeSetInstance(getCtx(), pline.getM_AttributeSetInstance_ID(), get_TrxName()); if (t != null)
dateMPolicy = asi.getCreated(); dateMPolicy = t;
}
} }
if (!MStorageOnHand.add(getCtx(), locator.getM_Warehouse_ID(), if (!MStorageOnHand.add(getCtx(), locator.getM_Warehouse_ID(),

View File

@ -1452,10 +1452,7 @@ public class MInOut extends X_M_InOut implements DocAction
if (dateMPolicy == null && storages.length > 0) if (dateMPolicy == null && storages.length > 0)
dateMPolicy = storages[0].getDateMaterialPolicy(); dateMPolicy = storages[0].getDateMaterialPolicy();
if (dateMPolicy==null && sLine.getM_AttributeSetInstance_ID()!=0) { if(dateMPolicy==null)
I_M_AttributeSetInstance asi = sLine.getM_AttributeSetInstance();
dateMPolicy = asi.getCreated();
} else if(dateMPolicy==null)
dateMPolicy = getMovementDate(); dateMPolicy = getMovementDate();
// Fallback: Update Storage - see also VMatch.createMatchRecord // Fallback: Update Storage - see also VMatch.createMatchRecord

View File

@ -151,14 +151,11 @@ public class MInOutLineMA extends X_M_InOutLineMA
{ {
if (M_AttributeSetInstance_ID > 0) if (M_AttributeSetInstance_ID > 0)
{ {
MAttributeSetInstance asi = new MAttributeSetInstance(parent.getCtx(), M_AttributeSetInstance_ID, parent.get_TrxName()); DateMaterialPolicy = MStorageOnHand.getDateMaterialPolicy(parent.getM_Product_ID(), M_AttributeSetInstance_ID, parent.get_TrxName());
DateMaterialPolicy = asi.getCreated();
} }
else if (DateMaterialPolicy == null)
{
DateMaterialPolicy = parent.getParent().getMovementDate(); DateMaterialPolicy = parent.getParent().getMovementDate();
} }
}
setDateMaterialPolicy(DateMaterialPolicy); setDateMaterialPolicy(DateMaterialPolicy);
setIsAutoGenerated(isAutoGenerated); setIsAutoGenerated(isAutoGenerated);
} // MInOutLineMA } // MInOutLineMA
@ -269,7 +266,7 @@ public class MInOutLineMA extends X_M_InOutLineMA
Timestamp dateMPolicy = null; Timestamp dateMPolicy = null;
if(getM_AttributeSetInstance_ID()>0) if(getM_AttributeSetInstance_ID()>0)
{ {
dateMPolicy = getM_AttributeSetInstance().getCreated(); dateMPolicy = MStorageOnHand.getDateMaterialPolicy(line.getM_Product_ID(), getM_AttributeSetInstance_ID(), get_TrxName());
} }
if(dateMPolicy == null) if(dateMPolicy == null)

View File

@ -568,10 +568,13 @@ public class MInventory extends X_M_Inventory implements DocAction
// Fallback // Fallback
if (mtrx == null) if (mtrx == null)
{ {
Timestamp dateMPolicy= getMovementDate(); Timestamp dateMPolicy= qtyDiff.signum() > 0 ? getMovementDate() : null;
I_M_AttributeSetInstance asi = line.getM_AttributeSetInstance(); if (line.getM_AttributeSetInstance_ID() > 0)
if (asi != null) {
dateMPolicy =asi.getCreated(); Timestamp t = MStorageOnHand.getDateMaterialPolicy(line.getM_Product_ID(), line.getM_AttributeSetInstance_ID(), line.get_TrxName());
if (t != null)
dateMPolicy = t;
}
//Fallback: Update Storage - see also VMatch.createMatchRecord //Fallback: Update Storage - see also VMatch.createMatchRecord
if (!MStorageOnHand.add(getCtx(), getM_Warehouse_ID(), if (!MStorageOnHand.add(getCtx(), getM_Warehouse_ID(),

View File

@ -167,10 +167,9 @@ public class MInventoryLineMA extends X_M_InventoryLineMA
{ {
if (M_AttributeSetInstance_ID > 0) if (M_AttributeSetInstance_ID > 0)
{ {
MAttributeSetInstance asi = new MAttributeSetInstance(parent.getCtx(), M_AttributeSetInstance_ID, parent.get_TrxName()); DateMaterialPolicy = MStorageOnHand.getDateMaterialPolicy(parent.getM_Product_ID(), M_AttributeSetInstance_ID, parent.get_TrxName());
DateMaterialPolicy = asi.getCreated();
} }
else if (DateMaterialPolicy == null)
{ {
DateMaterialPolicy = parent.getParent().getMovementDate(); DateMaterialPolicy = parent.getParent().getMovementDate();
} }
@ -244,7 +243,7 @@ public class MInventoryLineMA extends X_M_InventoryLineMA
Timestamp dateMPolicy = null; Timestamp dateMPolicy = null;
if(getM_AttributeSetInstance_ID()>0) if(getM_AttributeSetInstance_ID()>0)
{ {
dateMPolicy = getM_AttributeSetInstance().getCreated(); dateMPolicy = MStorageOnHand.getDateMaterialPolicy(line.getM_Product_ID(), getM_AttributeSetInstance_ID(), get_TrxName());
} }
if(dateMPolicy == null) if(dateMPolicy == null)

View File

@ -536,19 +536,16 @@ public class MMovement extends X_M_Movement implements DocAction
if (dateMPolicy == null && storages.length > 0) if (dateMPolicy == null && storages.length > 0)
dateMPolicy = storages[0].getDateMaterialPolicy(); dateMPolicy = storages[0].getDateMaterialPolicy();
if (dateMPolicy==null && line.getM_AttributeSetInstanceTo_ID()!=0) {
I_M_AttributeSetInstance asi = line.getM_AttributeSetInstance();
dateMPolicy = asi.getCreated();
} else if(dateMPolicy==null)
dateMPolicy = getMovementDate();
MLocator locator = new MLocator (getCtx(), line.getM_Locator_ID(), get_TrxName()); MLocator locator = new MLocator (getCtx(), line.getM_Locator_ID(), get_TrxName());
//Update Storage //Update Storage
Timestamp effDateMPolicy = dateMPolicy;
if (dateMPolicy == null && line.getMovementQty().negate().signum() > 0)
effDateMPolicy = getMovementDate();
if (!MStorageOnHand.add(getCtx(),locator.getM_Warehouse_ID(), if (!MStorageOnHand.add(getCtx(),locator.getM_Warehouse_ID(),
line.getM_Locator_ID(), line.getM_Locator_ID(),
line.getM_Product_ID(), line.getM_Product_ID(),
line.getM_AttributeSetInstance_ID(), line.getM_AttributeSetInstance_ID(),
line.getMovementQty().negate(),dateMPolicy, get_TrxName())) line.getMovementQty().negate(),effDateMPolicy, get_TrxName()))
{ {
String lastError = CLogger.retrieveErrorString(""); String lastError = CLogger.retrieveErrorString("");
m_processMsg = "Cannot correct Inventory OnHand (MA) - " + lastError; m_processMsg = "Cannot correct Inventory OnHand (MA) - " + lastError;
@ -556,12 +553,15 @@ public class MMovement extends X_M_Movement implements DocAction
} }
//Update Storage //Update Storage
effDateMPolicy = dateMPolicy;
if (dateMPolicy == null && line.getMovementQty().signum() > 0)
effDateMPolicy = getMovementDate();
MLocator locatorTo = new MLocator (getCtx(), line.getM_LocatorTo_ID(), get_TrxName()); MLocator locatorTo = new MLocator (getCtx(), line.getM_LocatorTo_ID(), get_TrxName());
if (!MStorageOnHand.add(getCtx(),locatorTo.getM_Warehouse_ID(), if (!MStorageOnHand.add(getCtx(),locatorTo.getM_Warehouse_ID(),
line.getM_LocatorTo_ID(), line.getM_LocatorTo_ID(),
line.getM_Product_ID(), line.getM_Product_ID(),
line.getM_AttributeSetInstanceTo_ID(), line.getM_AttributeSetInstanceTo_ID(),
line.getMovementQty(),dateMPolicy, get_TrxName())) line.getMovementQty(),effDateMPolicy, get_TrxName()))
{ {
String lastError = CLogger.retrieveErrorString(""); String lastError = CLogger.retrieveErrorString("");
m_processMsg = "Cannot correct Inventory OnHand (MA) - " + lastError; m_processMsg = "Cannot correct Inventory OnHand (MA) - " + lastError;

View File

@ -169,10 +169,9 @@ public class MMovementLineMA extends X_M_MovementLineMA
{ {
if (M_AttributeSetInstance_ID > 0) if (M_AttributeSetInstance_ID > 0)
{ {
MAttributeSetInstance asi = new MAttributeSetInstance(parent.getCtx(), M_AttributeSetInstance_ID, parent.get_TrxName()); DateMaterialPolicy = MStorageOnHand.getDateMaterialPolicy(parent.getM_Product_ID(), M_AttributeSetInstance_ID, parent.get_TrxName());
DateMaterialPolicy = asi.getCreated();
} }
else if (DateMaterialPolicy == null)
{ {
DateMaterialPolicy = parent.getParent().getMovementDate(); DateMaterialPolicy = parent.getParent().getMovementDate();
} }
@ -249,7 +248,7 @@ public class MMovementLineMA extends X_M_MovementLineMA
Timestamp dateMPolicy = null; Timestamp dateMPolicy = null;
if(getM_AttributeSetInstance_ID()>0) if(getM_AttributeSetInstance_ID()>0)
{ {
dateMPolicy = getM_AttributeSetInstance().getCreated(); dateMPolicy = MStorageOnHand.getDateMaterialPolicy(line.getM_Product_ID(), getM_AttributeSetInstance_ID(), get_TrxName());
} }
if(dateMPolicy == null) if(dateMPolicy == null)

View File

@ -99,7 +99,9 @@ public class MProductionLine extends X_M_ProductionLine {
Timestamp dateMPolicy = date; Timestamp dateMPolicy = date;
if(getM_AttributeSetInstance_ID()>0){ if(getM_AttributeSetInstance_ID()>0){
dateMPolicy = asi.getCreated(); Timestamp t = MStorageOnHand.getDateMaterialPolicy(getM_Product_ID(), getM_AttributeSetInstance_ID(), get_TrxName());
if (t != null)
dateMPolicy = t;
} }
dateMPolicy = Util.removeTime(dateMPolicy); dateMPolicy = Util.removeTime(dateMPolicy);

View File

@ -42,10 +42,9 @@ public class MProductionLineMA extends X_M_ProductionLineMA {
{ {
if (asi > 0) if (asi > 0)
{ {
MAttributeSetInstance masi = new MAttributeSetInstance(parent.getCtx(), asi, parent.get_TrxName()); dateMaterialPolicy = MStorageOnHand.getDateMaterialPolicy(parent.getM_Product_ID(), asi, parent.get_TrxName());
dateMaterialPolicy = masi.getCreated();
} }
else if (dateMaterialPolicy == null)
{ {
dateMaterialPolicy = parent.getM_Production().getMovementDate(); dateMaterialPolicy = parent.getM_Production().getMovementDate();
} }

View File

@ -167,8 +167,9 @@ public class MProjectIssue extends X_C_ProjectIssue
Timestamp dateMPolicy = getMovementDate(); Timestamp dateMPolicy = getMovementDate();
if(getM_AttributeSetInstance_ID()>0){ if(getM_AttributeSetInstance_ID()>0){
MAttributeSetInstance asi = new MAttributeSetInstance(getCtx(), getM_AttributeSetInstance_ID(), get_TrxName()); Timestamp t = MStorageOnHand.getDateMaterialPolicy(getM_Product_ID(), getM_AttributeSetInstance_ID(), get_TrxName());
dateMPolicy = asi.getCreated(); if (t != null)
dateMPolicy = t;
} }
if (MStorageOnHand.add(getCtx(), loc.getM_Warehouse_ID(), getM_Locator_ID(), if (MStorageOnHand.add(getCtx(), loc.getM_Warehouse_ID(), getM_Locator_ID(),

View File

@ -81,15 +81,6 @@ public class MStorageOnHand extends X_M_StorageOnHand
else else
sqlWhere += "M_AttributeSetInstance_ID=?"; sqlWhere += "M_AttributeSetInstance_ID=?";
if (dateMPolicy == null)
{
if (M_AttributeSetInstance_ID > 0)
{
MAttributeSetInstance asi = new MAttributeSetInstance(ctx, M_AttributeSetInstance_ID, trxName);
dateMPolicy = asi.getCreated();
}
}
if (dateMPolicy != null) if (dateMPolicy != null)
sqlWhere += " AND DateMaterialPolicy=trunc(cast(? as date))"; sqlWhere += " AND DateMaterialPolicy=trunc(cast(? as date))";
@ -630,9 +621,7 @@ public class MStorageOnHand extends X_M_StorageOnHand
throw new IllegalArgumentException("M_Locator_ID=0"); throw new IllegalArgumentException("M_Locator_ID=0");
if (M_Product_ID == 0) if (M_Product_ID == 0)
throw new IllegalArgumentException("M_Product_ID=0"); throw new IllegalArgumentException("M_Product_ID=0");
if (dateMPolicy == null) if (dateMPolicy != null)
dateMPolicy = new Timestamp(new Date().getTime());
dateMPolicy = Util.removeTime(dateMPolicy); dateMPolicy = Util.removeTime(dateMPolicy);
MStorageOnHand retValue = get(ctx, M_Locator_ID, M_Product_ID, M_AttributeSetInstance_ID,dateMPolicy, trxName); MStorageOnHand retValue = get(ctx, M_Locator_ID, M_Product_ID, M_AttributeSetInstance_ID,dateMPolicy, trxName);
@ -648,6 +637,11 @@ public class MStorageOnHand extends X_M_StorageOnHand
if (locator.get_ID() != M_Locator_ID) if (locator.get_ID() != M_Locator_ID)
throw new IllegalArgumentException("Not found M_Locator_ID=" + M_Locator_ID); throw new IllegalArgumentException("Not found M_Locator_ID=" + M_Locator_ID);
// //
if (dateMPolicy == null)
{
dateMPolicy = new Timestamp(new Date().getTime());
dateMPolicy = Util.removeTime(dateMPolicy);
}
retValue = new MStorageOnHand (locator, M_Product_ID, M_AttributeSetInstance_ID,dateMPolicy); retValue = new MStorageOnHand (locator, M_Product_ID, M_AttributeSetInstance_ID,dateMPolicy);
retValue.saveEx(trxName); retValue.saveEx(trxName);
if (s_log.isLoggable(Level.FINE)) s_log.fine("New " + retValue); if (s_log.isLoggable(Level.FINE)) s_log.fine("New " + retValue);
@ -696,19 +690,7 @@ public class MStorageOnHand extends X_M_StorageOnHand
if (diffQtyOnHand == null || diffQtyOnHand.signum() == 0) if (diffQtyOnHand == null || diffQtyOnHand.signum() == 0)
return true; return true;
if (dateMPolicy == null) if (dateMPolicy != null)
{
if (M_AttributeSetInstance_ID > 0)
{
MAttributeSetInstance asi = new MAttributeSetInstance(ctx, M_AttributeSetInstance_ID, trxName);
dateMPolicy = asi.getCreated();
}
else
{
dateMPolicy = new Timestamp(System.currentTimeMillis());
}
}
dateMPolicy = Util.removeTime(dateMPolicy); dateMPolicy = Util.removeTime(dateMPolicy);
// Get Storage // Get Storage
@ -1040,6 +1022,9 @@ public class MStorageOnHand extends X_M_StorageOnHand
*/ */
public static Timestamp getDateMaterialPolicy(int M_Product_ID, int M_AttributeSetInstance_ID,String trxName){ public static Timestamp getDateMaterialPolicy(int M_Product_ID, int M_AttributeSetInstance_ID,String trxName){
if (M_Product_ID <= 0 || M_AttributeSetInstance_ID <= 0)
return null;
String sql = "SELECT dateMaterialPolicy FROM M_StorageOnHand WHERE M_Product_ID=? and M_AttributeSetInstance_ID=?"; String sql = "SELECT dateMaterialPolicy FROM M_StorageOnHand WHERE M_Product_ID=? and M_AttributeSetInstance_ID=?";
PreparedStatement pstmt = null; PreparedStatement pstmt = null;