From 4340381f8ef7db6a32ce0279e631d029c28b9083 Mon Sep 17 00:00:00 2001 From: Brian Ryall Date: Fri, 28 Jun 2024 18:33:52 -0400 Subject: [PATCH] fix: allow more than one allocate in a given month --- .../modules/beancount_envelope.py | 35 +++++++++++++------ 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/src/fava_envelope/modules/beancount_envelope.py b/src/fava_envelope/modules/beancount_envelope.py index 8245d7d..606893f 100644 --- a/src/fava_envelope/modules/beancount_envelope.py +++ b/src/fava_envelope/modules/beancount_envelope.py @@ -348,15 +348,15 @@ def _calculate_budget_activity(self): temp ) else: - self.envelope_df.loc[ - account, (month_str, "budgeted") - ] = Decimal(0.00) - self.envelope_df.loc[ - account, (month_str, "activity") - ] = Decimal(temp) - self.envelope_df.loc[ - account, (month_str, "available") - ] = Decimal(0.00) + self.envelope_df.loc[account, (month_str, "budgeted")] = ( + Decimal(0.00) + ) + self.envelope_df.loc[account, (month_str, "activity")] = ( + Decimal(temp) + ) + self.envelope_df.loc[account, (month_str, "available")] = ( + Decimal(0.00) + ) def _calc_budget_budgeted(self): # rows = {} @@ -364,6 +364,21 @@ def _calc_budget_budgeted(self): if isinstance(e, Custom) and e.type == self.etype: if e.values[0].value == "allocate": month = f"{e.date.year}-{e.date.month:02}" + try: + _ = self.envelope_df.loc[ + e.values[1].value, (month, "budgeted") + ] + except KeyError: + self.envelope_df.loc[ + e.values[1].value, (month, "budgeted") + ] = Decimal(0.00) + self.envelope_df.loc[ e.values[1].value, (month, "budgeted") - ] = Decimal(e.values[2].value) + ] = Decimal( + self.envelope_df.loc[ + e.values[1].value, (month, "budgeted") + ] + ) + Decimal( + e.values[2].value + )