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

View File

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

View File

@ -4,7 +4,7 @@ from appPublic.dictObject import DictObject
from accounting.recharge import RechargeAccounting from accounting.recharge import RechargeAccounting
from run_test import run from run_test import run
async def test(): async def test1():
rl = DictObject() rl = DictObject()
rl.customerid = '4zXVMkBCEaTmR0xwneUBX' rl.customerid = '4zXVMkBCEaTmR0xwneUBX'
rl.recharge_date = '2024-09-21' rl.recharge_date = '2024-09-21'
@ -17,5 +17,22 @@ async def test():
async with db.sqlorContext('sage') as sor: async with db.sqlorContext('sage') as sor:
await ra.accounting(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__': if __name__ == '__main__':
run(test) 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)