IDEMPIERE-4269 shipment (on availability) should be created only if products are available (#1329)

IDEMPIERE-4269 shipment (on availability) should be created only if products are available

Co-authored-by: hengsin <hengsin@gmail.com>
This commit is contained in:
lHeidbreder 2022-06-29 16:15:08 +02:00 committed by GitHub
parent a93d516db2
commit ddaf0d6af3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 125 additions and 9 deletions

View File

@ -0,0 +1,34 @@
SET SQLBLANKLINES ON
SET DEFINE OFF
-- IDEMPIERE-4269
-- 29.06.2022 09:17:31
INSERT INTO AD_Element (AD_Element_ID,AD_Client_ID,AD_Org_ID,IsActive,Created,CreatedBy,Updated,UpdatedBy,ColumnName,Name,Description,PrintName,EntityType,AD_Element_UU) VALUES (203610,0,0,'Y',TO_DATE('2022-06-29 09:17:25','YYYY-MM-DD HH24:MI:SS'),100,TO_DATE('2022-06-29 09:17:25','YYYY-MM-DD HH24:MI:SS'),100,'SubtractOnHand','Subtract In Progress Shipment From On Hand','Subtract In Progress Shipment From On Hand','Subtract In Progress Shipment From On Hand','D','f09a7fa9-83fc-4644-85b2-b610c51b2fe0')
;
-- 29.06.2022 09:21:02
INSERT INTO AD_Process_Para (AD_Process_Para_ID,AD_Client_ID,AD_Org_ID,IsActive,Created,CreatedBy,Updated,UpdatedBy,Name,Description,AD_Process_ID,SeqNo,AD_Reference_ID,IsRange,FieldLength,IsMandatory,DefaultValue,ColumnName,IsCentrallyMaintained,EntityType,AD_Element_ID,AD_Process_Para_UU,IsEncrypted,IsAutocomplete) VALUES (200387,0,0,'Y',TO_DATE('2022-06-29 09:20:57','YYYY-MM-DD HH24:MI:SS'),100,TO_DATE('2022-06-29 09:20:57','YYYY-MM-DD HH24:MI:SS'),100,'Subtract In Progress Shipment From On Hand','Subtract In Progress Shipment From On Hand',118,70,20,'N',0,'N','N','SubtractOnHand','Y','D',203610,'159af26e-2742-445b-b847-d58bbfbbb24f','N','N')
;
-- 29.06.2022 09:32:35
INSERT INTO AD_TableIndex (AD_Client_ID,AD_Org_ID,AD_TableIndex_ID,AD_TableIndex_UU,Created,CreatedBy,EntityType,IsActive,Name,Updated,UpdatedBy,AD_Table_ID,IsCreateConstraint,IsUnique,Processing,TableIndexDrop,IsKey) VALUES (0,0,201124,'93a3dcd5-88ef-4d3a-bd60-03d52149b80b',TO_DATE('2022-06-29 09:32:30','YYYY-MM-DD HH24:MI:SS'),100,'D','Y','m_inout_docstatus',TO_DATE('2022-06-29 09:32:30','YYYY-MM-DD HH24:MI:SS'),100,319,'N','N','N','N','N')
;
-- 29.06.2022 09:36:53
INSERT INTO AD_IndexColumn (AD_Client_ID,AD_Org_ID,AD_IndexColumn_ID,AD_IndexColumn_UU,Created,CreatedBy,EntityType,IsActive,Updated,UpdatedBy,AD_Column_ID,AD_TableIndex_ID,SeqNo) VALUES (0,0,201503,'e311a6c6-fa5b-4763-8462-a0845164c255',TO_DATE('2022-06-29 09:36:48','YYYY-MM-DD HH24:MI:SS'),100,'D','Y',TO_DATE('2022-06-29 09:36:48','YYYY-MM-DD HH24:MI:SS'),100,4323,201124,10)
;
-- 29.06.2022 09:37:14
INSERT INTO AD_IndexColumn (AD_Client_ID,AD_Org_ID,AD_IndexColumn_ID,AD_IndexColumn_UU,Created,CreatedBy,EntityType,IsActive,Updated,UpdatedBy,AD_Column_ID,AD_TableIndex_ID,SeqNo) VALUES (0,0,201504,'407f09d0-60e2-45a1-895a-abe894e1c2c1',TO_DATE('2022-06-29 09:37:14','YYYY-MM-DD HH24:MI:SS'),100,'D','Y',TO_DATE('2022-06-29 09:37:14','YYYY-MM-DD HH24:MI:SS'),100,3790,201124,20)
;
-- 29.06.2022 09:37:29
INSERT INTO AD_IndexColumn (AD_Client_ID,AD_Org_ID,AD_IndexColumn_ID,AD_IndexColumn_UU,Created,CreatedBy,EntityType,IsActive,Updated,UpdatedBy,AD_Column_ID,AD_TableIndex_ID,SeqNo) VALUES (0,0,201505,'f46b4b2b-ed50-4142-bfec-c0cd55f15c4a',TO_DATE('2022-06-29 09:37:24','YYYY-MM-DD HH24:MI:SS'),100,'D','Y',TO_DATE('2022-06-29 09:37:24','YYYY-MM-DD HH24:MI:SS'),100,3798,201124,30)
;
-- 29.06.2022 09:37:43
CREATE INDEX m_inout_docstatus ON M_InOut (DocStatus,IsSOTrx,M_Warehouse_ID)
;
SELECT register_migration_script('202206290940_IDEMPIERE-4269.sql') FROM dual
;

View File

@ -0,0 +1,31 @@
-- IDEMPIERE-4269
-- 29.06.2022 09:17:31
INSERT INTO AD_Element (AD_Element_ID,AD_Client_ID,AD_Org_ID,IsActive,Created,CreatedBy,Updated,UpdatedBy,ColumnName,Name,Description,PrintName,EntityType,AD_Element_UU) VALUES (203610,0,0,'Y',TO_TIMESTAMP('2022-06-29 09:17:25','YYYY-MM-DD HH24:MI:SS'),100,TO_TIMESTAMP('2022-06-29 09:17:25','YYYY-MM-DD HH24:MI:SS'),100,'SubtractOnHand','Subtract In Progress Shipment From On Hand','Subtract In Progress Shipment From On Hand','Subtract In Progress Shipment From On Hand','D','f09a7fa9-83fc-4644-85b2-b610c51b2fe0')
;
-- 29.06.2022 09:21:02
INSERT INTO AD_Process_Para (AD_Process_Para_ID,AD_Client_ID,AD_Org_ID,IsActive,Created,CreatedBy,Updated,UpdatedBy,Name,Description,AD_Process_ID,SeqNo,AD_Reference_ID,IsRange,FieldLength,IsMandatory,DefaultValue,ColumnName,IsCentrallyMaintained,EntityType,AD_Element_ID,AD_Process_Para_UU,IsEncrypted,IsAutocomplete) VALUES (200387,0,0,'Y',TO_TIMESTAMP('2022-06-29 09:20:57','YYYY-MM-DD HH24:MI:SS'),100,TO_TIMESTAMP('2022-06-29 09:20:57','YYYY-MM-DD HH24:MI:SS'),100,'Subtract In Progress Shipment From On Hand','Subtract In Progress Shipment From On Hand',118,70,20,'N',0,'N','N','SubtractOnHand','Y','D',203610,'159af26e-2742-445b-b847-d58bbfbbb24f','N','N')
;
-- 29.06.2022 09:32:35
INSERT INTO AD_TableIndex (AD_Client_ID,AD_Org_ID,AD_TableIndex_ID,AD_TableIndex_UU,Created,CreatedBy,EntityType,IsActive,Name,Updated,UpdatedBy,AD_Table_ID,IsCreateConstraint,IsUnique,Processing,TableIndexDrop,IsKey) VALUES (0,0,201124,'93a3dcd5-88ef-4d3a-bd60-03d52149b80b',TO_TIMESTAMP('2022-06-29 09:32:30','YYYY-MM-DD HH24:MI:SS'),100,'D','Y','m_inout_docstatus',TO_TIMESTAMP('2022-06-29 09:32:30','YYYY-MM-DD HH24:MI:SS'),100,319,'N','N','N','N','N')
;
-- 29.06.2022 09:36:53
INSERT INTO AD_IndexColumn (AD_Client_ID,AD_Org_ID,AD_IndexColumn_ID,AD_IndexColumn_UU,Created,CreatedBy,EntityType,IsActive,Updated,UpdatedBy,AD_Column_ID,AD_TableIndex_ID,SeqNo) VALUES (0,0,201503,'e311a6c6-fa5b-4763-8462-a0845164c255',TO_TIMESTAMP('2022-06-29 09:36:48','YYYY-MM-DD HH24:MI:SS'),100,'D','Y',TO_TIMESTAMP('2022-06-29 09:36:48','YYYY-MM-DD HH24:MI:SS'),100,4323,201124,10)
;
-- 29.06.2022 09:37:14
INSERT INTO AD_IndexColumn (AD_Client_ID,AD_Org_ID,AD_IndexColumn_ID,AD_IndexColumn_UU,Created,CreatedBy,EntityType,IsActive,Updated,UpdatedBy,AD_Column_ID,AD_TableIndex_ID,SeqNo) VALUES (0,0,201504,'407f09d0-60e2-45a1-895a-abe894e1c2c1',TO_TIMESTAMP('2022-06-29 09:37:14','YYYY-MM-DD HH24:MI:SS'),100,'D','Y',TO_TIMESTAMP('2022-06-29 09:37:14','YYYY-MM-DD HH24:MI:SS'),100,3790,201124,20)
;
-- 29.06.2022 09:37:29
INSERT INTO AD_IndexColumn (AD_Client_ID,AD_Org_ID,AD_IndexColumn_ID,AD_IndexColumn_UU,Created,CreatedBy,EntityType,IsActive,Updated,UpdatedBy,AD_Column_ID,AD_TableIndex_ID,SeqNo) VALUES (0,0,201505,'f46b4b2b-ed50-4142-bfec-c0cd55f15c4a',TO_TIMESTAMP('2022-06-29 09:37:24','YYYY-MM-DD HH24:MI:SS'),100,'D','Y',TO_TIMESTAMP('2022-06-29 09:37:24','YYYY-MM-DD HH24:MI:SS'),100,3798,201124,30)
;
-- 29.06.2022 09:37:43
CREATE INDEX m_inout_docstatus ON M_InOut (DocStatus,IsSOTrx,M_Warehouse_ID)
;
SELECT register_migration_script('202206290940_IDEMPIERE-4269.sql') FROM dual
;

View File

@ -36,6 +36,7 @@ import org.compiere.model.MOrder;
import org.compiere.model.MOrderLine;
import org.compiere.model.MProduct;
import org.compiere.model.MStorageOnHand;
import org.compiere.model.Query;
import org.compiere.util.AdempiereUserError;
import org.compiere.util.DB;
import org.compiere.util.Env;
@ -61,6 +62,8 @@ public class InOutGenerate extends SvrProcess
private Timestamp p_DatePromised = null;
/** Include Orders w. unconfirmed Shipments */
private boolean p_IsUnconfirmedInOut = false;
/** Reserve on hand for this inout */
private boolean p_SubtractOnHand = false;
/** DocAction */
private String p_docAction = DocAction.ACTION_None;
/** Consolidate */
@ -112,6 +115,8 @@ public class InOutGenerate extends SvrProcess
p_Selection = "Y".equals(para[i].getParameter());
else if (name.equals("IsUnconfirmedInOut"))
p_IsUnconfirmedInOut = "Y".equals(para[i].getParameter());
else if (name.equals("SubtractOnHand"))
p_SubtractOnHand = "Y".equals(para[i].getParameter());
else if (name.equals("ConsolidateDocument"))
p_ConsolidateDocument = "Y".equals(para[i].getParameter());
else if (name.equals("DocAction"))
@ -273,27 +278,55 @@ public class InOutGenerate extends SvrProcess
// Check / adjust for confirmations
BigDecimal unconfirmedShippedQty = Env.ZERO;
BigDecimal totalunconfirmedShippedQty = Env.ZERO;
StringBuilder logInfo = null;
if (p_IsUnconfirmedInOut && product != null && toDeliver.signum() != 0)
{
String where2 = "EXISTS (SELECT * FROM M_InOut io WHERE io.M_InOut_ID=M_InOutLine.M_InOut_ID AND io.DocStatus IN ('DR','IN','IP','WC'))";
MInOutLine[] iols = MInOutLine.getOfOrderLine(getCtx(),
line.getC_OrderLine_ID(), where2, null);
for (int j = 0; j < iols.length; j++)
for (int j = 0; j < iols.length; j++)
unconfirmedShippedQty = unconfirmedShippedQty.add(iols[j].getMovementQty());
StringBuilder logInfo = new StringBuilder("Unconfirmed Qty=").append(unconfirmedShippedQty)
.append(" - ToDeliver=").append(toDeliver).append("->");
if (log.isLoggable(Level.FINE))
logInfo = new StringBuilder("Unconfirmed Qty=").append(unconfirmedShippedQty)
.append(" - ToDeliver=").append(toDeliver).append("->");
toDeliver = toDeliver.subtract(unconfirmedShippedQty);
logInfo.append(toDeliver);
if (log.isLoggable(Level.FINE))
logInfo.append(toDeliver);
if (toDeliver.signum() < 0)
{
toDeliver = Env.ZERO;
logInfo.append(" (set to 0)");
if (log.isLoggable(Level.FINE))
logInfo.append(" (set to 0)");
}
if (log.isLoggable(Level.FINE) && logInfo.length() > 0) log.fine(logInfo.toString());
if (toDeliver.signum() == 0) {
if (completeOrder)
completeOrder = false;
continue;
}
// Adjust On Hand
onHand = onHand.subtract(unconfirmedShippedQty);
if (log.isLoggable(Level.FINE)) log.fine(logInfo.toString());
}
if (product != null && toDeliver.signum() != 0) {
// Adjust On Hand
if(p_SubtractOnHand) {
StringBuilder where3 = new StringBuilder (
"EXISTS (SELECT * FROM M_InOut io "
+ "WHERE io.M_InOut_ID=M_InOutLine.M_InOut_ID "
+ "AND io.IsSOTrx = 'Y' "
+ "AND io.DocStatus IN ('IP','WC') "
+ "AND io.M_Warehouse_ID=").append(p_M_Warehouse_ID).append (") "
+ "AND M_Product_ID = ").append(line.getM_Product_ID());
totalunconfirmedShippedQty =
new Query(getCtx(), MInOutLine.Table_Name, where3.toString(), get_TrxName())
.aggregate(MInOutLine.COLUMNNAME_MovementQty, Query.AGGREGATE_SUM);
onHand = onHand.subtract(totalunconfirmedShippedQty);
} else if (unconfirmedShippedQty.signum() != 0){
onHand = onHand.subtract(unconfirmedShippedQty);
}
}
// Comments & lines w/o product & services
if ((product == null || !product.isStocked())
&& (line.getQtyOrdered().signum() == 0 // comments

View File

@ -46,6 +46,24 @@ public class MInOutLine extends X_M_InOutLine
*/
private static final long serialVersionUID = 8630611882798722864L;
/**
* Get Ship lines Of Product
* * @param ctx context
* @param M_Product_ID product
* @param where optional addition where clause
* @param trxName transaction
* @return array of receipt lines
*/
public static MInOutLine[] getOfProduct (Properties ctx,
int M_Product_ID, String where, String trxName)
{
String whereClause = "M_Product_ID=?" + (!Util.isEmpty(where, true) ? " AND "+where : "");
List<MInOutLine> list = new Query(ctx, Table_Name, whereClause, trxName)
.setParameters(M_Product_ID)
.list();
return list.toArray (new MInOutLine[list.size()]);
}
/**
* Get Ship lines Of Order Line
* @param ctx context