At the moment, validation of transaction existence does not occur before budget deletion.
According with new requirements : The user should only be able to delete a budget that has 0 transactions. It does not matter if it is for the current fiscal year, past year or upcoming year.
Additionally, the link between the group_fund_fiscal_year and the budget tables must be removed before deleting, to be able to delete the budget.
Upon budget deletion:
- find all transactions : query = ((transaction.toFundId=budget.fundId or transaction.fromFundId=budget.fundId) and transaction.fiscalYearId=budget.fiscalYearID) and get number of returned transactions. If the number is greater than 0, then deleting the budget is prohibited.
- find all groupFundFiscalYear by budget.fundId and budget.fiscalYearId and clear groupFundFiscalYear.budgetId field
Logic should be implemented in storage module to minimize data inconsistency in case below:
Deleting a budget is not an atomic operation, since we must first check for transactions and only then delete the budget.
There is a a slight chance, that between these two operations the transaction will be created by someone else and it will remain tied to a nonexistent budget.
The business logic described above has been added
Unit tests are updated
API tests are updated (mod-finance)