on ‎2019 Jun 06 3:23 PM
Hello everyone,
I need to add an article to the receipt. I'm trying to do the following:
CDBSession session = CDBSessionFactory.instance.createSession();
ReceiptManager receiptManager = new ReceiptManager(session);
ReceiptEntity receipt = receiptManager.findOrCreate(UserRegistry.INSTANCE.getCurrentUser(), null, false);
SalesItemEntity sie = new SalesItemEntity();
sie.setExternalId("A00004");
sie.setPercentageDiscount(true);
sie.setDiscountManuallyChanged(true);
sie.setItemDiscountChanged(true);
sie.setQuantity(new BigDecimal(1));
sie.setDescription("articulo ingresado");
sie.setTaxRateTypeCode("IVA19");
sie.setQuantityTypeCode("Manual");
sie.setPriceListId(receipt.getPriceListId());
receiptManager.addSalesItems(receipt, sie, true);
receiptManager.calculate(receipt, EntityActions.Update);
receiptManager.update(receipt);
UIEventDispatcher.INSTANCE.dispatchAction(CConst.UIEventsIds.RECEIPT_REFRESH, null, receipt);
But the receipt is not showing some fields: article id, unit, unit price, gross amount and therefore the total is not updated

What's wrong or what I need to take in account to achieve that?
Request clarification before answering.
Hi ricardo.renteria2 ,
please add a sales item like this:
SalesItemEntity newSalesItem = EntityFactory.INSTANCE.createSalesItemEntity(...);
/...
receiptManager.addSalesItem(newSalesItem);
In your code you are creating an unmanaged sales item entity. Please use the createSalesItemEntity from the EntityFactory class.
Regards
Robert
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I am having similar issue. I have created a test scenerio for my actual problem. The number of lines if greater than 2 should remove all the lines. if maxval=0 the code runs fine and remove the line from front end. but if the maxval = 1 or greater the front end line items are kept visible while they are not available in the backend. PLEASE HELP.
@PluginAt(pluginClass = IReceiptManager.class, method = "addSalesItems", where = POSITION.AFTER)
public void checkSalesItem_Test(Object proxy, Object[] args, Object ret, StackTraceElement Caller) {
if (args.length == 2) {
CDBSession session = CDBSessionFactory.instance.createSession();
ReceiptManager receiptManager = new ReceiptManager(session);
ReceiptEntity receipt = (ReceiptEntity) args[0];
SalesItemEntity saleseItem = (SalesItemEntity) args[1];
List<SalesItemEntity> receiptItems_All1 = receiptManager.getValidSalesItemList(receipt);
int size1 = receiptItems_All1.size();
int maxval = 2;
if(size1>maxval) {
for (int j = 0; j < size1; j++) {
SalesItemEntity entity = receiptItems_All1.get(j);
receiptManager.deleteSalesItem(receipt, entity);
}
receiptManager.calculate(receipt, EntityActions.UPDATE);
receiptManager.update(receipt);
UIEventDispatcher.INSTANCE.dispatchAction(CConst.UIEventsIds.RECEIPT_REFRESH, null, receipt);
}
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
| User | Count |
|---|---|
| 4 | |
| 2 | |
| 1 | |
| 1 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.