start overhead accounts
This commit is contained in:
parent
1d36d99462
commit
006b488c63
2
.gitignore
vendored
2
.gitignore
vendored
@ -5,4 +5,4 @@ api/config/authservice.pub
|
||||
cli/config/dbconfig.ini
|
||||
*~
|
||||
.*~
|
||||
|
||||
.vscode/
|
||||
|
68
cli/OverheadAccounts.py
Normal file
68
cli/OverheadAccounts.py
Normal file
@ -0,0 +1,68 @@
|
||||
from db import dbGetMany
|
||||
import datetime
|
||||
from loguru import logger
|
||||
|
||||
def perform(dbh, params):
|
||||
try:
|
||||
year = params['year']
|
||||
except KeyError:
|
||||
year = datetime.datetime.today().year
|
||||
startDate = datetime.datetime(year, 1, 1, 0, 0, 0)
|
||||
endDate = datetime.datetime(year, 12, 31, 23, 59, 59)
|
||||
premises = (1, 2)
|
||||
|
||||
|
||||
# get flat tenants by object and timespan with paid overhead and due overhead
|
||||
|
||||
|
||||
# get overhead sums by object, category and timespan
|
||||
overheadSums = dbGetMany(
|
||||
dbh,
|
||||
{
|
||||
"statement":
|
||||
"""
|
||||
select sum(ae.amount) as sum,
|
||||
aec.description as category,
|
||||
p.id as house_id,
|
||||
p.description as house
|
||||
from account_t a,
|
||||
premise_t p,
|
||||
account_entry_t ae,
|
||||
account_entry_category_t aec
|
||||
where p.account = a.id and
|
||||
ae.account = a.id and
|
||||
aec.overhead_relevant = 't' and
|
||||
ae.account_entry_category = aec.id and
|
||||
created_at between %(startDate)s and %(endDate)s and
|
||||
p.id in %(premises)s
|
||||
group by house_id, house, category
|
||||
union
|
||||
select 0 as sum,
|
||||
aec.description as category,
|
||||
p.id as house_id,
|
||||
p.description as house
|
||||
from account_t a,
|
||||
premise_t p,
|
||||
account_entry_t ae,
|
||||
account_entry_category_t aec
|
||||
where p.account = a.id and
|
||||
ae.account = a.id and
|
||||
aec.overhead_relevant = 't' and
|
||||
aec.id not in (select distinct account_entry_category from account_entry_t) and
|
||||
created_at between %(startDate)s and %(endDate)s and
|
||||
p.id in %(premises)s
|
||||
group by house_id, house, category
|
||||
order by house_id, category
|
||||
""",
|
||||
"params": {
|
||||
"startDate": startDate,
|
||||
"endDate": endDate,
|
||||
"premises": premises
|
||||
}
|
||||
}
|
||||
)
|
||||
logger.info(f"{overheadSums=}")
|
||||
|
||||
|
||||
|
||||
|
@ -12,7 +12,7 @@ def execDatabaseOperation(dbh, func, params):
|
||||
cur = None
|
||||
try:
|
||||
with dbh.cursor(cursor_factory = psycopg2.extras.RealDictCursor) as cur:
|
||||
params["params"] = [ v if not v=='' else None for v in params["params"] ]
|
||||
# params["params"] = [ v if not v=='' else None for v in params["params"] ]
|
||||
logger.debug("edo: {}".format(str(params)))
|
||||
return func(cur, params)
|
||||
except psycopg2.Error as err:
|
||||
@ -21,6 +21,7 @@ def execDatabaseOperation(dbh, func, params):
|
||||
|
||||
|
||||
def _opGetMany(cursor, params):
|
||||
logger.warning(f"{params=}")
|
||||
items = []
|
||||
cursor.execute(params["statement"], params["params"])
|
||||
for itemObj in cursor:
|
||||
|
Loading…
x
Reference in New Issue
Block a user