From d367c1d43f1349d27183d9edab6e16e6bba5d285 Mon Sep 17 00:00:00 2001 From: ydb5755 Date: Wed, 6 Nov 2024 09:17:37 +0200 Subject: [PATCH] update total month cost method for budget --- app/models.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/app/models.py b/app/models.py index ea9d0ba..03b80f4 100644 --- a/app/models.py +++ b/app/models.py @@ -1,5 +1,5 @@ from app import db -from sqlalchemy import Column, INTEGER, String, select +from sqlalchemy import Column, INTEGER, String, select, distinct import datetime class Vendor(db.Model): __tablename__ = 'vendor' @@ -34,11 +34,16 @@ class BudgetCategory(db.Model): def get_total_month_cost(self, month:int, year:int): from .utils import get_month_timestamps first_ts, last_ts = get_month_timestamps(month, year) - lis = self.get_line_items() + line_items = self.get_line_items() + x = list(db.session.execute(select(distinct(LineItem.parent_line_item_id))).scalars().all()) + if None in x: + x.remove(None) requested_month_lis = 0 - for li in lis: - if first_ts < li.date < last_ts: + for li in line_items: + if first_ts < li.date < last_ts and not li.id in x: requested_month_lis += li.amount + elif first_ts < li.date < last_ts: + print(li.amount) return requested_month_lis