This commit is contained in:
yumoqing 2025-01-17 13:49:41 +08:00
parent 2f8822aa77
commit 96a21d0c01
5 changed files with 51 additions and 47 deletions

View File

@ -5,7 +5,7 @@ from .accountingnode import get_parent_orgid
from .excep import *
from .getaccount import get_account, getAccountByName
from appPublic.uniqueID import getID
from appPublic.log import debug
from appPublic.log import debug, exception
from sqlor.dbpools import DBPools
from appPublic.timeUtils import curDateString
# from .argsconvert import ArgsConvert
@ -25,17 +25,13 @@ async def get_accounting_config(sor):
return None
class Accounting:
/*
"""
需要caller功能
caller中要有分录中的变量
get_accounting_orgid(leg) 获得记账机构
get_account(legaccounting_orgid) 获得记账账号通过科目机构类型账务机构确定一个唯一的账号
*/
def __init__(self, caller,
accounting_orgid,
customerid,
resellerid=None
):
"""
def __init__(self, caller):
self.caller = caller
self.curdate = caller.curdate
self.realtimesettled = False
@ -43,16 +39,14 @@ class Accounting:
self.timestamp = caller.timestamp
self.billid = caller.billid
self.action = caller.action
self.billid = getID()
self.summary = f'{self.caller.orderid}:{self.caller.billid}'
self.providerid = caller.providerid
self.productid = caller.productid
self.accounting_orgid = accounting_orgid
self.resellerid = resellerid
self.customerid = customerid
self.resellerid = caller.resellerid
self.customerid = caller.customerid
self.own_salemode = None
self.reseller_salemode = None
self.variable = self.caller.varable
self.variable = caller.variable
async def setup_accounting_legs(self):
global accounting_config
@ -68,14 +62,18 @@ class Accounting:
else:
l['acc_dir'] = l['accounting_dir']
ac = ArgsConvert('${', '}$')
debug(f'{l["id"]},{l["amt_pattern"]=}')
try:
amtstr = ac.convert(l['amt_pattern'],
self.variable.copy()
)
debug(f'{l["amt_pattern"]=}, {amtstr=}, {self.variable=}')
if isinstance(amtstr, str):
l['amount'] = eval(amtstr)
else:
l['amount'] = amtstr
except Exception as e:
print(l['amt_pattern'], l['id'], self.variable)
exception(f'{e=}, {l['amt_pattern']}, {self.variable=}')
raise e
if l['amount'] is None:
@ -87,9 +85,9 @@ class Accounting:
credit_balance = 0.0
for l in legs:
if l['acc_dir'] == DEBT:
debt_balance += legs['amount']
debt_balance += l['amount']
else:
credit_balance += legs['amount']
credit_balance += l['amount']
if abs(credit_balance - debt_balance) >= 0.01:
e = Exception('accounting legs not balance')
exception(f'{legs=}, {e=}')
@ -102,14 +100,18 @@ class Accounting:
debug(f'do_accounting() ...{self.accounting_legs=}')
self.check_accounting_balance(self.accounting_legs)
for leg in self.accounting_legs:
accounting_orgid = await self.caller.get_accounting_orgid(sor, leg.accounting_orgtype)
orgid = await self.caller.get_accounting_orgid(sor, leg.orgtype)
accounting_orgid = await self.caller.get_orgid_by_trans_role(sor, leg.accounting_orgtype)
orgid = await self.caller.get_orgid_by_trans_role(sor, leg.orgtype)
org1id = None if leg.org1type is None else \
await self.caller.get_account_orgid(sor, leg.org1type)
await self.caller.get_orgid_by_trans_role(sor, leg.org1type)
acc = await get_account(sor, accounting_orgid, orgid, leg.subjectid, org1id=org1id)
if acc is None:
debug('can not get accountid {accounting_orgid=}, {leg=}')
raise AccountIdNone(self.accounting_orgid, orgid, leg['subjectname'])
debug(f'can not get accountid {accounting_orgid=}, {orgid=},{leg.subjectid=}, {org1id=}')
raise AccountIdNone(accounting_orgid, orgid, leg['subjectid'])
leg['_accounting_orgid'] = accounting_orgid
leg['_orgid'] = orgid
leg['_org1id'] = org1id
leg['acc'] = acc
await self.leg_accounting(sor, acc.id, leg)
async def write_settle_log(self):
@ -197,9 +199,9 @@ where accountid=${accid}$
# summary = self.summary
ns = {
'id':getID(),
'accounting_orgid' : self.accounting_orgid,
'accounting_orgid' : leg['accounting_orgid'],
'billid' : self.billid,
'description' : self.specstr,
'description' : self.summary,
'participantid' : leg['orgid'],
'participanttype' : leg['orgtype'],
'subjectname' : leg['subjectname'],
@ -214,7 +216,7 @@ where accountid=${accid}$
'acc_date':self.curdte,
'acc_timestamp':self.timestamp,
'acc_dir':leg['acc_dir'],
'summary':leg['summary'],
'summary':self.summary,
'amount':leg['amount'],
'billid':self.billid
}
@ -225,7 +227,7 @@ where accountid=${accid}$
'acc_date':self.curdate,
'acc_timestamp':self.timestamp,
'acc_dir':leg['acc_dir'],
'summary':leg['summary'],
'summary':self.summary,
'amount':leg['amount'],
'balance':leg['new_balance'],
'acclogid':logid

View File

@ -1,13 +1,14 @@
from appPublic.uniqueID import getID
from appPublic.dictObject import DictObject
from sqlor.dbpools import DBPools
from ahserver.serverenv import get_serverenv
from appPublic.argsConvert import ArgsConvert
import datetime
from .const import *
from .accountingnode import get_offer_orgs, get_parent_orgid
from .excep import *
from .getaccount import getAccountByName
from .accounting_config import get_accounting_config, AccountingOrgs
from .businessdate import get_business_date
from .accounting_config import get_accounting_config, Accounting
# from .settle import SettleAccounting
async def write_bill(sor, customerid, userid, orderid, business_op, amount):
@ -18,6 +19,7 @@ async def write_bill(sor, customerid, userid, orderid, business_op, amount):
bill.orderid = orderid
bill.business_op = business_op
bill.amount = amount
get_business_date = get_serverenv('get_business_date')
bill.bill_date = await get_business_date(sor)
bill_state = '0'
await sor.C('bill', bill.copy())

View File

@ -1,3 +1,4 @@
from appPublic.log import debug, exception
from sqlor.dbpools import DBPools
from .const import *
from accounting.accountingnode import get_parent_orgid
@ -13,18 +14,22 @@ async def get_account(sor, accounting_orgid, orgid, subjectid, org1id=None):
accounting_orgid = ${accounting_orgid}$ and
orgid = ${orgid}$ and
""" + ss
ns = {
"accounting_orgid":accounting_orgid,
"orgid":orgid,
"org1id":org1id,
"subjectid":subjectid
}
recs = await sor.sqlExe(sql, {
"accounting_orgid":accounting_orgid,
"orgid":orgid,
"org1id":org1id,
"subjectid":subjectid
});
})
if len(recs) == 0:
debug(f'{sql=}, {ns=}')
return None
for rec in recs:
if a.org1id == org1id:
return rec['id']
return None
return recs[0]
async def get_account_by_subjectname(sor, accounting_orgid, orgid, subjectname, org1id=None):
ss = "a.org1id is NULL"

