Detached but with Info in View

Hi, i’m getting error of detached entity, see screenshot detached1.PNG. i’m getting error:

IllegalStateException: Cannot get unfetched attribute [tarifa] from detached object com.company.imgestion.entity.Clientes-a32e75a0-fd1d-590a-0b66-decc409b5644 [detached].

, and you can see in capture 2 and 3 in entity exists the related entity.

detached1

Captura2

Captura3

This is de CODE and line with problems is :

.setParameter(“tarifa”,presupuestosLineasDs.getItem().getCabecera().getClientes().getTarifa().getId()));


package com.company.imgestion.web.presupuestoslineas;

import com.haulmont.cuba.core.global.DataManager;
import com.haulmont.cuba.core.global.LoadContext;
import com.haulmont.cuba.gui.components.AbstractEditor;
import com.company.imgestion.entity.PresupuestosLineas;
import com.company.imgestion.entity.Presupuestos;
import com.company.imgestion.entity.Clientes;
import com.company.imgestion.entity.ArticulosPvp;
import com.haulmont.cuba.gui.data.Datasource;

import javax.inject.Inject;
import java.math.BigDecimal;
import java.util.Map;

public class PresupuestosLineasEdit extends AbstractEditor<PresupuestosLineas> {

    /*DEFINIMOS ENTORNO DE DATOS*/
    @Inject
    private Datasource<PresupuestosLineas> presupuestosLineasDs;
    private Datasource<ArticulosPvp> TarifasDs;
    private Datasource<Clientes> ClientesDs;

    @Inject
    private DataManager dataManager;

    @Override
    public void init(Map<String, Object> params) {
        presupuestosLineasDs.addItemChangeListener( e -> calculartotallinea());
        presupuestosLineasDs.addItemPropertyChangeListener(e -> calculartotallinea());
    }
    private void  calculartotallinea() {
        if (presupuestosLineasDs.getItem().getArticulo() != null && presupuestosLineasDs.getItem().getDescripcion() == null){
            presupuestosLineasDs.getItem().setDescripcion(presupuestosLineasDs.getItem().getArticulo().getNombre());

            LoadContext<ArticulosPvp> context = LoadContext.create(ArticulosPvp.class).setQuery(
                    LoadContext.createQuery("select pp from imgestion$ArticulosPvp pp where pp.articulo.id = :productid and pp.tarifa.id = :tarifa")
                            .setParameter("productid",presupuestosLineasDs.getItem().getArticulo().getId())
                            .setParameter("tarifa",presupuestosLineasDs.getItem().getCabecera().getClientes().getTarifa().getId()));
            ArticulosPvp pp = dataManager.load(context);

            if ((pp != null) && (pp.getPvp() != null)) {
                BigDecimal price = pp.getPvp();
                presupuestosLineasDs.getItem().setPrecio(price);
            }

            /*Si tuvieramos un precio Base de producto lo podriamos definir a continuacion del if.*/
            /*else presupuestosLineasDs.getItem().setPrecio(presupuestosLineasDs.getItem().getProducto().getPrecioBase());*/
        }

        if (presupuestosLineasDs.getItem().getDescripcion() != null && (presupuestosLineasDs.getItem().getUnidades() != null) && (presupuestosLineasDs.getItem().getDescuento() != null) && (presupuestosLineasDs.getItem().getPrecio() != null)) {
            /*showNotification(getMessage("selectBook.text"), NotificationType.HUMANIZED);*/
            BigDecimal totallinea = BigDecimal.ZERO;
            BigDecimal importelinea = BigDecimal.ZERO;
            BigDecimal importedescuento = BigDecimal.ZERO;

            importelinea = presupuestosLineasDs.getItem().getUnidades().multiply(getItem().getPrecio());

            BigDecimal porcentaje, dto, cero ;
            porcentaje = new BigDecimal("100");
            cero = new BigDecimal("0");
            dto = getItem().getDescuento();
            importedescuento = importelinea.divide(porcentaje).multiply(dto);

            totallinea = importedescuento;
            totallinea = importelinea.subtract(importelinea.divide(porcentaje).multiply(dto));

            getItem().setImportetotal(totallinea);
        }
    }
}

I see Errors is allways in third Level of view

For Example in Field Lines.Descripcion i can put values from:

Lines.Cabecera.Cliente.Nombre

but i cannot put value

Lines.Cabecera.Cliente.Vendedor.Nombre (this is detached)

Hi
I have tried to reproduce the problem as described (created a project with multiple associated entities created views, screens) and did not find any faults.
Could you prepare a simple project which will show the issue and share it here?
Also describe some steps which should I do to reproduce the problem.

