Closed wvengen closed 10 years ago
For code, see the vokomokum plugin in lib/foodsoft_vokomokum
. Uploading totals is done using #upload_amounts
. Pass a hash of {ordergroup_id => sum}
s to it, like this csv export; or to export the total of the current user's unsettled orders:
ordergroup = current_user.ordergroup
group_orders = ordergroup.group_orders.includes(:order).where(orders: {state: ['open', 'finished']})
amounts = {ordergroup.id => group_orders.sum(:price)}
We also need to upload amounts after changing the order from open to finished.
The export_amounts CSV should group the orders by type, as that's the way the manual upload expects it.
As I see Order.finish calls GroupOrder.update_price!, so that should already work.
Functionality is done! I've tested opening, closing and settling an order, as well as updating order amounts when the order is closed. All works! Let's open a new bug for testing if we want to.
As a side note, deleting a closed order also works (updating the dry goods system), but takes a lot of time; a future improvement may be to also do the update once in batch. But, as that's not likely to happen often or even at all, it's ok for now.
Vokomokum's existing ordering system needs to receive totals of the fresh orders. For every order cycle, there are totals for "Groente", "Kaas" and "Misc.".
How to get totals from foodsoft into the Vokomokum ordering system?
The plan is as follows:
GroupOrder#update_price!
.114: Handling account balance
115: Handling errors gracefully
131: Group export_amounts CSV by type