Closed
Description
Issue
The current implementation of budget validation needs some refactor. On large sites, Purchase Orders with 100 items timeout while submitting.
Bottlenecks
Unavoidable nested-loop
Purchase Order can have any number of Items 'I', each item can have any number of dimensions 'D', and each dimension can have budgets for different fiscal years 'B'.
This structure lends itself to be handled by nested-loop - (I x D x B), like so
for x in item / gl entry:
for dim in all_dimensions:
for budget in all_budgets:
calculate_and_validate_expenses()
Methods are too generic
validate_expense_against_budget()
is too generic. It implicitly handles individual GL Entries and 'Items' (from Purchase Order) passed as args.