In the quick start videos, it shows how calculate the amount of an order. However, the price was an attribute of the product entity. What if I have an entity called Price Type and another called price which is composite of PriceType (Same like Order & OrderLine) PriceType being Order and Price being OrderLine. However the Customer has a pricetype when being created. So how can I set the price in the OrderLine from the Price Entity based on the PriceType of the Customer.
I have tried a lot of things, but many of them failed or gave wrong results.
In PriceBrowse, which is used as a lookup screen for selecting prices, change the datasource query depending on the passed PriceType:
public class PriceBrowse extends AbstractLookup {
@WindowParam
private PriceType priceType;
@Inject
private CollectionDatasource<Price, UUID> pricesDs;
@Override
public void init(Map<String, Object> params) {
if (priceType != null) {
pricesDs.setQuery("select e from sales$Price e where e.priceType.id = :param$priceType");
}
}
}
Now when a user selects a Customer for an Order, this Customer’s PriceType will be used to select a Price for all OrderLines.
I am really grateful for all your help on this question and the other one as well. I just have a couple of questions. You said that I have to relate the price in OrderLine with Price table, but the thing is, that’s not part of the design.
generally this IllegalStateException comes from the fact that the view that you are using does not include certain elements of the entity graph you try to access. In this case it will probably be the pricetype attribute of the customer entity. Just look at the OrderLine view you created.
@the haulmont people: Would it be possible to get a “better to understand” exception with a reference to the view ? I oftentimes saw that create some kind of confusion around this exception / problem… That would be cool!
Thank you so much Mario
I really appreciate your response. It really helped me understand a lot of things and solve several problems that I had. However, there is something that I don’t really get. I add another collection data source in the OrderLineEdit which has the customerwithPriceType. however when I try to get the pricetype from the new collectiondatasource, it returns null. I think the problem is that the Customer that I pass to my getPriceType function is a detached object. At least, that’s what was shown when I tried to display the Cusomter that I got. It said [detached] at the end. Check my code below.
Would it be possible to get a “better to understand” exception with a reference to the view ?
This is now a default message for EclipseLink. We’ll think about making it more clear for our case. Pointing to a specific view is hardly possible though.