This commit is contained in:
yumoqing 2024-09-21 20:39:47 +08:00
parent 1d8f368223
commit 77c2c31961
4 changed files with 55 additions and 10 deletions

View File

@ -5,6 +5,7 @@ from .accountingnode import get_parent_orgid
from .excep import *
from .getaccount import getAccountByName
from appPublic.uniqueID import getID
from appPublic.log import debug
from sqlor.dbpools import DBPools
from appPublic.timeUtils import curDateString
from .argsconvert import ArgsConvert
@ -108,6 +109,7 @@ where a.id = b.protocolid
aorgtype = '客户所在机构'
if self.resellerid:
aorgtype = '分销商机构'
debug(f'{accounting_config=}, {aorgtype=}')
if self.specstr.startswith(ACTNAME_SETTLE):
self.accounting_legs = [r.copy() for r in accounting_config
if r['specstr'] == specstr ]
@ -115,6 +117,7 @@ where a.id = b.protocolid
self.accounting_legs = [r.copy() for r in accounting_config
if r['specstr'] == specstr
and r['accounting_orgtype'] == aorgtype]
debug(f'{self.accounting_legs=}')
for l in self.accounting_legs:
l['summary'] = self.action
@ -396,7 +399,9 @@ where accountid=${accid}$
async def get_act_specstr(self):
sor = self.sor
debug(f'{self.action=} ---')
if self.action in [ ACTION_RECHARGE, ACTION_RECHARGE_REVERSE ]:
debug(f'{self.action=}, {ACTNAME_RECHARGE=}')
return ACTNAME_RECHARGE
if self.action in [ ACTION_SETTLE, ACTION_SETTLE_REVERSE ]:
@ -407,6 +412,7 @@ where accountid=${accid}$
spec = f'{ACTNAME_SETTLE}-{SALEMODE_REBATE}'
else:
spec = f'{ACTNAME_SETTLE}-{SALEMODE_FLOORPRICE}'
debug(f'{self.action=} {spec=}')
return spec
@ -428,6 +434,7 @@ where accountid=${accid}$
else:
self.reseller_salemode = sale_mode
await self.setup_bill_variable()
debug(f'{ret=}')
return ret

View File

@ -1,4 +1,4 @@
DBNAME = 'kboss'
DBNAME = 'sage'
RESELLER_ORG = '1'
OWNER_OGR = '0'
CORP_CUSTOMER = '2'
@ -10,12 +10,12 @@ PARTY_CUSTOMER = '客户'
PARTY_RESELLER = '分销商'
PARTY_PROVIDER = '供应商'
DEBT = ''
CREDIT = ''
DEBT = '0'
CREDIT = '1'
ACTNAME_BUY = '付费'
ACTNAME_RECHARGE = '充值'
ACTNAME_RECHARGE_ALIPAY = '支付宝充值'
ACTNAME_BUY = 'sonsume'
ACTNAME_RECHARGE = 'recharge'
ACTNAME_RECHARGE_ALIPAY = 'rechange_alipay'
ACTNAME_SETTLE = '结算'
SALEMODE_DISCOUNT = '折扣'

View File

@ -1,6 +1,7 @@
from sqlor.dbpools import DBPools
from .const import *
from appPublic.uniqueID import getID
from appPublic.log import debug
from datetime import datetime
async def openAccount(sor, accounting_orgid, orgid, account_config):
@ -12,6 +13,7 @@ async def openAccount(sor, accounting_orgid, orgid, account_config):
'balance_at':account_config['balance_side'],
'max_detailno':0
}
debug(f'openAccount(), {ns=}')
await sor.C('account', ns.copy())
print(ns, 'opened')
@ -20,7 +22,7 @@ async def openPartyAccounts(sor, accounting_orgid, orgid, party_type):
where a.subjectname = b.name
and a.partytype=${partytype}$ """
recs = await sor.sqlExe(sql, {'partytype':party_type})
print(f'select account_config {recs=}', party_type)
# print(f'select account_config {recs=}', party_type)
for r in recs:
await openAccount(sor, accounting_orgid, orgid, r)
@ -43,9 +45,16 @@ 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
where parentid=${accounting_orgid}$ and
org_type in ('2', '3' )"""
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})
print(f'{recs=}')
for r in recs:

29
test/open_account.py Normal file
View File

@ -0,0 +1,29 @@
from run_test import run
from appPublic.log import debug
from sqlor.dbpools import DBPools
from accounting.openaccount import openAllCustomerAccounts, \
openOwnerAccounts, openAllProviderAccounts, openAllResellerAccounts
async def OpenAccount():
orgid = '_VaV5trl8faujgr7xaE3D'
db = DBPools()
async with db.sqlorContext('sage') as sor:
try:
await openAllCustomerAccounts(sor, orgid)
except Exception as e:
debug(f'{e}')
try:
await openOwnerAccounts(sor, orgid)
except Exception as e:
debug(f'{e}')
try:
await openAllProviderAccounts(sor, orgid)
except Exception as e:
debug(f'{e}')
try:
await openAllResellerAccounts(sor, orgid)
except Exception as e:
debug(f'{e}')
if __name__ == '__main__':
run(OpenAccount)