accounting/accounting/businessdate.py
2024-09-21 14:07:27 +08:00

40 lines
1.1 KiB
Python

from sqlor.dbpools import DBPools
from appPublic.timeUtils import strdate_add
from .excep import BusinessDateParamsError
from .const import *
async def get_business_date(sor=None):
async def _f(sor):
sql = "select * from params where params_name = 'business_date'"
recs = await sor.sqlExe(sql, {})
if len(recs) > 0:
return recs[0]['params_value']
raise BusinessDateParamsError
if sor:
return await _f(sor)
db = DBPools()
async with db.sqlorContext(DBNAME) as sor:
return await _f(sor)
async def new_business_date(sor=None):
async def _f(sor):
dat = await get_business_date(sor)
new_dat = strdate_add(dat, days=1)
sql = "update params set params_value=${new_dat}$ where params_name='business_date'"
await sor.sqlExe(sql, {'new_dat':new_dat})
if sor:
return await _f(sor)
db = DBPools()
async with db.sqlorContext(DBNAME) as sor:
return await _f(sor)
async def previous_business_date(sor=None):
dat = await get_business_date(sor=sor)
return strdate_add(dat, days=-1)
async def next_business_date(sor=None):
dat = await get_business_date(sor=sor)
return strdate_add(dat, days=1)