This commit is contained in:
yumoqing 2024-09-22 12:27:44 +08:00
parent 7383fc245b
commit 231403885d
9 changed files with 85 additions and 37 deletions

View File

@ -13,7 +13,7 @@ async def get_business_date(sor=None):
if sor:
return await _f(sor)
db = DBPools()
async with db.sqlorContext(DBNAME) as sor:
async with db.sqlorContext(DBNAME()) as sor:
return await _f(sor)
async def new_business_date(sor=None):
@ -26,7 +26,7 @@ async def new_business_date(sor=None):
if sor:
return await _f(sor)
db = DBPools()
async with db.sqlorContext(DBNAME) as sor:
async with db.sqlorContext(DBNAME()) as sor:
return await _f(sor)
async def previous_business_date(sor=None):

View File

@ -1,4 +1,14 @@
DBNAME = 'sage'
from appPublic.registerfunction import RegisterFunction
def DBNAME():
rf = RegisterFunction()
f = rf.get('get_module_database')
if f is None:
e = Exception('function "get_module_database" not registed')
exception(f'{e}')
raise e
return f('accounting')
RESELLER_ORG = '1'
OWNER_OGR = '0'
CORP_CUSTOMER = '2'

63
accounting/consume.py Normal file
View File

@ -0,0 +1,63 @@
from datetime import datetime
from appPublic.uniqueID import getID
from sqlor.dbpools import DBPools
from appPublic.timeUtils import curDateString
from appPublic.argsConvert import ArgsConvert
from .accounting_config import get_accounting_config, AccountingOrgs
from .const import *
from .accountingnode import get_accounting_nodes
from .excep import *
from .getaccount import getAccountByName
from .businessdate import get_business_date
class ConsumeAccounting:
def __init__(self, cnsume_log):
self.db = DBPools()
self.recharge_log = recharge_log
self.customerid = recharge_log['customerid']
self.orderid = None
self.curdate = recharge_log['recharge_date']
self.transamount = recharge_log['recharge_amt']
self.timestamp = datetime.now()
self.productid = None
self.providerid = None
self.action = recharge_log['action']
self.summary = self.action
self.billid = getID()
self.bill = {
'id':self.billid,
'customerid':self.recharge_log['customerid'],
'resellerid':None,
'orderid':None,
'business_op':self.recharge_log['action'],
'amount':self.recharge_log['recharge_amt'],
'bill_date':self.curdate,
'bill_timestamp':self.timestamp
}
async def accounting(self, sor):
self.sor = sor
bz_date = await get_business_date(sor=sor)
if bz_date != self.curdate:
raise AccountingDateNotInBusinessDate(self.curdate, bz_date)
nodes = await get_accounting_nodes(sor, self.customerid)
lst = len(nodes) - 1
self.accountingOrgs = []
for i, n in enumerate(nodes):
if i < lst:
ao = AccountingOrgs(self, nodes[i], self.customerid,
resellerid=nodes[i+1])
else:
ao = AccountingOrgs(self, nodes[i], self.customerid)
self.accountingOrgs.append(ao)
await self.write_bill(sor)
[await ao.do_accounting(sor) for ao in self.accountingOrgs ]
print(f'recharge ok for {self.bill}, {nodes=}')
return True
async def write_bill(self, sor):
await sor.C('bill', self.bill.copy())
# await sor.C('recharge_log', self.recharge_log.copy())

View File

@ -9,7 +9,7 @@ async def dayend_balance():
ts = datetime.now()
sql = """select a.* from (select accountid, max(acc_date) as acc_date, balance from acc_balance where accountid is not null group by accountid) a where acc_date < ${acc_date}$"""
db = DBPools()
async with db.sqlorContext(DBNAME) as sor:
async with db.sqlorContext(DBNAME()) as sor:
recs = await sor.sqlExe(sql, {'acc_date':dat})
for r in recs:
r['id'] = getID()

View File

@ -29,7 +29,7 @@ where a.subjectname = b.name
async def _openPartyAccounts(accounting_orgid, orgid, party_type):
db = DBPools()
async with db.sqlorContext(DBNAME) as sor:
async with db.sqlorContext(DBNAME()) as sor:
await openPartyAccounts(sor, accounting_orgid, orgid, party_type)
async def openResellerAccounts(sor, accounting_orgid, orgid):

View File

@ -50,7 +50,7 @@ where o.id = og.orderid
async def order2bill(orderid, sor=None):
if sor is None:
db = DBPools()
async with db.sqlorContext(DBNAME) as sor:
async with db.sqlorContext(DBNAME()) as sor:
await _order2bill(sor, orderid)
else:
await _order2bill(sor, orderid)

View File

@ -23,6 +23,6 @@ async def is_provider_settle_date(strdate:str,
if sor:
return await f(sor, strdate, providerid)
db = DBPools()
async with db.sqlorContext(DBNAME) as sor:
async with db.sqlorContext(DBNAME()) as sor:
return await f(sor, strdate, providerid)

View File

@ -1,30 +0,0 @@
import asyncio
from datetime import date
from sqlor.dbpools import DBPools
from appPublic.jsonConfig import getConfig
from appPublic.timeUtils import curDateString
from accounting.accounting_config import Accounting
async def main():
db = DBPools()
orders = []
dat = date.today() #curDateString()
async with db.sqlorContext('kboss') as sor:
sql = "select * from bz_order where order_date=${dat}$"
orders = await sor.sqlExe(sql, {'dat':dat})
print(dat, orders)
ai = [ Accounting(o) for o in orders ]
print(ai)
[ await a.accounting() for a in ai ]
if __name__ == '__main__':
import sys
p = '.'
if len(sys.argv) > 1:
p = sys.argv[1]
config = getConfig(p, {'woridir':p})
DBPools(config.databases)
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
loop.run_until_complete(main())

View File

@ -2,6 +2,11 @@ from appPublic.registerfunction import RegisterFunction
rf = RegisterFunction()
def get_module_database(module_name):
return 'sage'
rf.register('get_module_database', get_module_database)
async def get_providers_by_orgid(sor, accounting_orgid):
sql = """select * from organization a, orgtypes b
where a.parentid = ${accounting_orgid}$ and