Hi, i’ve attached project, you need to create a Customer, product, family, and taxrate, Rate, and productprice and then go to Sales / Quotes (presupuestos), and add a new pressupuesto.

  1. in Screen Presupuestos-edit , we have a button names añadirlinea. This button calls a method that adds a line in Grid. This line is not visible until i close and reopen Screen.

  2. In same Screen, when you use a button to add line (normal button (second button)) it open Prespupuestos-lineas-edit, when you select an Product, you give the Detached messages.

  3. We need in Screen Presupuestos-edit to set the layou on the 100% of the screen, then the GroupBOX (cabecera) we need to set fix on TOP of the Page, the GroupBOX(totales) on BOTTOM of the Page, and then the GroupBox(lineasBox) in available center, with Scroll if the lines pass the available Space. We have been teste several configurations, and cannot make this :(. Can you see how can i make this?

  4. In Articulos-edit, i need when i add a new Articulo, we need to add lines in ArticulosPrecios Grid for Each Tarifa existent in Database with price = 0, with this method, you can add a new articulo and set the prices in same moment, for all available rates.

  5. Then i’ve detected this: If you create a new Quote, and you use button to add line in Table, you get error of you are working with a new entity of quote, but, if you use Add button (opens a lines edit), it works fine.

iMGestion.zip (191.8K)

The points: 1, 4, 5 is solved. We need only support for 2 and 3.

Thanks!

Hi
On the second question.
When the property is selected by the use of pickerField, the chosen entity is loaded with the view adjusted for the entity browse screen.
In your Articulos.browse screen the “_local” view is chosen for the articulosesDs. So that is why the Product is loaded without IVA.
The easiest way to solve the problem is to switch the articulosesDS to articulos-view(which contains IVA fields).

On the third.
It seems the following screen should meet your requirements.

  1. fixed height is adjusted for cabecera and totales boxes.
  2. lineas is put between cabecera and totales
  3. Scrollbox is removed
  4. For the Layout expand=“lineasBox” is specified.

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<window xmlns="[url=http://schemas.haulmont.com/cuba/window.xsd]http://schemas.haulmont.com/cuba/window.xsd"[/url];
        caption="msg://editCaption"
        class="com.company.imgestion.gui.presupuestos.PresupuestosEdit"
        datasource="presupuestosDs"
        focusComponent="fieldGroup"
        messagesPack="com.company.imgestion.gui.presupuestos">
    <dsContext>
        <datasource id="presupuestosDs"
                    class="com.company.imgestion.entity.Presupuestos"
                    view="presupuestos-view">
            <collectionDatasource id="lineasDs"
                                  property="lineas"/>
        </datasource>
    </dsContext>
    <layout expand="lineasBox"
            spacing="true">
        <groupBox id="Cabecera"
                  caption="Datos Cabecera"
                  height="150px">
            <fieldGroup id="fieldGroup"
                        datasource="presupuestosDs"
                        height="100%">
                <column>
                    <field id="periodo"
                           editable="false"
                           width="60px"></field>
                    <field id="vendedor"
                           width="250px"></field>
                </column>
                <column width="60px">
                    <field id="numero"></field>
                </column>
                <column width="250px">
                    <field id="formapago"></field>
                    <field id="fecha"></field>
                </column>
                <column width="250px">
                    <field id="clientes"></field>
                </column>
                <column width="250px">
                    <field id="comentarios"
                           rows="5"></field>
                </column>
            </fieldGroup>
        </groupBox>
        <groupBox id="lineasBox"
                  caption="msg://com.company.imgestion.entity/Presupuestos.lineas"
                  spacing="true">
            <table id="lineasTable"
                   aggregatable="true"
                   editable="true"
                   height="100%"
                   width="100%">
                <actions>
                    <action id="create"></action>
                    <action id="edit"></action>
                    <action id="remove"></action>
                </actions>
                <columns>
                    <column id="articulo"
                            editable="true"
                            width="150"/>
                    <column id="descripcion"
                            editable="true"/>
                    <column id="unidades"
                            editable="true"
                            width="75"/>
                    <column id="precio"
                            editable="true"
                            width="75"/>
                    <column id="descuento"
                            editable="true"
                            width="75"/>
                    <column id="porcentajeIva"
                            caption="% Iva"
                            width="75"/>
                    <column id="importebases"
                            caption="Importe"
                            width="75"/>
                    <column id="importeDescuento"
                            width="75"/>
                    <column id="articulo.iva.iva"/>
                </columns>
                <rows datasource="lineasDs"></rows>
                <rowsCount></rowsCount>
                <buttonsPanel>
                    <button id="añadirlinea"
                            caption="añadirLinea"
                            invoke="addlinedirectly"></button>
                    <button id="testmeBTN"
                            caption="testme"
                            invoke="testME"></button>
                    <button id="lestLineBTN"
                            caption="test Line"
                            invoke="testLine"></button>
                    <button action="lineasTable.create"
                            caption="msg://crear"></button>
                    <button action="lineasTable.edit"
                            caption="msg://Editar"></button>
                    <button action="lineasTable.remove"
                            caption="msg://borrar"></button>
                </buttonsPanel>
            </table>
        </groupBox>
        <groupBox id="Totales"
                  align="BOTTOM_RIGHT"
                  caption="Totales"
                  collapsed="true"
                  height="150px"
                  spacing="true">
            <fieldGroup id="Pies Documento"
                        border="visible"
                        datasource="presupuestosDs"
                        height="100%">
                <column width="250px">
                    <field id="importeBase"
                           editable="false"></field>
                    <field id="importeCuotas"
                           editable="false"></field>
                    <field id="importeTotal"
                           editable="false"></field>
                </column>
            </fieldGroup>
        </groupBox>
        <frame id="windowActions"
               screen="extendedEditWindowActions"></frame>
    </layout>
</window>

Thanks!!! All is ok!!! in mi mind, all time we have the presupuestosline view… i cannot mind in naviation to products browse screen…

;/