Hello,
I have to do a simple customization validation for the field PriceList in the order line table. If the field be equal 0, the client can't save the record. So, I create a new EventHandler as you can see in the code below, but the system never execute my class:
public class CompanyEventHandler extends AbstractEventHandler
{
private static CLogger log = CLogger.getCLogger(CompanyEventHandler.class);
//constants
public static final String MESSAGE_PRICELIST_ZERO = "O valor do preço de lista não pode ser 0";
protected void initialize()
{
registerEvent(IEventTopics.AFTER_LOGIN);
registerTableEvent(IEventTopics.PO_BEFORE_CHANGE, MOrderLine.Table_Name);
registerTableEvent(IEventTopics.PO_BEFORE_NEW, MOrderLine.Table_Name);
}
protected void doHandleEvent(Event event)
{
log.info("starting.. Topic :" + event.getTopic());
if (event.getTopic().equals(IEventTopics.AFTER_LOGIN))
{
return;
}
PO po = getPO(event);
if (po instanceof MOrderLine
&& (event.getTopic().equals(IEventTopics.PO_BEFORE_CHANGE) ||
event.getTopic().equals(IEventTopics.PO_BEFORE_NEW)))
{
MOrderLine mOrderLine = (MOrderLine) po;
if (mOrderLine.getPriceList().equals(new BigDecimal(0)))
{
throw new AdempiereException(MESSAGE_PRICELIST_ZERO);
}
}
}
}
I put breakpoints in the beginning of the two methods and the system never execute the class. I follow the instructions of this tutorial
https://www.youtube.com/watch?v=zc_Ye8WZ-jc without sucess. I would be greatful if someone can help me.