100 lines
3.7 KiB
Python
100 lines
3.7 KiB
Python
from sqlor.dbpools import DBPools
|
|
from .const import *
|
|
from appPublic.uniqueID import getID
|
|
from appPublic.registerfunction import RegisterFunction
|
|
from appPublic.log import debug, exception
|
|
from datetime import datetime
|
|
|
|
async def openAccount(sor, accounting_orgid, orgid, account_config, org1id=None):
|
|
ns = {
|
|
'id':getID(),
|
|
'accounting_orgid':accounting_orgid,
|
|
'orgid':orgid,
|
|
'subjectid':account_config['subjectid'],
|
|
'balance_at':account_config['balance_side'],
|
|
'max_detailno':0
|
|
}
|
|
if org1id:
|
|
ns['org1id'] = org1id;
|
|
debug(f'openAccount(), {ns=}')
|
|
await sor.C('account', ns.copy())
|
|
print(ns, 'opened')
|
|
|
|
async def openPartyAccounts(sor, accounting_orgid, orgid, party_type, org1id=None, party1_type=None):
|
|
addon_cond = " and a.party1type is NULL "
|
|
ns = {'partytype':party_type}
|
|
if party1_type:
|
|
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
|
|
where a.subjectname = b.name """
|
|
+ addon_cond + """
|
|
and a.partytype=${partytype}$ """
|
|
recs = await sor.sqlExe(sql, ns)
|
|
# print(f'select account_config {recs=}', party_type)
|
|
for r in recs:
|
|
await openAccount(sor, accounting_orgid, orgid, r, org1id=org1id)
|
|
|
|
async def _openPartyAccounts(accounting_orgid, orgid, party_type):
|
|
db = DBPools()
|
|
async with db.sqlorContext(DBNAME()) as sor:
|
|
await openPartyAccounts(sor, accounting_orgid, orgid, party_type)
|
|
|
|
async def openResellerAccounts(sor, accounting_orgid, orgid):
|
|
return await _openPartyAccounts(accounting_orgid, orgid, PARTY_RESELLER)
|
|
|
|
async def openCustomerAccounts(sor, accounting_orgid, orgid):
|
|
return await _openPartyAccounts(accounting_orgid, orgid, PARTY_CUSTOMER)
|
|
|
|
async def openOwnerAccounts(sor, accounting_orgid):
|
|
orgid = accounting_orgid
|
|
return await _openPartyAccounts(accounting_orgid, orgid, PARTY_OWNER)
|
|
|
|
async def openProviderAccounts(sor, accounting_orgid, orgid):
|
|
return await _openPartyAccounts(accounting_orgid, orgid, PARTY_PROVIDER)
|
|
|
|
async def openAllCustomerAccounts(sor, accounting_orgid):
|
|
rf = RegisterFunction()
|
|
f = rf.get('get_customers_by_orgid')
|
|
if f is None:
|
|
exception(f'get_customers_by_orgid function not registed, {accounting_orgid=}')
|
|
raise Exception('get_customers_by_orgid not registed')
|
|
recs = await f(sor, accounting_orgid)
|
|
print(f'{recs=}')
|
|
for r in recs:
|
|
await openCustomerAccounts(sor, accounting_orgid, r['id'])
|
|
|
|
async def openAllResellerAccounts(sor, accounting_orgid):
|
|
rf = RegisterFunction()
|
|
f = rf.get('get_resellers_by_orgid')
|
|
if f is None:
|
|
exception(f'get_resellers_by_orgid function not registed, {accounting_orgid=}')
|
|
raise Exception('get_resellers_by_orgid not registed')
|
|
recs = await f(sor, accounting_orgid)
|
|
print(f'{recs=}')
|
|
for r in recs:
|
|
await openResellerAccounts(sor, accounting_orgid, r['id'])
|
|
|
|
async def openAllProviderAccounts(sor, accounting_orgid):
|
|
rf = RegisterFunction()
|
|
f = rf.get('get_providers_by_orgid')
|
|
if f is None:
|
|
exception(f'get_providers_by_orgid function not registed, {accounting_orgid=}')
|
|
raise Exception('get_providers_by_orgid not registed')
|
|
recs = await f(sor, accounting_orgid)
|
|
print(f'{recs=}')
|
|
for r in recs:
|
|
await openProviderAccounts(sor, accounting_orgid, r['id'])
|
|
|
|
async def openRetailRelationshipAccounts(sor, accounting_orgid, providerid, resellerid):
|
|
db = DBPools()
|
|
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)
|
|
|