From 8db15d01d15e1720939285cd07ba5695ad040964 Mon Sep 17 00:00:00 2001 From: hengsin Date: Tue, 16 Nov 2021 02:06:24 +0800 Subject: [PATCH] IDEMPIERE-2168 Product with ASI Mandatory Type = When Shipping is still mandatory on sales orders (#976) --- .../src/org/compiere/model/MInOut.java | 2 +- .../src/org/compiere/model/MInventory.java | 2 +- .../src/org/compiere/model/MMovement.java | 4 ++-- .../src/org/compiere/model/MOrder.java | 2 +- .../src/org/compiere/model/MProduct.java | 23 ++++++++++++++----- 5 files changed, 22 insertions(+), 11 deletions(-) diff --git a/org.adempiere.base/src/org/compiere/model/MInOut.java b/org.adempiere.base/src/org/compiere/model/MInOut.java index b787e1b89f..7a7561a2fc 100644 --- a/org.adempiere.base/src/org/compiere/model/MInOut.java +++ b/org.adempiere.base/src/org/compiere/model/MInOut.java @@ -1194,7 +1194,7 @@ public class MInOut extends X_M_InOut implements DocAction // if (line.getM_AttributeSetInstance_ID() != 0) continue; - if (product != null && product.isASIMandatory(isSOTrx())) + if (product != null && product.isASIMandatoryFor(MAttributeSet.MANDATORYTYPE_WhenShipping,isSOTrx())) { if (product.getAttributeSet() != null && !product.getAttributeSet().excludeTableEntry(MInOutLine.Table_ID, isSOTrx())) { BigDecimal qtyDiff = line.getMovementQty(); diff --git a/org.adempiere.base/src/org/compiere/model/MInventory.java b/org.adempiere.base/src/org/compiere/model/MInventory.java index abc0c4e338..4ad6678e4c 100644 --- a/org.adempiere.base/src/org/compiere/model/MInventory.java +++ b/org.adempiere.base/src/org/compiere/model/MInventory.java @@ -380,7 +380,7 @@ public class MInventory extends X_M_Inventory implements DocAction if (line.getM_AttributeSetInstance_ID() == 0) { MProduct product = MProduct.get(getCtx(), line.getM_Product_ID(), get_TrxName()); - if (product != null && product.isASIMandatory(line.isSOTrx())) + if (product != null && product.isASIMandatoryFor(null, line.isSOTrx())) { if (product.getAttributeSet() != null && !product.getAttributeSet().excludeTableEntry(MInventoryLine.Table_ID, line.isSOTrx())) { MDocType dt = MDocType.get(getC_DocType_ID()); diff --git a/org.adempiere.base/src/org/compiere/model/MMovement.java b/org.adempiere.base/src/org/compiere/model/MMovement.java index 5a720e7ea2..2c2f7bc9a9 100644 --- a/org.adempiere.base/src/org/compiere/model/MMovement.java +++ b/org.adempiere.base/src/org/compiere/model/MMovement.java @@ -294,7 +294,7 @@ public class MMovement extends X_M_Movement implements DocAction // Mandatory Instance MProduct product = line.getProduct(); if (line.getM_AttributeSetInstance_ID() == 0) { - if (product != null && product.isASIMandatory(true)) { + if (product != null && product.isASIMandatoryFor(null, true)) { if (product.getAttributeSet() != null && !product.getAttributeSet().excludeTableEntry(MMovementLine.Table_ID, true)) { // outgoing BigDecimal qtyDiff = line.getMovementQty(); // verify if the ASIs are captured on lineMA @@ -315,7 +315,7 @@ public class MMovement extends X_M_Movement implements DocAction } if (line.getM_AttributeSetInstanceTo_ID() == 0) { - if (product != null && product.isASIMandatory(false) && line.getM_AttributeSetInstanceTo_ID() == 0) + if (product != null && product.isASIMandatoryFor(null, false) && line.getM_AttributeSetInstanceTo_ID() == 0) { if (product.getAttributeSet() != null && !product.getAttributeSet().excludeTableEntry(MMovementLine.Table_ID, false)) { // incoming m_processMsg = "@Line@ " + line.getLine() + ": @FillMandatory@ @M_AttributeSetInstanceTo_ID@"; diff --git a/org.adempiere.base/src/org/compiere/model/MOrder.java b/org.adempiere.base/src/org/compiere/model/MOrder.java index d72de2b4e6..4497572aa2 100644 --- a/org.adempiere.base/src/org/compiere/model/MOrder.java +++ b/org.adempiere.base/src/org/compiere/model/MOrder.java @@ -1373,7 +1373,7 @@ public class MOrder extends X_C_Order implements DocAction for (MOrderLine line : getLines()) { if (line.getM_Product_ID() > 0 && line.getM_AttributeSetInstance_ID() == 0) { MProduct product = line.getProduct(); - if (product.isASIMandatory(isSOTrx())) { + if (product.isASIMandatoryFor(null, isSOTrx())) { if (product.getAttributeSet() != null && !product.getAttributeSet().excludeTableEntry(MOrderLine.Table_ID, isSOTrx())) { StringBuilder msg = new StringBuilder("@M_AttributeSet_ID@ @IsMandatory@ (@Line@ #") .append(line.getLine()) diff --git a/org.adempiere.base/src/org/compiere/model/MProduct.java b/org.adempiere.base/src/org/compiere/model/MProduct.java index 538063f802..14cf2955d9 100644 --- a/org.adempiere.base/src/org/compiere/model/MProduct.java +++ b/org.adempiere.base/src/org/compiere/model/MProduct.java @@ -882,8 +882,18 @@ public class MProduct extends X_M_Product implements ImmutablePOSupport * @param isSOTrx is outgoing trx? * @return true if ASI is mandatory, false otherwise */ + @Deprecated public boolean isASIMandatory(boolean isSOTrx) { - // + return isASIMandatoryFor(null, isSOTrx); + } + + /** + * Check if ASI is mandatory according to mandatory type + * @param mandatoryType + * @param isSOTrx + * @return true if ASI is mandatory, false otherwise + */ + public boolean isASIMandatoryFor(String mandatoryType, boolean isSOTrx) { // If CostingLevel is BatchLot ASI is always mandatory - check all client acct schemas MAcctSchema[] mass = MAcctSchema.getClientAcctSchema(getCtx(), getAD_Client_ID(), get_TrxName()); for (MAcctSchema as : mass) @@ -899,14 +909,15 @@ public class MProduct extends X_M_Product implements ImmutablePOSupport if (M_AttributeSet_ID != 0) { MAttributeSet mas = MAttributeSet.get(getCtx(), M_AttributeSet_ID); - if (mas == null || !mas.isInstanceAttribute()) + if (mas == null || !mas.isInstanceAttribute()){ return false; - // Outgoing transaction - else if (isSOTrx) - return mas.isMandatory(); + } else if (isSOTrx){ // Outgoing transaction + return mas.isMandatoryAlways() || (mas.isMandatory() && mas.getMandatoryType().equals(mandatoryType)); + } // Incoming transaction - else // isSOTrx == false + else{ // isSOTrx == false return mas.isMandatoryAlways(); + } } // // Default not mandatory