diff --git a/accounting/accountingnode.py b/accounting/accountingnode.py index 8c5c20b..4d149cc 100644 --- a/accounting/accountingnode.py +++ b/accounting/accountingnode.py @@ -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']) diff --git a/accounting/businessdate.py b/accounting/businessdate.py index fa9644f..191d25e 100644 --- a/accounting/businessdate.py +++ b/accounting/businessdate.py @@ -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: diff --git a/test/recharge.py b/test/recharge.py new file mode 100644 index 0000000..3ef5251 --- /dev/null +++ b/test/recharge.py @@ -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) diff --git a/test/run_test.py b/test/run_test.py new file mode 100644 index 0000000..b72908d --- /dev/null +++ b/test/run_test.py @@ -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()) +