This commit is contained in:
yumoqing 2025-03-04 15:50:24 +08:00
parent 5a08708164
commit 44b3d73974
2 changed files with 39 additions and 35 deletions

View File

@ -33,29 +33,29 @@ async def get_account(sor, accounting_orgid, orgid, subjectid, org1id=None):
return recs[0]
async def get_account_by_subjectname(sor, accounting_orgid, orgid, subjectname, org1id=None):
ss = "a.org1id is NULL"
if org1id:
ss = "a.org1id = ${org1id}$"
ss = "a.org1id is NULL"
if org1id:
ss = "a.org1id = ${org1id}$"
sql = """select * from account a, subject b
sql = """select * from account a, subject b
where
a.subjectid = b.id and
b.name = ${subjectname}$ and
a.accounting_orgid = ${accounting_orgid}$ and
a.orgid = ${orgid}$ and
""" + ss
recs = await sor.sqlExe(sql, {
"accounting_orgid":accounting_orgid,
"orgid":orgid,
"org1id":org1id,
"subjectname":subjectname
});
if len(recs) == 0:
return None
for rec in recs:
if a.org1id == org1id:
return rec['id']
return None
b.name = ${subjectname}$ and
a.accounting_orgid = ${accounting_orgid}$ and
a.orgid = ${orgid}$ and
""" + ss
recs = await sor.sqlExe(sql, {
"accounting_orgid":accounting_orgid,
"orgid":orgid,
"org1id":org1id,
"subjectname":subjectname
});
if len(recs) == 0:
return None
for rec in recs:
if a.org1id == org1id:
return rec['id']
return None
async def getAccountByName(sor, accounting_orgid, orgid, name, org1id):
sql = """select a.* from account a, subject b
@ -106,11 +106,11 @@ async def getAccountBalance(sor, accounting_orgid, orgid, subjectname, org1id):
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
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}$
and acc_date >= ${from_date}$
and acc_date < ${to_date}$
and acc_dir = ${accounting_dir}$
"""
ns = {
'accountid':accid,

View File

@ -4,8 +4,15 @@ from appPublic.uniqueID import getID
from appPublic.registerfunction import RegisterFunction, rfexe
from appPublic.log import debug, exception
from datetime import datetime
from accounting.getaccount import get_account
async def openAccount(sor, accounting_orgid, orgid, account_config, org1id=None):
acc = await get_account(sor, accounting_orgid, orgid,
account_config['subjectid'], org1id=org1id)
if acc:
debug(f'{acc=} opened')
return
ns = {
'id':getID(),
'accounting_orgid':accounting_orgid,
@ -18,7 +25,7 @@ async def openAccount(sor, accounting_orgid, orgid, account_config, org1id=None)
ns['org1id'] = org1id;
debug(f'openAccount(), {ns=}')
await sor.C('account', ns.copy())
print(ns, 'opened')
debug(f'{ns=} opened')
async def openPartyAccounts(sor, accounting_orgid, orgid, party_type, org1id=None, party1_type=None):
addon_cond = " and a.party1type is NULL "
@ -27,7 +34,7 @@ async def openPartyAccounts(sor, accounting_orgid, orgid, party_type, org1id=Non
addon_cond = " and a.party1type = ${party1type}$ "
ns['party1type'] = party1_type
sql = """select a.*, b.id as subjectid, b.balance_side from account_config a, subject b
sql = """select a.*, b.id as subjectid, b.name as subjectname,b.balance_side from account_config a, subject b
where a.subjectid = b.id """ \
+ addon_cond + """
and a.partytype=${partytype}$ """
@ -91,13 +98,10 @@ async def openAllProviderAccounts(sor, accounting_orgid):
await openProviderAccounts(sor, accounting_orgid, r['id'])
async def openRetailRelationshipAccounts(sor, accounting_orgid, providerid, resellerid):
db = DBPools()
dbname = await rfexe('get_module_dbname', 'accounting')
async with db.sqlorContext(dbname) as sor:
await openPartyAccounts(sor, accounting_orgid, providerid, PARTY_PROVIDER,
org1id=resellerid,
party1_type=PARTY_RESELLER)
await openPartyAccounts(sor, accounting_orgid, resellerid, PARTY_RESELLER,
org1id=providerid,
party1_type=PARTY_PROVIDER)
await openPartyAccounts(sor, accounting_orgid, providerid, PARTY_PROVIDER,
org1id=resellerid,
party1_type=PARTY_RESELLER)
await openPartyAccounts(sor, accounting_orgid, resellerid, PARTY_RESELLER,
org1id=providerid,
party1_type=PARTY_PROVIDER)