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:
parent
a5e7802795
commit
3309d9a157
|
@ -21,7 +21,6 @@ import java.sql.Timestamp;
|
|||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import org.compiere.model.MAttributeSetInstance;
|
||||
import org.compiere.model.MClient;
|
||||
import org.compiere.model.MLocator;
|
||||
import org.compiere.model.MProduct;
|
||||
|
@ -158,10 +157,9 @@ public class M_Production_Run extends SvrProcess {
|
|||
|
||||
Timestamp dateMPolicy = production.getMovementDate();
|
||||
if(pline.getM_AttributeSetInstance_ID()>0){
|
||||
if(pline.getM_AttributeSetInstance_ID()>0){
|
||||
MAttributeSetInstance asi = new MAttributeSetInstance(getCtx(), pline.getM_AttributeSetInstance_ID(), get_TrxName());
|
||||
dateMPolicy = asi.getCreated();
|
||||
}
|
||||
Timestamp t = MStorageOnHand.getDateMaterialPolicy(pline.getM_Product_ID(), pline.getM_AttributeSetInstance_ID(), get_TrxName());
|
||||
if (t != null)
|
||||
dateMPolicy = t;
|
||||
}
|
||||
|
||||
if (!MStorageOnHand.add(getCtx(), locator.getM_Warehouse_ID(),
|
||||
|
|
|
@ -1452,10 +1452,7 @@ public class MInOut extends X_M_InOut implements DocAction
|
|||
if (dateMPolicy == null && storages.length > 0)
|
||||
dateMPolicy = storages[0].getDateMaterialPolicy();
|
||||
|
||||
if (dateMPolicy==null && sLine.getM_AttributeSetInstance_ID()!=0) {
|
||||
I_M_AttributeSetInstance asi = sLine.getM_AttributeSetInstance();
|
||||
dateMPolicy = asi.getCreated();
|
||||
} else if(dateMPolicy==null)
|
||||
if(dateMPolicy==null)
|
||||
dateMPolicy = getMovementDate();
|
||||
|
||||
// Fallback: Update Storage - see also VMatch.createMatchRecord
|
||||
|
|
|
@ -151,14 +151,11 @@ public class MInOutLineMA extends X_M_InOutLineMA
|
|||
{
|
||||
if (M_AttributeSetInstance_ID > 0)
|
||||
{
|
||||
MAttributeSetInstance asi = new MAttributeSetInstance(parent.getCtx(), M_AttributeSetInstance_ID, parent.get_TrxName());
|
||||
DateMaterialPolicy = asi.getCreated();
|
||||
DateMaterialPolicy = MStorageOnHand.getDateMaterialPolicy(parent.getM_Product_ID(), M_AttributeSetInstance_ID, parent.get_TrxName());
|
||||
}
|
||||
else
|
||||
{
|
||||
if (DateMaterialPolicy == null)
|
||||
DateMaterialPolicy = parent.getParent().getMovementDate();
|
||||
}
|
||||
}
|
||||
setDateMaterialPolicy(DateMaterialPolicy);
|
||||
setIsAutoGenerated(isAutoGenerated);
|
||||
} // MInOutLineMA
|
||||
|
@ -269,7 +266,7 @@ public class MInOutLineMA extends X_M_InOutLineMA
|
|||
Timestamp dateMPolicy = null;
|
||||
if(getM_AttributeSetInstance_ID()>0)
|
||||
{
|
||||
dateMPolicy = getM_AttributeSetInstance().getCreated();
|
||||
dateMPolicy = MStorageOnHand.getDateMaterialPolicy(line.getM_Product_ID(), getM_AttributeSetInstance_ID(), get_TrxName());
|
||||
}
|
||||
|
||||
if(dateMPolicy == null)
|
||||
|
|
|
@ -568,10 +568,13 @@ public class MInventory extends X_M_Inventory implements DocAction
|
|||
// Fallback
|
||||
if (mtrx == null)
|
||||
{
|
||||
Timestamp dateMPolicy= getMovementDate();
|
||||
I_M_AttributeSetInstance asi = line.getM_AttributeSetInstance();
|
||||
if (asi != null)
|
||||
dateMPolicy =asi.getCreated();
|
||||
Timestamp dateMPolicy= qtyDiff.signum() > 0 ? getMovementDate() : null;
|
||||
if (line.getM_AttributeSetInstance_ID() > 0)
|
||||
{
|
||||
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
|
||||
if (!MStorageOnHand.add(getCtx(), getM_Warehouse_ID(),
|
||||
|
|
|
@ -167,10 +167,9 @@ public class MInventoryLineMA extends X_M_InventoryLineMA
|
|||
{
|
||||
if (M_AttributeSetInstance_ID > 0)
|
||||
{
|
||||
MAttributeSetInstance asi = new MAttributeSetInstance(parent.getCtx(), M_AttributeSetInstance_ID, parent.get_TrxName());
|
||||
DateMaterialPolicy = asi.getCreated();
|
||||
DateMaterialPolicy = MStorageOnHand.getDateMaterialPolicy(parent.getM_Product_ID(), M_AttributeSetInstance_ID, parent.get_TrxName());
|
||||
}
|
||||
else
|
||||
if (DateMaterialPolicy == null)
|
||||
{
|
||||
DateMaterialPolicy = parent.getParent().getMovementDate();
|
||||
}
|
||||
|
@ -244,7 +243,7 @@ public class MInventoryLineMA extends X_M_InventoryLineMA
|
|||
Timestamp dateMPolicy = null;
|
||||
if(getM_AttributeSetInstance_ID()>0)
|
||||
{
|
||||
dateMPolicy = getM_AttributeSetInstance().getCreated();
|
||||
dateMPolicy = MStorageOnHand.getDateMaterialPolicy(line.getM_Product_ID(), getM_AttributeSetInstance_ID(), get_TrxName());
|
||||
}
|
||||
|
||||
if(dateMPolicy == null)
|
||||
|
|
|
@ -536,19 +536,16 @@ public class MMovement extends X_M_Movement implements DocAction
|
|||
if (dateMPolicy == null && storages.length > 0)
|
||||
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());
|
||||
//Update Storage
|
||||
Timestamp effDateMPolicy = dateMPolicy;
|
||||
if (dateMPolicy == null && line.getMovementQty().negate().signum() > 0)
|
||||
effDateMPolicy = getMovementDate();
|
||||
if (!MStorageOnHand.add(getCtx(),locator.getM_Warehouse_ID(),
|
||||
line.getM_Locator_ID(),
|
||||
line.getM_Product_ID(),
|
||||
line.getM_AttributeSetInstance_ID(),
|
||||
line.getMovementQty().negate(),dateMPolicy, get_TrxName()))
|
||||
line.getMovementQty().negate(),effDateMPolicy, get_TrxName()))
|
||||
{
|
||||
String lastError = CLogger.retrieveErrorString("");
|
||||
m_processMsg = "Cannot correct Inventory OnHand (MA) - " + lastError;
|
||||
|
@ -556,12 +553,15 @@ public class MMovement extends X_M_Movement implements DocAction
|
|||
}
|
||||
|
||||
//Update Storage
|
||||
effDateMPolicy = dateMPolicy;
|
||||
if (dateMPolicy == null && line.getMovementQty().signum() > 0)
|
||||
effDateMPolicy = getMovementDate();
|
||||
MLocator locatorTo = new MLocator (getCtx(), line.getM_LocatorTo_ID(), get_TrxName());
|
||||
if (!MStorageOnHand.add(getCtx(),locatorTo.getM_Warehouse_ID(),
|
||||
line.getM_LocatorTo_ID(),
|
||||
line.getM_Product_ID(),
|
||||
line.getM_AttributeSetInstanceTo_ID(),
|
||||
line.getMovementQty(),dateMPolicy, get_TrxName()))
|
||||
line.getMovementQty(),effDateMPolicy, get_TrxName()))
|
||||
{
|
||||
String lastError = CLogger.retrieveErrorString("");
|
||||
m_processMsg = "Cannot correct Inventory OnHand (MA) - " + lastError;
|
||||
|
|
|
@ -169,10 +169,9 @@ public class MMovementLineMA extends X_M_MovementLineMA
|
|||
{
|
||||
if (M_AttributeSetInstance_ID > 0)
|
||||
{
|
||||
MAttributeSetInstance asi = new MAttributeSetInstance(parent.getCtx(), M_AttributeSetInstance_ID, parent.get_TrxName());
|
||||
DateMaterialPolicy = asi.getCreated();
|
||||
DateMaterialPolicy = MStorageOnHand.getDateMaterialPolicy(parent.getM_Product_ID(), M_AttributeSetInstance_ID, parent.get_TrxName());
|
||||
}
|
||||
else
|
||||
if (DateMaterialPolicy == null)
|
||||
{
|
||||
DateMaterialPolicy = parent.getParent().getMovementDate();
|
||||
}
|
||||
|
@ -249,7 +248,7 @@ public class MMovementLineMA extends X_M_MovementLineMA
|
|||
Timestamp dateMPolicy = null;
|
||||
if(getM_AttributeSetInstance_ID()>0)
|
||||
{
|
||||
dateMPolicy = getM_AttributeSetInstance().getCreated();
|
||||
dateMPolicy = MStorageOnHand.getDateMaterialPolicy(line.getM_Product_ID(), getM_AttributeSetInstance_ID(), get_TrxName());
|
||||
}
|
||||
|
||||
if(dateMPolicy == null)
|
||||
|
|
|
@ -99,7 +99,9 @@ public class MProductionLine extends X_M_ProductionLine {
|
|||
|
||||
Timestamp dateMPolicy = date;
|
||||
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);
|
||||
|
|
|
@ -42,10 +42,9 @@ public class MProductionLineMA extends X_M_ProductionLineMA {
|
|||
{
|
||||
if (asi > 0)
|
||||
{
|
||||
MAttributeSetInstance masi = new MAttributeSetInstance(parent.getCtx(), asi, parent.get_TrxName());
|
||||
dateMaterialPolicy = masi.getCreated();
|
||||
dateMaterialPolicy = MStorageOnHand.getDateMaterialPolicy(parent.getM_Product_ID(), asi, parent.get_TrxName());
|
||||
}
|
||||
else
|
||||
if (dateMaterialPolicy == null)
|
||||
{
|
||||
dateMaterialPolicy = parent.getM_Production().getMovementDate();
|
||||
}
|
||||
|
|
|
@ -167,8 +167,9 @@ public class MProjectIssue extends X_C_ProjectIssue
|
|||
Timestamp dateMPolicy = getMovementDate();
|
||||
|
||||
if(getM_AttributeSetInstance_ID()>0){
|
||||
MAttributeSetInstance asi = new MAttributeSetInstance(getCtx(), getM_AttributeSetInstance_ID(), get_TrxName());
|
||||
dateMPolicy = asi.getCreated();
|
||||
Timestamp t = MStorageOnHand.getDateMaterialPolicy(getM_Product_ID(), getM_AttributeSetInstance_ID(), get_TrxName());
|
||||
if (t != null)
|
||||
dateMPolicy = t;
|
||||
}
|
||||
|
||||
if (MStorageOnHand.add(getCtx(), loc.getM_Warehouse_ID(), getM_Locator_ID(),
|
||||
|
|
|
@ -81,15 +81,6 @@ public class MStorageOnHand extends X_M_StorageOnHand
|
|||
else
|
||||
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)
|
||||
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");
|
||||
if (M_Product_ID == 0)
|
||||
throw new IllegalArgumentException("M_Product_ID=0");
|
||||
if (dateMPolicy == null)
|
||||
dateMPolicy = new Timestamp(new Date().getTime());
|
||||
|
||||
if (dateMPolicy != null)
|
||||
dateMPolicy = Util.removeTime(dateMPolicy);
|
||||
|
||||
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)
|
||||
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.saveEx(trxName);
|
||||
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)
|
||||
return true;
|
||||
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
||||
if (dateMPolicy != null)
|
||||
dateMPolicy = Util.removeTime(dateMPolicy);
|
||||
|
||||
// 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){
|
||||
|
||||
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=?";
|
||||
|
||||
PreparedStatement pstmt = null;
|
||||
|
|
Loading…
Reference in New Issue