foodcoop-adam / foodsoft

DEPRECATED, being merged in upstream. Web-based software for foodcoops - as used in NL.
http://foodcoop-adam.github.io/
Other
10 stars 3 forks source link

[vokomokum] synchronize order amounts #106

Closed wvengen closed 10 years ago

wvengen commented 10 years ago

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:

wvengen commented 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)}
tg-x commented 10 years ago

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.

tg-x commented 10 years ago

As I see Order.finish calls GroupOrder.update_price!, so that should already work.

wvengen commented 10 years ago

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.