View File

@ -1,18 +1,16 @@
from appPublic.registerfunction import RegisterFunction
from appPublic.dictOBject import DictObject
from appPublic.dictObject import DictObject
from appPublic.log import debug, exception, error
from ahserver.serverenv import ServerEnv
from accounting.accounting_config import AccountingOrgs
from accounting.accounting_config import Accounting
from accounting.bill import write_bill
from accounting.openaccount import openOwnerAccounts, openProviderAccounts, openResellerAccounts, openCustomerAccounts
def load_accounting():
g = ServerEnv()
g.recharge_accounting = recharge_accounting
g.pay_accounting = pay_accounting
g.settle_accounting = settle_accounting
g.open_customer_account = open_customer_account
g.open_reseller_account = open_reseller_account
g.open_provider_account = open_provider_account
g.open_owner_account = open_owner_account
g.get_customer_balance = get_customer_balance
g.Accounting = Accounting
g.write_bill = write_bill
g.openOwnerAccounts = openOwnerAccounts
g.openProviderAccounts = openProviderAccounts
g.openResellerAccounts = openResellerAccounts
g.openCustomerAccounts = openCustomerAccounts

View File

@ -1,7 +1,4 @@
{
"models_dir": "${HOME}$/py/accounting/models",
"output_dir": "${HOME}$/py/sage/wwwroot/accounting_config",
"dbname": "sage",
"tblname": "accounting_config",
"title":"账务设置",
"params": {