This commit is contained in:
yumoqing 2024-09-22 12:05:37 +08:00
parent 77c2c31961
commit 7383fc245b
4 changed files with 80 additions and 20 deletions

View File

@ -1,7 +1,8 @@
from sqlor.dbpools import DBPools
from .const import *
from appPublic.uniqueID import getID
from appPublic.log import debug
from appPublic.registerfunction import RegisterFunction
from appPublic.log import debug, exception
from datetime import datetime
async def openAccount(sor, accounting_orgid, orgid, account_config):
@ -45,34 +46,34 @@ async def openProviderAccounts(sor, accounting_orgid, orgid):
return await _openPartyAccounts(accounting_orgid, orgid, PARTY_PROVIDER)
async def openAllCustomerAccounts(sor, accounting_orgid):
sql = """select * from organization a,
(select orgid, count(*) cnt
from orgtypes
where orgtypeid in ('customer', 'personalcustomer', 'agencycustomer')
group by orgid
) b
where a.parentid=${accounting_orgid}$ and
a.id = b.orgid and
b.cnt > 0
"""
recs = await sor.sqlExe(sql, {'accounting_orgid':accounting_orgid})
rf = RegisterFunction()
f = rf.get('get_customers_by_orgid')
if f is None:
exception(f'get_customers_by_orgid function not registed, {accounting_orgid=}')
raise Exception('get_customers_by_orgid not registed')
recs = await f(sor, accounting_orgid)
print(f'{recs=}')
for r in recs:
await openCustomerAccounts(sor, accounting_orgid, r['id'])
async def openAllResellerAccounts(sor, accounting_orgid):
sql = """select * from organization
where parentid=${accounting_orgid}$ and
org_type = '1'"""
recs = await sor.sqlExe(sql, {'accounting_orgid':accounting_orgid})
rf = RegisterFunction()
f = rf.get('get_resellers_by_orgid')
if f is None:
exception(f'get_resellers_by_orgid function not registed, {accounting_orgid=}')
raise Exception('get_resellers_by_orgid not registed')
recs = await f(sor, accounting_orgid)
print(f'{recs=}')
for r in recs:
await openResellerAccounts(sor, accounting_orgid, r['id'])
async def openAllProviderAccounts(sor, accounting_orgid):
sql = """select * from organization
where org_type = '4'"""
recs = await sor.sqlExe(sql, {'accounting_orgid':accounting_orgid})
rf = RegisterFunction()
f = rf.get('get_providers_by_orgid')
if f is None:
exception(f'get_providers_by_orgid function not registed, {accounting_orgid=}')
raise Exception('get_providers_by_orgid not registed')
recs = await f(sor, accounting_orgid)
print(f'{recs=}')
for r in recs:
await openProviderAccounts(sor, accounting_orgid, r['id'])

View File

@ -4,6 +4,8 @@ from sqlor.dbpools import DBPools
from accounting.openaccount import openAllCustomerAccounts, \
openOwnerAccounts, openAllProviderAccounts, openAllResellerAccounts
import test_rf
async def OpenAccount():
orgid = '_VaV5trl8faujgr7xaE3D'
db = DBPools()

View File

@ -4,7 +4,7 @@ from appPublic.dictObject import DictObject
from accounting.recharge import RechargeAccounting
from run_test import run
async def test():
async def test1():
rl = DictObject()
rl.customerid = '4zXVMkBCEaTmR0xwneUBX'
rl.recharge_date = '2024-09-21'
@ -17,5 +17,22 @@ async def test():
async with db.sqlorContext('sage') as sor:
await ra.accounting(sor)
async def test2():
rl = DictObject()
rl.customerid = '4zXVMkBCEaTmR0xwneUBX'
rl.recharge_date = '2024-09-21'
rl.recharge_amt = 100
rl.action = 'RECHARGE_REVERSE'
rl.orderid = '1'
rl.recharge_channel = 'alipay'
ra = RechargeAccounting(rl)
db = DBPools()
async with db.sqlorContext('sage') as sor:
await ra.accounting(sor)
async def test():
await test1()
await test2()
if __name__ == '__main__':
run(test)

40
test/test_rf.py Normal file
View File

@ -0,0 +1,40 @@
from appPublic.registerfunction import RegisterFunction
rf = RegisterFunction()
async def get_providers_by_orgid(sor, accounting_orgid):
sql = """select * from organization a, orgtypes b
where a.parentid = ${accounting_orgid}$ and
b.orgtypeid = 'provider' and
a.id = b.orgid """
recs = await sor.sqlExe(sql, {'accounting_orgid':accounting_orgid})
return recs
rf.register('get_providers_by_orgid', get_providers_by_orgid)
async def get_resellers_by_orgid(sor, accounting_orgid):
sql = """select * from organization a, orgtypes b
where a.parentid=${accounting_orgid}$ and
a.id = b.orgid and
b.orgtypeid = 'reseller'"""
recs = await sor.sqlExe(sql, {'accounting_orgid':accounting_orgid})
return recs
rf.register('get_resellers_by_orgid', get_resellers_by_orgid)
async def get_customers_by_orgid(sor, accounting_orgid):
sql = """select * from organization a,
(select orgid, count(*) cnt
from orgtypes
where orgtypeid in ('customer', 'personalcustomer', 'agencycustomer')
group by orgid
) b
where a.parentid=${accounting_orgid}$ and
a.id = b.orgid and
b.cnt > 0
"""
recs = await sor.sqlExe(sql, {'accounting_orgid':accounting_orgid})
return recs
rf.register('get_customers_by_orgid', get_customers_by_orgid)