BF [ 2820743 ] CalloutBOM - apply ABP
https://sourceforge.net/tracker/?func=detail&aid=2820743&group_id=176962&atid=934929
This commit is contained in:
parent
fe16694e18
commit
64bdad502d
|
@ -19,48 +19,29 @@ package org.eevolution.model;
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
import javax.swing.JOptionPane;
|
import org.adempiere.exceptions.AdempiereException;
|
||||||
|
import org.adempiere.model.GridTabWrapper;
|
||||||
import org.compiere.model.CalloutEngine;
|
import org.compiere.model.CalloutEngine;
|
||||||
import org.compiere.model.GridField;
|
import org.compiere.model.GridField;
|
||||||
import org.compiere.model.GridTab;
|
import org.compiere.model.GridTab;
|
||||||
|
import org.compiere.model.I_M_Product;
|
||||||
|
import org.compiere.model.MProduct;
|
||||||
import org.compiere.model.MUOMConversion;
|
import org.compiere.model.MUOMConversion;
|
||||||
import org.compiere.model.X_M_Product;
|
|
||||||
import org.compiere.util.Env;
|
import org.compiere.util.Env;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Order Callouts.
|
* BOM Callouts
|
||||||
*
|
*
|
||||||
* @author Victor Perez www.e-evolution.com
|
* @author Victor Perez www.e-evolution.com
|
||||||
* @version $Id: CalloutBOM.java,v 1.11 2004/03/22 07:15:03 vpj-cd Exp $
|
* @author Teo Sarca, www.arhipac.ro
|
||||||
|
* <li>BF [ 2820743 ] CalloutBOM - apply ABP
|
||||||
|
* https://sourceforge.net/tracker/?func=detail&aid=2820743&group_id=176962&atid=934929
|
||||||
*/
|
*/
|
||||||
public class CalloutBOM extends CalloutEngine
|
public class CalloutBOM extends CalloutEngine
|
||||||
{
|
{
|
||||||
/** Debug Steps */
|
|
||||||
private boolean steps = false;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Order Header Change - DocType.
|
* Parent cycle.
|
||||||
* - InvoiceRuld/DeliveryRule/PaymentRule
|
|
||||||
* - temporary Document
|
|
||||||
* Context:
|
|
||||||
* - DocSubTypeSO
|
|
||||||
* - HasCharges
|
|
||||||
* - (re-sets Business Partner info of required)
|
|
||||||
*
|
|
||||||
* @param ctx Context
|
|
||||||
* @param WindowNo current Window No
|
|
||||||
* @param mTab Model Tab
|
|
||||||
* @param mField Model Field
|
|
||||||
* @param value The new value
|
|
||||||
* @return Error message or ""
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Parent cicle.
|
|
||||||
* @param ctx Context
|
* @param ctx Context
|
||||||
* @param WindowNo current Window No
|
* @param WindowNo current Window No
|
||||||
* @param mTab Model Tab
|
* @param mTab Model Tab
|
||||||
|
@ -69,183 +50,63 @@ public class CalloutBOM extends CalloutEngine
|
||||||
*/
|
*/
|
||||||
public String parent (Properties ctx, int WindowNo, GridTab mTab, GridField mField, Object value)
|
public String parent (Properties ctx, int WindowNo, GridTab mTab, GridField mField, Object value)
|
||||||
{
|
{
|
||||||
Integer M_Product_ID = (Integer)value;
|
|
||||||
if (M_Product_ID == null || M_Product_ID.intValue() == 0)
|
|
||||||
return "";
|
|
||||||
setCalloutActive(true);
|
|
||||||
|
|
||||||
if (isCalloutActive() || value == null)
|
if (isCalloutActive() || value == null)
|
||||||
return "";
|
return "";
|
||||||
|
final int M_Product_ID = (Integer)value;
|
||||||
|
if (M_Product_ID <= 0)
|
||||||
|
return "";
|
||||||
|
|
||||||
|
I_PP_Product_BOMLine bomLine = GridTabWrapper.create(mTab, I_PP_Product_BOMLine.class);
|
||||||
if (steps) log.warning("parent - init");
|
I_PP_Product_BOM bom = bomLine.getPP_Product_BOM();
|
||||||
|
if (bom.getM_Product_ID() == bomLine.getM_Product_ID())
|
||||||
setCalloutActive(true);
|
|
||||||
|
|
||||||
int PP_Product_BOM_ID = Env.getContextAsInt(ctx, WindowNo, "PP_Product_BOM_ID");
|
|
||||||
X_PP_Product_BOM PP_Product_BOM = new X_PP_Product_BOM(ctx, PP_Product_BOM_ID,"PP_Product_BOM");
|
|
||||||
if (PP_Product_BOM.getM_Product_ID() == M_Product_ID.intValue())
|
|
||||||
{
|
{
|
||||||
JOptionPane.showMessageDialog(null,"ValidComponent" , "Error Parent not be Componet" , JOptionPane.ERROR_MESSAGE);
|
throw new AdempiereException("@ValidComponent@ - Error Parent not be Component");
|
||||||
return "";
|
|
||||||
}
|
}
|
||||||
setCalloutActive(false);
|
|
||||||
return "";
|
return "";
|
||||||
} // amt
|
}
|
||||||
|
|
||||||
public String qty (Properties ctx, int WindowNo, GridTab mTab, GridField mField, Object value)
|
|
||||||
{
|
|
||||||
if (isCalloutActive() || value == null)
|
|
||||||
return "";
|
|
||||||
setCalloutActive(true);
|
|
||||||
|
|
||||||
int M_Product_ID = Env.getContextAsInt(ctx, WindowNo, "M_Product_ID");
|
|
||||||
if (steps) log.warning("qty - init - M_Product_ID=" + M_Product_ID + " - " );
|
|
||||||
BigDecimal QtyOrdered, QtyEntered; //, PriceActual, PriceEntered;
|
|
||||||
|
|
||||||
// No Product
|
|
||||||
if (M_Product_ID == 0)
|
|
||||||
{
|
|
||||||
QtyEntered = (BigDecimal)mTab.getValue("QtyEntered");
|
|
||||||
mTab.setValue("QtyOrdered", QtyEntered);
|
|
||||||
}
|
|
||||||
// UOM Changed - convert from Entered -> Product
|
|
||||||
else if (mField.getColumnName().equals("C_UOM_ID"))
|
|
||||||
{
|
|
||||||
int C_UOM_To_ID = ((Integer)value).intValue();
|
|
||||||
QtyEntered = (BigDecimal)mTab.getValue("QtyEntered");
|
|
||||||
QtyOrdered = MUOMConversion.convertProductFrom (ctx, M_Product_ID,
|
|
||||||
C_UOM_To_ID, QtyEntered);
|
|
||||||
if (QtyOrdered == null)
|
|
||||||
QtyOrdered = QtyEntered;
|
|
||||||
boolean conversion = QtyEntered.compareTo(QtyOrdered) != 0;
|
|
||||||
//PriceActual = (BigDecimal)mTab.getValue("PriceActual");
|
|
||||||
//PriceEntered = MUOMConversion.convertProductFrom (ctx, M_Product_ID,
|
|
||||||
// C_UOM_To_ID, PriceActual);
|
|
||||||
//if (PriceEntered == null)
|
|
||||||
// PriceEntered = PriceActual;
|
|
||||||
// log.fine("qty - UOM=" + C_UOM_To_ID
|
|
||||||
// + ", QtyEntered/PriceActual=" + QtyEntered + "/" + PriceActual
|
|
||||||
// + " -> " + conversion
|
|
||||||
// + " QtyOrdered/PriceEntered=" + QtyOrdered + "/" + PriceEntered);
|
|
||||||
Env.setContext(ctx, WindowNo, "UOMConversion", conversion ? "Y" : "N");
|
|
||||||
mTab.setValue("QtyOrdered", QtyOrdered);
|
|
||||||
// mTab.setValue("PriceEntered", PriceEntered);
|
|
||||||
}
|
|
||||||
// QtyEntered changed - calculate QtyOrdered
|
|
||||||
else if (mField.getColumnName().equals("QtyEntered"))
|
|
||||||
{
|
|
||||||
int C_UOM_To_ID = Env.getContextAsInt(ctx, WindowNo, "C_UOM_ID");
|
|
||||||
QtyEntered = (BigDecimal)value;
|
|
||||||
QtyOrdered = MUOMConversion.convertProductFrom (ctx, M_Product_ID,
|
|
||||||
C_UOM_To_ID, QtyEntered);
|
|
||||||
if (QtyOrdered == null)
|
|
||||||
QtyOrdered = QtyEntered;
|
|
||||||
boolean conversion = QtyEntered.compareTo(QtyOrdered) != 0;
|
|
||||||
log.fine("qty - UOM=" + C_UOM_To_ID
|
|
||||||
+ ", QtyEntered=" + QtyEntered
|
|
||||||
+ " -> " + conversion
|
|
||||||
+ " QtyOrdered=" + QtyOrdered);
|
|
||||||
Env.setContext(ctx, WindowNo, "UOMConversion", conversion ? "Y" : "N");
|
|
||||||
mTab.setValue("QtyOrdered", QtyOrdered);
|
|
||||||
}
|
|
||||||
// QtyOrdered changed - calculate QtyEntered
|
|
||||||
else if (mField.getColumnName().equals("QtyOrdered"))
|
|
||||||
{
|
|
||||||
int C_UOM_To_ID = Env.getContextAsInt(ctx, WindowNo, "C_UOM_ID");
|
|
||||||
QtyOrdered = (BigDecimal)value;
|
|
||||||
QtyEntered = MUOMConversion.convertProductTo (ctx, M_Product_ID,
|
|
||||||
C_UOM_To_ID, QtyOrdered);
|
|
||||||
if (QtyEntered == null)
|
|
||||||
QtyEntered = QtyOrdered;
|
|
||||||
boolean conversion = QtyOrdered.compareTo(QtyEntered) != 0;
|
|
||||||
log.fine("qty - UOM=" + C_UOM_To_ID
|
|
||||||
+ ", QtyOrdered=" + QtyOrdered
|
|
||||||
+ " -> " + conversion
|
|
||||||
+ " QtyEntered=" + QtyEntered);
|
|
||||||
Env.setContext(ctx, WindowNo, "UOMConversion", conversion ? "Y" : "N");
|
|
||||||
mTab.setValue("QtyEntered", QtyEntered);
|
|
||||||
}
|
|
||||||
//
|
|
||||||
setCalloutActive(false);
|
|
||||||
return "";
|
|
||||||
} // qty
|
|
||||||
|
|
||||||
public String qtyLine (Properties ctx, int WindowNo, GridTab mTab, GridField mField, Object value)
|
public String qtyLine (Properties ctx, int WindowNo, GridTab mTab, GridField mField, Object value)
|
||||||
{
|
{
|
||||||
if (isCalloutActive() || value == null)
|
if (isCalloutActive() || value == null)
|
||||||
return "";
|
return "";
|
||||||
setCalloutActive(true);
|
|
||||||
|
|
||||||
int M_Product_ID = Env.getContextAsInt(ctx, WindowNo, "M_Product_ID");
|
final I_PP_Order_BOMLine bomLine = GridTabWrapper.create(mTab, I_PP_Order_BOMLine.class);
|
||||||
if (steps) log.warning("qty - init - M_Product_ID=" + M_Product_ID + " - " );
|
final int M_Product_ID = bomLine.getM_Product_ID();
|
||||||
BigDecimal QtyRequiered, QtyEntered; //, PriceActual, PriceEntered;
|
final String columnName = mField.getColumnName();
|
||||||
|
|
||||||
// No Product
|
// No Product
|
||||||
if (M_Product_ID == 0)
|
if (M_Product_ID <= 0)
|
||||||
{
|
{
|
||||||
QtyEntered = (BigDecimal)mTab.getValue("QtyEntered");
|
BigDecimal QtyEntered = bomLine.getQtyEntered();
|
||||||
mTab.setValue("QtyOrdered", QtyEntered);
|
bomLine.setQtyRequiered(QtyEntered);
|
||||||
}
|
}
|
||||||
// UOM Changed - convert from Entered -> Product
|
// UOM Changed - convert from Entered -> Product
|
||||||
else if (mField.getColumnName().equals("C_UOM_ID"))
|
|
||||||
{
|
|
||||||
int C_UOM_To_ID = ((Integer)value).intValue();
|
|
||||||
QtyEntered = (BigDecimal)mTab.getValue("QtyEntered");
|
|
||||||
QtyRequiered = MUOMConversion.convertProductFrom (ctx, M_Product_ID,
|
|
||||||
C_UOM_To_ID, QtyEntered);
|
|
||||||
if (QtyRequiered == null)
|
|
||||||
QtyRequiered = QtyEntered;
|
|
||||||
boolean conversion = QtyEntered.compareTo(QtyRequiered) != 0;
|
|
||||||
//PriceActual = (BigDecimal)mTab.getValue("PriceActual");
|
|
||||||
//PriceEntered = MUOMConversion.convertProductFrom (ctx, M_Product_ID,
|
|
||||||
// C_UOM_To_ID, PriceActual);
|
|
||||||
//if (PriceEntered == null)
|
|
||||||
// PriceEntered = PriceActual;
|
|
||||||
// log.fine("qty - UOM=" + C_UOM_To_ID
|
|
||||||
// + ", QtyEntered/PriceActual=" + QtyEntered + "/" + PriceActual
|
|
||||||
// + " -> " + conversion
|
|
||||||
// + " QtyOrdered/PriceEntered=" + QtyOrdered + "/" + PriceEntered);
|
|
||||||
Env.setContext(ctx, WindowNo, "UOMConversion", conversion ? "Y" : "N");
|
|
||||||
mTab.setValue("QtyOrdered", QtyRequiered);
|
|
||||||
// mTab.setValue("PriceEntered", PriceEntered);
|
|
||||||
}
|
|
||||||
// QtyEntered changed - calculate QtyOrdered
|
// QtyEntered changed - calculate QtyOrdered
|
||||||
else if (mField.getColumnName().equals("QtyEntered"))
|
else if (I_PP_Order_BOMLine.COLUMNNAME_C_UOM_ID.equals(columnName)
|
||||||
|
|| I_PP_Order_BOMLine.COLUMNNAME_QtyEntered.equals(columnName) )
|
||||||
{
|
{
|
||||||
int C_UOM_To_ID = Env.getContextAsInt(ctx, WindowNo, "C_UOM_ID");
|
final BigDecimal QtyEntered = bomLine.getQtyEntered();
|
||||||
QtyEntered = (BigDecimal)value;
|
BigDecimal QtyRequiered = MUOMConversion.convertProductFrom (ctx, M_Product_ID,
|
||||||
QtyRequiered = MUOMConversion.convertProductFrom (ctx, M_Product_ID,
|
bomLine.getC_UOM_ID(), QtyEntered);
|
||||||
C_UOM_To_ID, QtyEntered);
|
if (QtyRequiered == null) // NO Conversion Found
|
||||||
if (QtyRequiered == null)
|
|
||||||
QtyRequiered = QtyEntered;
|
QtyRequiered = QtyEntered;
|
||||||
boolean conversion = QtyEntered.compareTo(QtyRequiered) != 0;
|
boolean conversion = QtyEntered.compareTo(QtyRequiered) != 0;
|
||||||
log.fine("qty - UOM=" + C_UOM_To_ID
|
Env.setContext(ctx, WindowNo, "UOMConversion", conversion);
|
||||||
+ ", QtyEntered=" + QtyEntered
|
bomLine.setQtyRequiered(QtyRequiered);
|
||||||
+ " -> " + conversion
|
|
||||||
+ " QtyOrdered=" + QtyRequiered);
|
|
||||||
Env.setContext(ctx, WindowNo, "UOMConversion", conversion ? "Y" : "N");
|
|
||||||
mTab.setValue("QtyOrdered", QtyRequiered);
|
|
||||||
}
|
}
|
||||||
// QtyOrdered changed - calculate QtyEntered
|
// QtyOrdered changed - calculate QtyEntered
|
||||||
else if (mField.getColumnName().equals("QtyOrdered"))
|
else if (I_PP_Order_BOMLine.COLUMNNAME_QtyRequiered.equals(columnName))
|
||||||
{
|
{
|
||||||
int C_UOM_To_ID = Env.getContextAsInt(ctx, WindowNo, "C_UOM_ID");
|
final BigDecimal QtyRequiered = bomLine.getQtyRequiered();
|
||||||
QtyRequiered = (BigDecimal)value;
|
BigDecimal QtyEntered = MUOMConversion.convertProductTo (ctx, M_Product_ID,
|
||||||
QtyEntered = MUOMConversion.convertProductTo (ctx, M_Product_ID,
|
bomLine.getC_UOM_ID(), QtyRequiered);
|
||||||
C_UOM_To_ID, QtyRequiered);
|
if (QtyEntered == null) // No Conversion Found
|
||||||
if (QtyEntered == null)
|
|
||||||
QtyEntered = QtyRequiered;
|
QtyEntered = QtyRequiered;
|
||||||
boolean conversion = QtyRequiered.compareTo(QtyEntered) != 0;
|
boolean conversion = QtyRequiered.compareTo(QtyEntered) != 0;
|
||||||
log.fine("qty - UOM=" + C_UOM_To_ID
|
Env.setContext(ctx, WindowNo, "UOMConversion", conversion);
|
||||||
+ ", QtyOrdered=" + QtyRequiered
|
bomLine.setQtyEntered(QtyEntered);
|
||||||
+ " -> " + conversion
|
|
||||||
+ " QtyEntered=" + QtyEntered);
|
|
||||||
Env.setContext(ctx, WindowNo, "UOMConversion", conversion ? "Y" : "N");
|
|
||||||
mTab.setValue("QtyEntered", QtyEntered);
|
|
||||||
}
|
}
|
||||||
//
|
//
|
||||||
setCalloutActive(false);
|
|
||||||
return "";
|
return "";
|
||||||
} // qty
|
} // qty
|
||||||
|
|
||||||
|
@ -260,29 +121,21 @@ public class CalloutBOM extends CalloutEngine
|
||||||
*/
|
*/
|
||||||
public String getdefaults (Properties ctx, int WindowNo, GridTab mTab, GridField mField, Object value)
|
public String getdefaults (Properties ctx, int WindowNo, GridTab mTab, GridField mField, Object value)
|
||||||
{
|
{
|
||||||
Integer M_Product_ID = (Integer)value;
|
|
||||||
if (M_Product_ID == null || M_Product_ID.intValue() == 0)
|
|
||||||
return "";
|
|
||||||
setCalloutActive(true);
|
|
||||||
|
|
||||||
if (isCalloutActive() || value == null)
|
if (isCalloutActive() || value == null)
|
||||||
return "";
|
return "";
|
||||||
|
int M_Product_ID = (Integer)value;
|
||||||
|
if (M_Product_ID <= 0)
|
||||||
|
return "";
|
||||||
|
|
||||||
if (steps) log.warning("parent - init");
|
I_M_Product product = MProduct.get(ctx, M_Product_ID);
|
||||||
|
I_PP_Product_BOM bom = GridTabWrapper.create(mTab, I_PP_Product_BOM.class);
|
||||||
|
bom.setValue(product.getValue());
|
||||||
|
bom.setName(product.getName());
|
||||||
|
bom.setDescription(product.getDescription());
|
||||||
|
bom.setHelp(product.getHelp());
|
||||||
|
bom.setC_UOM_ID(product.getC_UOM_ID());
|
||||||
|
|
||||||
setCalloutActive(true);
|
|
||||||
|
|
||||||
X_M_Product M_Product = new X_M_Product(ctx, M_Product_ID.intValue(),null);
|
|
||||||
|
|
||||||
mTab.setValue("Value", M_Product.getValue());
|
|
||||||
mTab.setValue("Name", M_Product.getName());
|
|
||||||
mTab.setValue("Description", M_Product.getDescription());
|
|
||||||
mTab.setValue("Help", M_Product.getHelp());
|
|
||||||
mTab.setValue("C_UOM_ID", M_Product.getC_UOM_ID());
|
|
||||||
|
|
||||||
setCalloutActive(false);
|
|
||||||
return "";
|
return "";
|
||||||
} // getdefaults
|
} // getdefaults
|
||||||
|
|
||||||
} // CalloutOrder
|
} // CalloutOrder
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue