fix budget excluding subtasks getting "fixed" to be negative
authorJacob Lifshay <programmerjake@gmail.com>
Mon, 20 Jun 2022 04:32:13 +0000 (21:32 -0700)
committerJacob Lifshay <programmerjake@gmail.com>
Mon, 20 Jun 2022 04:32:13 +0000 (21:32 -0700)
src/budget_sync/budget_graph.py
src/budget_sync/test/test_budget_graph.py

index de1bed8c7f9d88f7e70fb97c5bb0cd0eb2ae89ee..1577a4b531463f1dcdebdbeed10c13b918751fb0 100644 (file)
@@ -750,8 +750,10 @@ class BudgetGraph:
                     node.fixed_budget_including_subtasks))
 
         def set_excluding_from_including_and_error():
-            node.fixed_budget_excluding_subtasks = \
-                node.budget_including_subtasks - subtasks_total
+            v = node.budget_including_subtasks - subtasks_total
+            if v < 0:
+                return set_including_from_excluding_and_error()
+            node.fixed_budget_excluding_subtasks = v
             errors.append(
                 BudgetGraphMoneyMismatchForBudgetExcludingSubtasks(
                     node.bug.id, root.bug.id,
index bd3a9cb0658765a72ab7943ac524348a37e0e45c..7aaadf5ae04865a2ac2a03b881d28ffa915bf05a 100644 (file)
@@ -893,12 +893,12 @@ alias2 = {paid=2020-03-16,amount=23}
         errors = bg.get_errors()
         self.assertErrorTypesMatches(errors, [
             BudgetGraphNegativeMoney,
-            BudgetGraphMoneyMismatchForBudgetExcludingSubtasks])
+            BudgetGraphMoneyMismatchForBudgetIncludingSubtasks])
         self.assertEqual(errors[0].bug_id, 1)
         self.assertEqual(errors[0].root_bug_id, 1)
         self.assertEqual(errors[1].bug_id, 1)
         self.assertEqual(errors[1].root_bug_id, 1)
-        self.assertEqual(errors[1].expected_budget_excluding_subtasks, -10)
+        self.assertEqual(errors[1].expected_budget_including_subtasks, 0)
         bg = BudgetGraph([
             MockBug(bug_id=1,
                     cf_budget_parent=None,