This commit is contained in:
yumoqing 2025-02-07 17:20:43 +08:00
parent 37c9ab2a0e
commit 5a08708164
2 changed files with 27 additions and 4 deletions

View File

@ -71,7 +71,7 @@ where a.subjectid = b.id and
if len(recs) == 0: if len(recs) == 0:
return None return None
for rec in recs: for rec in recs:
if a.org1id == org1id: if rec.org1id == org1id:
return rec['id'] return rec['id']
return None return None
@ -84,12 +84,13 @@ async def getCustomerBalance(sor, customerid):
if get_owner_orgid is None: if get_owner_orgid is None:
debug('get_owner_orgid function is not a serverenv function') debug('get_owner_orgid function is not a serverenv function')
return None return None
debug(f'{get_owner_orgid=}')
orgid = await get_owner_orgid(sor, customerid) orgid = await get_owner_orgid(sor, customerid)
if orgid is None: if orgid is None:
debug(f"{customerid=}'s parent organization not found") debug(f"{customerid=}'s parent organization not found")
return None return None
balance = await getAccountBalance(sor, orgid, customerid, name) balance = await getAccountBalance(sor, orgid, customerid, name, None)
if balance is None: if balance is None:
debug(f'accid is None, {orgid=}, {customerid=}, {name=}') debug(f'accid is None, {orgid=}, {customerid=}, {name=}')
return None return None
@ -104,6 +105,27 @@ async def getAccountBalance(sor, accounting_orgid, orgid, subjectname, org1id):
return None return None
return await getAccountBalanceByAccid(sor, accid) return await getAccountBalanceByAccid(sor, accid)
async def get_account_total_amount(sor, accid, accounting_dir, from_date, to_date):
sql = """select sun(amount) as amount from acc_detail
where accountid =${accountid}$
and acc_date >= ${from_date}$
and acc_date < ${to_date}$
and acc_dir = ${accounting_dir}$
"""
ns = {
'accountid':accid,
'accounting_dir':accounting_dir,
'from_date':from_date,
'to_date':to_date
}
recs = await sor.sqlExe(sql, ns.copy())
if len(recs)==0:
e = Exception(f'get_account_total_amount() error, {ns=}')
exception('{e=}')
raise e
return recs[0].amount
async def getAccountBalanceByAccid(sor, accid): async def getAccountBalanceByAccid(sor, accid):
balances = await sor.sqlExe("""select * from acc_balance where accountid=${accid}$ order by acc_date desc""", {'accid':accid}) balances = await sor.sqlExe("""select * from acc_balance where accountid=${accid}$ order by acc_date desc""", {'accid':accid})
if len(balances) == 0: if len(balances) == 0:

View File

@ -5,7 +5,7 @@ from ahserver.serverenv import ServerEnv
from accounting.accounting_config import Accounting from accounting.accounting_config import Accounting
from accounting.bill import write_bill from accounting.bill import write_bill
from accounting.openaccount import openOwnerAccounts, openProviderAccounts, openResellerAccounts, openCustomerAccounts from accounting.openaccount import openOwnerAccounts, openProviderAccounts, openResellerAccounts, openCustomerAccounts
from getaccount import getAccountBalance, getCustomerBalance from accounting.getaccount import getAccountBalance, getCustomerBalance, getAccountByName, get_account_total_amount
def load_accounting(): def load_accounting():
g = ServerEnv() g = ServerEnv()
@ -17,4 +17,5 @@ def load_accounting():
g.openCustomerAccounts = openCustomerAccounts g.openCustomerAccounts = openCustomerAccounts
g.getAccountBalance = getAccountBalance g.getAccountBalance = getAccountBalance
g.getCustomerBalance = getCustomerBalance g.getCustomerBalance = getCustomerBalance
g.getAccountByName = getAccountByName
g.get_account_total_amount = get_account_total_amount