This commit is contained in:
yumoqing 2026-04-10 20:45:55 +08:00
parent 78ef190c9d
commit 8613abf6c0
2 changed files with 11 additions and 6 deletions

View File

@ -151,13 +151,14 @@ class Accounting:
acc_balance = l['acc'].balance acc_balance = l['acc'].balance
if l['acc_dir'] != l['balance_at']: if l['acc_dir'] != l['balance_at']:
acc_balance -= l['amount'] acc_balance -= l['amount']
l['balance_amount'] = -l['amount']
else: else:
acc_balance += l['amount'] acc_balance += l['amount']
l['balance_amount'] = l['amount']
if acc_balance < 0.000001: if acc_balance < 0.000001:
e = AccountOverDraw(curacc, l['acc'].balance, l['amount']) e = AccountOverDraw(curacc, l['acc'].balance, l['amount'])
exception(f'{e},{legs=}') exception(f'{e},{legs=}')
raise e raise e
l['new_balance'] = acc_balance
if l['acc_dir'] == DEBT: if l['acc_dir'] == DEBT:
debt_balance += l['amount'] debt_balance += l['amount']
else: else:
@ -206,20 +207,23 @@ class Accounting:
# write acc_balance # write acc_balance
sql = """select * from acc_balance sql = """select * from acc_balance
where accountid=${accid}$ where accountid=${accid}$
and acc_date = ${curdate}$""" and acc_date = ${curdate}$ for update"""
recs = await sor.sqlExe(sql, {'accid':accid, 'curdate':self.curdate}) recs = await sor.sqlExe(sql, {'accid':accid, 'curdate':self.curdate})
new_balance = 0
if len(recs) == 0: if len(recs) == 0:
ns = { ns = {
'id':getID(), 'id':getID(),
'accountid':accid, 'accountid':accid,
'acc_date':self.curdate, 'acc_date':self.curdate,
'balance':leg['new_balance'] 'balance':leg['balance_amount']
} }
await sor.C('acc_balance', ns.copy()) await sor.C('acc_balance', ns.copy())
new_balance = leg['balance_amount']
else: else:
ns = recs[0] ns = recs[0]
ns['balance'] = leg['new_balance'] ns['balance'] += leg['balance_amount']
await sor.U('acc_balance', ns.copy()) await sor.U('acc_balance', ns.copy())
new_balance = ns['balance']
# summary = self.summary # summary = self.summary
ns = { ns = {
@ -256,8 +260,9 @@ where accountid=${accid}$
'acc_dir':leg['acc_dir'], 'acc_dir':leg['acc_dir'],
'summary':self.summary, 'summary':self.summary,
'amount':leg['amount'], 'amount':leg['amount'],
'balance':leg['new_balance'], 'balance':new_balance,
'acclogid':logid 'acclogid':logid
} }
await sor.C('acc_detail', ns.copy()) await sor.C('acc_detail', ns.copy())
await sor.U('account', {id: accid, 'balance': new_balance})

View File

@ -89,7 +89,7 @@
"target":"PopupWindow", "target":"PopupWindow",
"popup_options":{ "popup_options":{
"icon":"{{entire_url('imgs/accdetail.svg')}}", "icon":"{{entire_url('imgs/accdetail.svg')}}",
"title":"充值", "title":"明细",
{% if params_kw._is_mobile %} {% if params_kw._is_mobile %}
"width":"100%", "width":"100%",
"height":"95%" "height":"95%"