Listener solution

Hi,

I have a specific situation with 3 entities: InvoiceLine is nested in Invoice and Invoice is nested in Transaction.
Transaction - Invoice (one-to-many), Invoice-InvoiceLine(One-to-many).
Furthermore in InvoiceLine I have a (many-to-one) relation with PriceList.

According to invoice enum (usd/eur) I have to choose different prices (in list).

I chosen Datasource Listener like in Sales example.

My problem is that the data is committed in database only once, if I open again the Invoice window and change the enum value the data remains the same.

With Entity listeners (onbeforeinsert and onbeforeupdate) the data is committed ok in database (at save time) but when I choose a new description (price and name) I cannot see them in UI (only if I logout/login).

Part of my code (invoiceEdit):

Invoice item = invoiceDs.getItem();
   invoiceLineDs.addCollectionChangeListener(event -> {
if (entity.getCurrency() == InvCurrencyEnum.usd) {
    BigDecimal amount = BigDecimal.ZERO;
    for (InvoiceLine line : invoiceLineDs.getItems()) {

        line.setNameline(line.getDescription().getName());
        line.setPriceline(line.getDescription().getPrice());
        amount = amount.add(line.getPriceline().multiply(line.getQuantity()));
    }
    entity.setAmount(amount);
}
}

This is because when I change the enum from eur to usd or vice versa, addCollectionChangeListener is not changed.

Is there any workaround?

I tried to added an addItemChangeListener but the amount is set only if I close and open the invoice screen.
I don’t understand why is not set when I close the screen.

 invoiceDs.addItemChangeListener(inv -> {

            Invoice item = invoiceDs.getItem();


            if (item.getCurrency()!=null){
                getItem().setAmount(getItem().getAmount());
                commit();

            }