Hi, i have a screen code :
package com.company.imgestion.gui.presupuestos;
import com.haulmont.cuba.core.global.DataManager;
import com.haulmont.cuba.core.global.Metadata;
import com.haulmont.cuba.gui.components.AbstractEditor;
import com.company.imgestion.entity.Presupuestos;
import com.company.imgestion.entity.PresupuestosLineas;
import com.haulmont.cuba.gui.components.actions.EditAction;
import com.haulmont.cuba.gui.data.CollectionDatasource;
import com.haulmont.cuba.gui.data.Datasource;
import javax.inject.Inject;
import javax.inject.Named;
import java.math.BigDecimal;
import java.util.Map;
import java.util.UUID;
import com.haulmont.cuba.gui.components.Component;
public class PresupuestosEdit extends AbstractEditor<Presupuestos> {
/*VARIABLES NECESARIAS PARA TRABAJAR CON LA BDD Y TRATAR OTRAS TABLAS EN EL ENTORNO*/
@Inject
private DataManager dataManager;
@Inject
private Metadata metadata;
/*DEFINIMOS LA TABLA CON LA QUE TRABAJAREMOS, ESTA TABLA ES LA QUE TIENE EL XML VINCULADO EN LA PANTALLA*/
@Inject
private CollectionDatasource<PresupuestosLineas, UUID> lineasDs;
/*LE AÑADISMO EL LISTENER DE CAMBIOS*/
@Override
public void init(Map<String, Object> params) {
lineasDs.addCollectionChangeListener(e -> calculartotal());
lineasDs.addItemPropertyChangeListener(e -> calculartotallinea());
/*lineasDs.refresh();*/
}
/*CALCULAMOS VALORES*/
private void calculartotal() {
/*IMPORTE TOTAL PRESUPUESTO*/
/*DEFINIMOS VARIABLES NECESARIAS*/
BigDecimal importe = BigDecimal.ZERO;
BigDecimal importeiva = BigDecimal.ZERO;
BigDecimal importerecargo = BigDecimal.ZERO;
/*VAMOS RECALCULANDO LOS TOTALES POR CADA LINEA Y ASIGNANDOLOS A LAS VARIABLES*/
/*SIEMPRE SUMAMOS EN LAS VARIABLES*/
for (PresupuestosLineas linea : lineasDs.getItems()) {
importe = importe.add(linea.getImportebases());
if (getItem().getClientes() != null && getItem().getClientes().getRecargo()){
importerecargo = importerecargo.add(linea.getImporterecargo());
}
importeiva = importeiva.add(linea.getImportecuotas());
}
/*ASIGNAMOS VALORES A LOS CAMPOS*/
getItem().setImporteBase(importe);
getItem().setImporteCuotas(importeiva);
getItem().setImporteRecargos(importerecargo);
/*SUMAMOS LAS TRES VARIABLES EN EL MISMO PROCESO.*/
getItem().setImporteTotal(importe.add(importeiva.add(importerecargo)));
}
private void calculartotallinea() {
if (lineasDs.getItem().getArticulo() != null && lineasDs.getItem().getDescripcion() == null){
lineasDs.getItem().setDescripcion(lineasDs.getItem().getArticulo().getNombre());
}
if (lineasDs.getItem().getDescripcion() != null && (lineasDs.getItem().getUnidades() != null) && (lineasDs.getItem().getDescuento() != null) && (lineasDs.getItem().getPrecio() != null)) {
/*showNotification(getMessage("selectBook.text"), NotificationType.HUMANIZED);*/
BigDecimal totallinea = BigDecimal.ZERO;
BigDecimal importelinea = BigDecimal.ZERO;
BigDecimal importedescuento = BigDecimal.ZERO;
BigDecimal preciounitario = lineasDs.getItem().getPrecio();
BigDecimal precioBASE = lineasDs.getItem().getPrecio();
BigDecimal unidades = lineasDs.getItem().getUnidades();
/*PRECIO UNITARIO CON DESCUENTO DE LA LINEA*/
BigDecimal porcentaje, dto;
porcentaje = new BigDecimal("100");
dto = lineasDs.getItem().getDescuento();
/*ASIGNAMOS PRECIO DE LA LINEA*/
preciounitario = lineasDs.getItem().getPrecio();
precioBASE = preciounitario.multiply(unidades);
/*LE APLICAMOS EL DESCUENTO PARA SABER PRECIO NETO*/
preciounitario = preciounitario.subtract(preciounitario.divide(porcentaje).multiply(dto));
/*PRECIO TOTAL DE LA LINEA CON DESCUENTOS*/
importelinea = unidades.multiply(preciounitario);
lineasDs.getItem().setImportebases(importelinea);
/*Colocamos valores internos*/
/*Importe de Descuento*/
lineasDs.getItem().setImporteDescuento(precioBASE.subtract(importelinea));
/*Importe total de linea, pero OJO aun no tiene en cuenta IMPUESTOS*/
lineasDs.getItem().setImportetotal(importelinea);
}
calculartotal();
}
public void addlinedirectly(Component source) {
BigDecimal cero = BigDecimal.ZERO;
PresupuestosLineas lineas = metadata.create(PresupuestosLineas.class);
lineas.setDescripcion("");
lineas.setCabecera(getItem());
dataManager.commit(lineas);
lineasDs.refresh();
calculartotal();
}
}
and the Screen attached has a button that call the method addlinedirectly, but, after the insert the lineasDs.Refresh() not refresh, i need to close and reopen Screen.
How can i fix this?