bugfix
This commit is contained in:
parent
2f8822aa77
commit
96a21d0c01
@ -5,7 +5,7 @@ from .accountingnode import get_parent_orgid
|
|||||||
from .excep import *
|
from .excep import *
|
||||||
from .getaccount import get_account, getAccountByName
|
from .getaccount import get_account, getAccountByName
|
||||||
from appPublic.uniqueID import getID
|
from appPublic.uniqueID import getID
|
||||||
from appPublic.log import debug
|
from appPublic.log import debug, exception
|
||||||
from sqlor.dbpools import DBPools
|
from sqlor.dbpools import DBPools
|
||||||
from appPublic.timeUtils import curDateString
|
from appPublic.timeUtils import curDateString
|
||||||
# from .argsconvert import ArgsConvert
|
# from .argsconvert import ArgsConvert
|
||||||
@ -25,17 +25,13 @@ async def get_accounting_config(sor):
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
class Accounting:
|
class Accounting:
|
||||||
/*
|
"""
|
||||||
需要caller功能:
|
需要caller功能:
|
||||||
caller中要有分录中的变量
|
caller中要有分录中的变量
|
||||||
get_accounting_orgid(leg) 获得记账机构
|
get_accounting_orgid(leg) 获得记账机构
|
||||||
get_account(leg,accounting_orgid) 获得记账账号(通过科目,机构类型,账务机构确定一个唯一的账号)
|
get_account(leg,accounting_orgid) 获得记账账号(通过科目,机构类型,账务机构确定一个唯一的账号)
|
||||||
*/
|
"""
|
||||||
def __init__(self, caller,
|
def __init__(self, caller):
|
||||||
accounting_orgid,
|
|
||||||
customerid,
|
|
||||||
resellerid=None
|
|
||||||
):
|
|
||||||
self.caller = caller
|
self.caller = caller
|
||||||
self.curdate = caller.curdate
|
self.curdate = caller.curdate
|
||||||
self.realtimesettled = False
|
self.realtimesettled = False
|
||||||
@ -43,16 +39,14 @@ class Accounting:
|
|||||||
self.timestamp = caller.timestamp
|
self.timestamp = caller.timestamp
|
||||||
self.billid = caller.billid
|
self.billid = caller.billid
|
||||||
self.action = caller.action
|
self.action = caller.action
|
||||||
self.billid = getID()
|
|
||||||
self.summary = f'{self.caller.orderid}:{self.caller.billid}'
|
self.summary = f'{self.caller.orderid}:{self.caller.billid}'
|
||||||
self.providerid = caller.providerid
|
self.providerid = caller.providerid
|
||||||
self.productid = caller.productid
|
self.productid = caller.productid
|
||||||
self.accounting_orgid = accounting_orgid
|
self.resellerid = caller.resellerid
|
||||||
self.resellerid = resellerid
|
self.customerid = caller.customerid
|
||||||
self.customerid = customerid
|
|
||||||
self.own_salemode = None
|
self.own_salemode = None
|
||||||
self.reseller_salemode = None
|
self.reseller_salemode = None
|
||||||
self.variable = self.caller.varable
|
self.variable = caller.variable
|
||||||
|
|
||||||
async def setup_accounting_legs(self):
|
async def setup_accounting_legs(self):
|
||||||
global accounting_config
|
global accounting_config
|
||||||
@ -68,14 +62,18 @@ class Accounting:
|
|||||||
else:
|
else:
|
||||||
l['acc_dir'] = l['accounting_dir']
|
l['acc_dir'] = l['accounting_dir']
|
||||||
ac = ArgsConvert('${', '}$')
|
ac = ArgsConvert('${', '}$')
|
||||||
debug(f'{l["id"]},{l["amt_pattern"]=}')
|
|
||||||
try:
|
try:
|
||||||
amtstr = ac.convert(l['amt_pattern'],
|
amtstr = ac.convert(l['amt_pattern'],
|
||||||
self.variable.copy()
|
self.variable.copy()
|
||||||
)
|
)
|
||||||
l['amount'] = eval(amtstr)
|
debug(f'{l["amt_pattern"]=}, {amtstr=}, {self.variable=}')
|
||||||
|
if isinstance(amtstr, str):
|
||||||
|
l['amount'] = eval(amtstr)
|
||||||
|
else:
|
||||||
|
l['amount'] = amtstr
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(l['amt_pattern'], l['id'], self.variable)
|
exception(f'{e=}, {l['amt_pattern']}, {self.variable=}')
|
||||||
raise e
|
raise e
|
||||||
|
|
||||||
if l['amount'] is None:
|
if l['amount'] is None:
|
||||||
@ -87,9 +85,9 @@ class Accounting:
|
|||||||
credit_balance = 0.0
|
credit_balance = 0.0
|
||||||
for l in legs:
|
for l in legs:
|
||||||
if l['acc_dir'] == DEBT:
|
if l['acc_dir'] == DEBT:
|
||||||
debt_balance += legs['amount']
|
debt_balance += l['amount']
|
||||||
else:
|
else:
|
||||||
credit_balance += legs['amount']
|
credit_balance += l['amount']
|
||||||
if abs(credit_balance - debt_balance) >= 0.01:
|
if abs(credit_balance - debt_balance) >= 0.01:
|
||||||
e = Exception('accounting legs not balance')
|
e = Exception('accounting legs not balance')
|
||||||
exception(f'{legs=}, {e=}')
|
exception(f'{legs=}, {e=}')
|
||||||
@ -102,14 +100,18 @@ class Accounting:
|
|||||||
debug(f'do_accounting() ...{self.accounting_legs=}')
|
debug(f'do_accounting() ...{self.accounting_legs=}')
|
||||||
self.check_accounting_balance(self.accounting_legs)
|
self.check_accounting_balance(self.accounting_legs)
|
||||||
for leg in self.accounting_legs:
|
for leg in self.accounting_legs:
|
||||||
accounting_orgid = await self.caller.get_accounting_orgid(sor, leg.accounting_orgtype)
|
accounting_orgid = await self.caller.get_orgid_by_trans_role(sor, leg.accounting_orgtype)
|
||||||
orgid = await self.caller.get_accounting_orgid(sor, leg.orgtype)
|
orgid = await self.caller.get_orgid_by_trans_role(sor, leg.orgtype)
|
||||||
org1id = None if leg.org1type is None else \
|
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)
|
acc = await get_account(sor, accounting_orgid, orgid, leg.subjectid, org1id=org1id)
|
||||||
if acc is None:
|
if acc is None:
|
||||||
debug('can not get accountid {accounting_orgid=}, {leg=}')
|
debug(f'can not get accountid {accounting_orgid=}, {orgid=},{leg.subjectid=}, {org1id=}')
|
||||||
raise AccountIdNone(self.accounting_orgid, orgid, leg['subjectname'])
|
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)
|
await self.leg_accounting(sor, acc.id, leg)
|
||||||
|
|
||||||
async def write_settle_log(self):
|
async def write_settle_log(self):
|
||||||
@ -197,9 +199,9 @@ where accountid=${accid}$
|
|||||||
# summary = self.summary
|
# summary = self.summary
|
||||||
ns = {
|
ns = {
|
||||||
'id':getID(),
|
'id':getID(),
|
||||||
'accounting_orgid' : self.accounting_orgid,
|
'accounting_orgid' : leg['accounting_orgid'],
|
||||||
'billid' : self.billid,
|
'billid' : self.billid,
|
||||||
'description' : self.specstr,
|
'description' : self.summary,
|
||||||
'participantid' : leg['orgid'],
|
'participantid' : leg['orgid'],
|
||||||
'participanttype' : leg['orgtype'],
|
'participanttype' : leg['orgtype'],
|
||||||
'subjectname' : leg['subjectname'],
|
'subjectname' : leg['subjectname'],
|
||||||
@ -214,7 +216,7 @@ where accountid=${accid}$
|
|||||||
'acc_date':self.curdte,
|
'acc_date':self.curdte,
|
||||||
'acc_timestamp':self.timestamp,
|
'acc_timestamp':self.timestamp,
|
||||||
'acc_dir':leg['acc_dir'],
|
'acc_dir':leg['acc_dir'],
|
||||||
'summary':leg['summary'],
|
'summary':self.summary,
|
||||||
'amount':leg['amount'],
|
'amount':leg['amount'],
|
||||||
'billid':self.billid
|
'billid':self.billid
|
||||||
}
|
}
|
||||||
@ -225,7 +227,7 @@ where accountid=${accid}$
|
|||||||
'acc_date':self.curdate,
|
'acc_date':self.curdate,
|
||||||
'acc_timestamp':self.timestamp,
|
'acc_timestamp':self.timestamp,
|
||||||
'acc_dir':leg['acc_dir'],
|
'acc_dir':leg['acc_dir'],
|
||||||
'summary':leg['summary'],
|
'summary':self.summary,
|
||||||
'amount':leg['amount'],
|
'amount':leg['amount'],
|
||||||
'balance':leg['new_balance'],
|
'balance':leg['new_balance'],
|
||||||
'acclogid':logid
|
'acclogid':logid
|
||||||
|
@ -1,13 +1,14 @@
|
|||||||
from appPublic.uniqueID import getID
|
from appPublic.uniqueID import getID
|
||||||
|
from appPublic.dictObject import DictObject
|
||||||
from sqlor.dbpools import DBPools
|
from sqlor.dbpools import DBPools
|
||||||
|
from ahserver.serverenv import get_serverenv
|
||||||
from appPublic.argsConvert import ArgsConvert
|
from appPublic.argsConvert import ArgsConvert
|
||||||
import datetime
|
import datetime
|
||||||
from .const import *
|
from .const import *
|
||||||
from .accountingnode import get_offer_orgs, get_parent_orgid
|
from .accountingnode import get_offer_orgs, get_parent_orgid
|
||||||
from .excep import *
|
from .excep import *
|
||||||
from .getaccount import getAccountByName
|
from .getaccount import getAccountByName
|
||||||
from .accounting_config import get_accounting_config, AccountingOrgs
|
from .accounting_config import get_accounting_config, Accounting
|
||||||
from .businessdate import get_business_date
|
|
||||||
# from .settle import SettleAccounting
|
# from .settle import SettleAccounting
|
||||||
|
|
||||||
async def write_bill(sor, customerid, userid, orderid, business_op, amount):
|
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.orderid = orderid
|
||||||
bill.business_op = business_op
|
bill.business_op = business_op
|
||||||
bill.amount = amount
|
bill.amount = amount
|
||||||
|
get_business_date = get_serverenv('get_business_date')
|
||||||
bill.bill_date = await get_business_date(sor)
|
bill.bill_date = await get_business_date(sor)
|
||||||
bill_state = '0'
|
bill_state = '0'
|
||||||
await sor.C('bill', bill.copy())
|
await sor.C('bill', bill.copy())
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
from appPublic.log import debug, exception
|
||||||
from sqlor.dbpools import DBPools
|
from sqlor.dbpools import DBPools
|
||||||
from .const import *
|
from .const import *
|
||||||
from accounting.accountingnode import get_parent_orgid
|
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
|
accounting_orgid = ${accounting_orgid}$ and
|
||||||
orgid = ${orgid}$ and
|
orgid = ${orgid}$ and
|
||||||
""" + ss
|
""" + ss
|
||||||
|
ns = {
|
||||||
|
"accounting_orgid":accounting_orgid,
|
||||||
|
"orgid":orgid,
|
||||||
|
"org1id":org1id,
|
||||||
|
"subjectid":subjectid
|
||||||
|
}
|
||||||
recs = await sor.sqlExe(sql, {
|
recs = await sor.sqlExe(sql, {
|
||||||
"accounting_orgid":accounting_orgid,
|
"accounting_orgid":accounting_orgid,
|
||||||
"orgid":orgid,
|
"orgid":orgid,
|
||||||
"org1id":org1id,
|
"org1id":org1id,
|
||||||
"subjectid":subjectid
|
"subjectid":subjectid
|
||||||
});
|
})
|
||||||
if len(recs) == 0:
|
if len(recs) == 0:
|
||||||
|
debug(f'{sql=}, {ns=}')
|
||||||
return None
|
return None
|
||||||
for rec in recs:
|
return recs[0]
|
||||||
if a.org1id == org1id:
|
|
||||||
return rec['id']
|
|
||||||
return None
|
|
||||||
|
|
||||||
async def get_account_by_subjectname(sor, accounting_orgid, orgid, subjectname, org1id=None):
|
async def get_account_by_subjectname(sor, accounting_orgid, orgid, subjectname, org1id=None):
|
||||||
ss = "a.org1id is NULL"
|
ss = "a.org1id is NULL"
|
||||||
|
@ -1,18 +1,16 @@
|
|||||||
from appPublic.registerfunction import RegisterFunction
|
from appPublic.registerfunction import RegisterFunction
|
||||||
from appPublic.dictOBject import DictObject
|
from appPublic.dictObject import DictObject
|
||||||
from appPublic.log import debug, exception, error
|
from appPublic.log import debug, exception, error
|
||||||
from ahserver.serverenv import ServerEnv
|
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.bill import write_bill
|
||||||
|
from accounting.openaccount import openOwnerAccounts, openProviderAccounts, openResellerAccounts, openCustomerAccounts
|
||||||
|
|
||||||
def load_accounting():
|
def load_accounting():
|
||||||
g = ServerEnv()
|
g = ServerEnv()
|
||||||
g.recharge_accounting = recharge_accounting
|
g.Accounting = 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.write_bill = write_bill
|
g.write_bill = write_bill
|
||||||
|
g.openOwnerAccounts = openOwnerAccounts
|
||||||
|
g.openProviderAccounts = openProviderAccounts
|
||||||
|
g.openResellerAccounts = openResellerAccounts
|
||||||
|
g.openCustomerAccounts = openCustomerAccounts
|
||||||
|
@ -1,7 +1,4 @@
|
|||||||
{
|
{
|
||||||
"models_dir": "${HOME}$/py/accounting/models",
|
|
||||||
"output_dir": "${HOME}$/py/sage/wwwroot/accounting_config",
|
|
||||||
"dbname": "sage",
|
|
||||||
"tblname": "accounting_config",
|
"tblname": "accounting_config",
|
||||||
"title":"账务设置",
|
"title":"账务设置",
|
||||||
"params": {
|
"params": {
|
||||||
|
Loading…
Reference in New Issue
Block a user