2
I’d like help finding a calculated field. The problem is that it involves relationships.
I need to calculate the total of a Sale with various Sales Items (products). Partial total per Item of Sale (product price * quantity) is calculated correctly.
But when I go to valvular the total of the Sale the total of the Sale Item comes null, in these codes:
// Item de Venda
@Transient
private Double total;
// Este código funciona ao consultar os itens de venda (separadamente)
public Double getTotal() {
return this.product.getPrice() * this.quantity;
}
// Venda
@Transient
private Double total;
public Double getTotal() {
if (!sellItems.isEmpty()) {
for (SellItem item : sellItems){
// Essa linha dá NullPointer pois o valor é null.
this.total += item.getTotal();
}
}
return this.total;
}
Look at my answer here, please =)
– Sérgio Mucciaccia