cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

update price from plugin

xsalgadog
Participant
0 Likes
234

Good night,

how can I modify the price value from my java code in the plugin.

Thank you.

Accepted Solutions (0)

Answers (1)

Answers (1)

R_Zieschang
Active Contributor
0 Likes

Hello xsalgadog ,

when using the quickservice ui, it should work with something like this:

try (CDBSession cdbSession = CDBSessionFactory.instance.createSession()) {
    ReceiptPosService receiptPosService = ServiceFactory.INSTANCE.getOrCreateServiceInstance(ReceiptPosService.class, cdbSession);
    ReceiptEntity receipt = receiptPosService.findOrCreate(UserRegistry.INSTANCE.getCurrentUser(), null, true);
    CalculationPosService calculationPosService = ServiceFactory.INSTANCE.getOrCreateServiceInstance(CalculationPosService.class, cdbSession);


                receipt.getSalesItems()
                        .stream()
                        .filter(salesItem -> StringUtils.equals(salesItem.getKey(), item.getReference()))
                        .forEach(salesItem -> {
                            salesItem.setUnitGrossAmount(BigDecimal.ONE);
                            salesItem.setUnitPriceChanged(true);
                            salesItem.setMarkChanged(true);
                        });

        calculationPosService.recalculateReceipt(receipt);
        receiptPosService.updateReceipt(receipt, true);
        BroadcasterHolder.INSTANCE.getBroadcaster().broadcastPluginEventForPath("RECEIPT_REFRESH", null);


} catch (InconsistentReceiptStateException e) {
    log.severe(e.getLocalizedMessage());
    log.fine(ExceptionUtils.getFullStackTrace(e));
}

hth

Robert

xsalgadog
Participant
0 Likes

Good morning,

Thanks for the quick response;

How can I make these fields also update in the database? the way it doesn't update

salesItem.setPaymentNetAmount(salesItem.getUnitGrossAmountOrigin());

salesItem.setPaymentTaxAmount(new BigDecimal(77));

thank you