This commit is contained in:
yumoqing 2024-09-21 14:07:27 +08:00
parent cecb0d9e73
commit 1d8f368223
4 changed files with 55 additions and 4 deletions

View File

@ -1,4 +1,5 @@
from .const import *
from appPublic.log import debug
from sqlor.dbpools import DBPools
async def get_parent_orgid(sor, orgid):
@ -49,16 +50,33 @@ async def get_ancestor_orgs(sor, orgid):
ret = await get_ancestor_orgs(sor, id)
return ret + [id]
async def get_orgtypes(sor, orgid):
sql = "select orgtypeid from orgtypes where orgid = ${orgid}$"
recs = await sor.sqlExe(sql, {'orgid':orgid})
return [r.orgtypeid for r in recs]
async def get_accounting_nodes(sor, customerid):
"""
gt all accounting organization for transactes customer orgid
"""
mytypes = await get_orgtypes(sor, customerid)
is_c = False
for t in mytypes:
if t in ['customer', 'agencycustomer', 'personalcustomer']:
is_c = True
break
if not is_c:
debug(f'{customerid=} is not a customer organzition')
return []
sql = """select a.id from organization a, organization b
where b.parentid = a.id
and b.id = ${customerid}$
and b.org_type in ('2','3')"""
"""
recs = await sor.sqlExe(sql, {'customerid':customerid})
if len(recs) == 0:
debug(f'{customerid=} not found is organziation table')
return []
ret = await get_ancestor_orgs(sor, recs[0]['id'])
ret.append(recs[0]['id'])

View File

@ -4,10 +4,10 @@ from .excep import BusinessDateParamsError
from .const import *
async def get_business_date(sor=None):
async def _f(sor):
sql = "select * from params where pname = 'business_date'"
sql = "select * from params where params_name = 'business_date'"
recs = await sor.sqlExe(sql, {})
if len(recs) > 0:
return recs[0]['pvalue']
return recs[0]['params_value']
raise BusinessDateParamsError
if sor:
@ -20,7 +20,7 @@ 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 pvalue=${new_dat}$ where pname='business_date'"
sql = "update params set params_value=${new_dat}$ where params_name='business_date'"
await sor.sqlExe(sql, {'new_dat':new_dat})
if sor:

21
test/recharge.py Normal file
View File

@ -0,0 +1,21 @@
from sqlor.dbpools import DBPools
from appPublic.jsonConfig import getConfig
from appPublic.dictObject import DictObject
from accounting.recharge import RechargeAccounting
from run_test import run
async def test():
rl = DictObject()
rl.customerid = '4zXVMkBCEaTmR0xwneUBX'
rl.recharge_date = '2024-09-21'
rl.recharge_amt = 100
rl.action = 'RECHARGE'
rl.orderid = '1'
rl.recharge_channel = 'alipay'
ra = RechargeAccounting(rl)
db = DBPools()
async with db.sqlorContext('sage') as sor:
await ra.accounting(sor)
if __name__ == '__main__':
run(test)

12
test/run_test.py Normal file
View File

@ -0,0 +1,12 @@
import os
import asyncio
from sqlor.dbpools import DBPools
from appPublic.jsonConfig import getConfig
def run(test_coro):
os.chdir('/Users/ymq/py/sage')
conf = getConfig()
DBPools(conf.databases)
asyncio.get_event_loop().run_until_complete(test_coro())