Ejemplo n.º 1
0
    def _update_buckets_from_dataframe(self, account: Account, df: pd.DataFrame):
        try:
            logging.debug(df.dtypes)
            for index, row in df.iterrows():
                name = row['name']
                logging.debug(row)
                dsvca.update_bucket(account, name,
                                    priority=int(row["priority"]),
                                    due_day_of_month=int(row["due_day_of_month"]),
                                    spend_category=SpendCategory[row["spend_category"].upper()],
                                    base_budget_amount=float(row["base_budget_amount"]),
                                    perc_budget_amount=float(row["perc_budget_amount"]),
                                    waterfall_amount=float(row["waterfall_amount"]),
                                    saved_amount=float(row["saved_amount"]),
                                    percent_of_income_adjustment_amount=float(row["percent_of_income_adjustment_amount"]),
                                    provider=row["provider"] if pd.notna(row["provider"]) else "",
                                    payment_account=row["payment_account"] if pd.notna(row["payment_account"]) else "",
                                    payment_method=PaymentMethod[row["payment_method"].upper()] if pd.notna(row["payment_method"]) else ""
                                    )

            bucket_names_imported = set(x.upper() for x in df['name'])
            buckets = dsvca.buckets_by_account(account)
            for bucket in buckets:
                if bucket.name.upper() not in bucket_names_imported:
                    dsvca.delete_bucket_from_account(account, bucket.name)

            return True


        except Exception as e:
            error = f"Unable to import the dataset: {e}"
            self.uns.notify_user(error)
            self.uns.notify_user(df.columns)
            return False
Ejemplo n.º 2
0
    def delete_account(self, ledgerManager, account:Account=None):
        account = account if account else self.uns.select_account()
        if account is None:
            return

        yousure = self.uns.request_you_sure("Are you sure? This will break all reference to this account!")
        if yousure is None:
            return

        if yousure == "Yes":
            buckets = dsvca.buckets_by_account(account)

            waterfall_amt = 0
            saved_amt = 0
            for bucket in buckets:
                waterfall_amt += bucket.waterfall_amount
                saved_amt += bucket.saved_amount

            okay_to_delete = False
            if((waterfall_amt > 0) or (saved_amt > 0)):
                yousure = self.uns.request_you_sure("Funds in account. Are you sure?")
                if yousure is None:
                    return

                if yousure == "Yes":
                    okay_to_delete = True
            else:
                okay_to_delete = True

            if okay_to_delete:
                dsvca.delete_account(account.account_name)
                self.uns.notify_user(f"Account {account.account_name} Deleted")
            else:
                self.uns.notify_user(f"Deletion Cancelled.")
Ejemplo n.º 3
0
    def print_waterfall_buckets(self, account: Account = None):
        account = account if account else self.uns.select_account()

        buckets = dsvca.buckets_by_account(account)
        data = mongoHelper.list_mongo_to_pandas(buckets)
        data.sort_values(by=["priority", 'due_day_of_month'], inplace=True)

        self.uns.pretty_print_items(data)
Ejemplo n.º 4
0
    def cycle_waterfall(self, account:Account=None):
        account = account if account else self.uns.select_account()
        buckets = dsvca.buckets_by_account(account)

        for bucket in buckets:
            self._cycle_bucket(account, bucket)

        self.uns.notify_user(f"{account.account_name} cycled")
Ejemplo n.º 5
0
    def get_add_waterfall_funds_input(self, account: Account):
        ret = {}
        ret['amount'] = self.request_float("Amount to add:", forcePos=True)
        ret['description'] = self.request_string("Description: ")
        ret['date'] = self.request_date()
        ret['notes'] = self.request_string("Notes: ")
        ret['buckets'] = dsvca.buckets_by_account(account)

        return ret
Ejemplo n.º 6
0
    def positive_remaining_buckets(self, account: Account=None, amount_threshold: float = None):
        account = account if account else self.uns.select_account()

        buckets = dsvca.buckets_by_account(account)
        data = mongoHelper.list_mongo_to_pandas(buckets)
        filtered = data[data["saved_amount"] > 0].sort_values(by=["priority"])

        if amount_threshold is not None:
            filtered = filtered[filtered['saved_amount']>amount_threshold]

        return filtered
Ejemplo n.º 7
0
    def save_buckets_as_csv(self, account: Account = None):
        account = account if account else self.uns.select_account()

        buckets = dsvca.buckets_by_account(account)
        data = mongoHelper.list_mongo_to_pandas(buckets)

        filepath = self.uns.request_save_filepath()

        data.to_csv(filepath)
        if data is None:
            return

        self.uns.notify_user(f"Buckets data written successfully to {filepath}")
Ejemplo n.º 8
0
    def print_waterfall_summary(self, account: Account = None):
        account = account if account else self.uns.select_account()

        buckets = dsvca.buckets_by_account(account)
        data = mongoHelper.list_mongo_to_pandas(buckets)

        waterfall_amount = data['waterfall_amount'].sum()
        saved_amount = data['saved_amount'].sum()

        total_saved = waterfall_amount + saved_amount
        self.uns.notify_user(f"\n------Waterfall Summary------\n"
                             f"Total Balance: ${round(total_saved, 2)}\n"
                             f"Saved for next cycle: S{round(saved_amount, 2)}", delay_sec=0)
Ejemplo n.º 9
0
 def allocated_total(self, account: Account):
     buckets = dsvca.buckets_by_account(account)
     return sum(b.saved_amount + b.waterfall_amount for b in buckets)
Ejemplo n.º 10
0
 def print_buckets(self, account:Account=None):
     account = account if account else self.uns.select_account()
     buckets = dsvca.buckets_by_account(account)
     self.uns.notify_user("\n------Buckets------", delay_sec=0)
     self.uns.pretty_print_items(sorted(buckets, key=lambda x: x.priority),
                                 title=CollectionType.BUCKETS.name)