I am having trouble with a sum aggregation. I am performing a sum on a table called orderitems, on a field called linetotal, which is worked out via quantity * price, a fairly basic thing to do. The problem is that if I add to orderitems via a formindialog, the aggregate function doesn’t seem fire, so I can add items to an order without the total being updated. The aggregation is used in a stored calculation on an orders table, to work out the current total for an order:
var totaldiscounts = discount + preorders_to_credits_total.orderCreditsTotal;
var totalcharges = deliverycharge + surcharge + vat;
return (preorders_to_preorderitems.agg_sum_orderItemsLineTotals + totalcharges) - totaldiscounts;
When I add most items to an order, the total updates. However I have to add pizza toppings via a formindialog to ensure that they are associated with a pizza item and it’s these items that are not counted in the total when they’re added to an order. HOWEVER! If I add say three toppings ($0.50) to a pizza ($1.00) for a total of $2.50, then delete one topping, the total updates showing the new correct total for pizza + two toppings ($2.00).
I am at a loss as to why this is happening, and it is rather a large problem. Any ideas?
Just tried the latest beta (2.2.1 rc2 is what the announcement says, but 2.2.2 build 328 is what shows up in the Help > About dialog) and this problem is still present.
be carefull with stored calculations and aggregates.
first you have to had every record in view (on the form), before, the calc is really calculated. (saved to the DB) Only THAN the aggregate will work.
if you want to be 100% sure, you have to do: databasemanager.recalculate(foundset) first!
(but that can be a real time consuming thing if you have thousands of records in your foundset.)