diff --git a/accounting/getaccount.py b/accounting/getaccount.py index df52e26..a9964c8 100644 --- a/accounting/getaccount.py +++ b/accounting/getaccount.py @@ -71,7 +71,7 @@ where a.subjectid = b.id and if len(recs) == 0: return None for rec in recs: - if a.org1id == org1id: + if rec.org1id == org1id: return rec['id'] return None @@ -84,12 +84,13 @@ async def getCustomerBalance(sor, customerid): if get_owner_orgid is None: debug('get_owner_orgid function is not a serverenv function') return None + debug(f'{get_owner_orgid=}') orgid = await get_owner_orgid(sor, customerid) if orgid is None: debug(f"{customerid=}'s parent organization not found") return None - balance = await getAccountBalance(sor, orgid, customerid, name) + balance = await getAccountBalance(sor, orgid, customerid, name, None) if balance is None: debug(f'accid is None, {orgid=}, {customerid=}, {name=}') return None @@ -104,6 +105,27 @@ async def getAccountBalance(sor, accounting_orgid, orgid, subjectname, org1id): return None 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): balances = await sor.sqlExe("""select * from acc_balance where accountid=${accid}$ order by acc_date desc""", {'accid':accid}) if len(balances) == 0: diff --git a/accounting/init.py b/accounting/init.py index 76ed959..c32923c 100644 --- a/accounting/init.py +++ b/accounting/init.py @@ -5,7 +5,7 @@ from ahserver.serverenv import ServerEnv from accounting.accounting_config import Accounting from accounting.bill import write_bill 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(): g = ServerEnv() @@ -17,4 +17,5 @@ def load_accounting(): g.openCustomerAccounts = openCustomerAccounts g.getAccountBalance = getAccountBalance g.getCustomerBalance = getCustomerBalance - + g.getAccountByName = getAccountByName + g.get_account_total_amount = get_account_total_amount