update total month cost method for budget
This commit is contained in:
parent
a2f9cc31f5
commit
d367c1d43f
1 changed files with 9 additions and 4 deletions
|
|
@ -1,5 +1,5 @@
|
||||||
from app import db
|
from app import db
|
||||||
from sqlalchemy import Column, INTEGER, String, select
|
from sqlalchemy import Column, INTEGER, String, select, distinct
|
||||||
import datetime
|
import datetime
|
||||||
class Vendor(db.Model):
|
class Vendor(db.Model):
|
||||||
__tablename__ = 'vendor'
|
__tablename__ = 'vendor'
|
||||||
|
|
@ -34,11 +34,16 @@ class BudgetCategory(db.Model):
|
||||||
def get_total_month_cost(self, month:int, year:int):
|
def get_total_month_cost(self, month:int, year:int):
|
||||||
from .utils import get_month_timestamps
|
from .utils import get_month_timestamps
|
||||||
first_ts, last_ts = get_month_timestamps(month, year)
|
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
|
requested_month_lis = 0
|
||||||
for li in lis:
|
for li in line_items:
|
||||||
if first_ts < li.date < last_ts:
|
if first_ts < li.date < last_ts and not li.id in x:
|
||||||
requested_month_lis += li.amount
|
requested_month_lis += li.amount
|
||||||
|
elif first_ts < li.date < last_ts:
|
||||||
|
print(li.amount)
|
||||||
return requested_month_lis
|
return requested_month_lis
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue