on ‎2020 Nov 10 11:00 PM
Hello all, hello rzieschang , hello kfrick ,
We have a small method that tries to change the item description when added from a different unit of measure. E.g. When the barcode for a "Coca Cola" is scanned and the barcode belongs to a six-pack, we want to have the description read "Coca Cola - Six-Pack". However we have trouble in both the events BEFORE and AFTER:
@PluginAt(pluginClass=ReceiptPosService.class, method="addSalesItem", where=POSITION.BEFORE)
public void AddSaleItem(Object proxy, Object[] args, StackTraceElement callStack) throws BreakExecutionException
{
ReceiptEntity receipt = (ReceiptEntity)args[0];
receipt.getSalesItems().stream().forEach(item -> {
if(!item.getDescription().contains(item.getQuantityTypeCodeName())
&& !item.getQuantityTypeCode().equals("-1"))
item.setDescription(item.getDescription() + " - " + item.getQuantityTypeCodeName());
});
BroadcasterHolder.INSTANCE.getBroadcaster().broadcastPluginEventForPath("RECEIPT_REFRESH", null);
}
The problem with the BEFORE event above is that the screen doesn't show the updated description until you add another item. It basically always excludes the current item being added.
The problem with the same in the AFTER method is that in FP10 it causes all cash-in/out transactions to fail with an exception, even if we add no plugin code at all:
@PluginAt(pluginClass = ReceiptPosService.class, method = "addSalesItem", where = PluginAt.POSITION.AFTER)
public void UpdateSaleItemAFTER(Object proxy, Object[] args, Object returnValue, StackTraceElement callStack) throws InvalidStateException
{
// do nothing, or anything
}
I'm not sure if the exception caused by this is actually a bug, but I guess it might be.
Do you have any suggestions on properly updating the item description when adding it?
Maybe we have to:
Any pointers would be welcome!
Thanks and best regards,
Joerg.
Request clarification before answering.
Hello joerg.ceo
I forgot that, here the complete construct.
@PluginAt(pluginClass=ReceiptPosService.class, method="addSalesItem", where=POSITION.AFTER)
public Object UpdateSaleItemAFTER(Object proxy, Object args[], Object ret, StackTraceElement stack){
// do nothing, or anything
return ret;
}Best Regards
Klaus
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello Klaus!
That worked! Apparently the returnValue is of a different type depending on whether it's a sales item being added or a cash-in/out transaction. Instead of checking the args.length() we decided to go with checking "returnValue instanceof ReceiptEntity" to escape from any modifications in the case of cash transactions, because we don't know if the args.length() could be changed in a future update.
Thanks again,
Joerg.
Hello joerg.ceo
The AFTER Method should be the right one for this. But it you are using it wrong - it should look like this:
@PluginAt(pluginClass=ReceiptPosService.class, method="addSalesItem", where=POSITION.AFTER)
public Object UpdateSaleItemAFTER(Object proxy, Object args[], Object ret, StackTraceElement stack){
// do nothing, or anything
}
I also do not see any errors. But as this event also occurs with cash-in/cash-out transactions, you have to verify the args.length. When args.length is 2, then it is likely to be a cash-in transaction....
Best Regards
Klaus
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
| User | Count |
|---|---|
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.