fix: correct indentation in leg_accounting credit limit block
Two bugs fixed: 1. FATAL: lines 213-278 were indented inside the 'if new_balance < 0' block, causing all normal (positive balance) accounting operations to be skipped. All post-credit-check code now correctly at method body level (2 tabs). 2. LOGIC: added else clause to reset used_credit to 0 when balance returns to non-negative (e.g. after recharge). Previously used_credit stayed stale after account recovered from overdraft.
This commit is contained in:
parent
5da6ddd7d5
commit
5fa058add9
@ -197,26 +197,29 @@ class Accounting:
|
|||||||
e = Exception(f'{accid} account not exist')
|
e = Exception(f'{accid} account not exist')
|
||||||
exception(f'{e}')
|
exception(f'{e}')
|
||||||
raise e
|
raise e
|
||||||
account = accounts[0]
|
account = accounts[0]
|
||||||
new_balance = account.balance + leg['balance_amount']
|
new_balance = account.balance + leg['balance_amount']
|
||||||
|
|
||||||
# Check credit limit if balance goes negative
|
# Check credit limit if balance goes negative
|
||||||
if new_balance < -0.0000001:
|
if new_balance < -0.0000001:
|
||||||
credit_limit = await get_credit_limit_for_account(sor, accid)
|
credit_limit = await get_credit_limit_for_account(sor, accid)
|
||||||
if credit_limit is None or credit_limit['available_credit'] < abs(new_balance):
|
if credit_limit is None or credit_limit['available_credit'] < abs(new_balance):
|
||||||
e = AccountOverDraw(accid, account.balance, leg['amount'])
|
e = AccountOverDraw(accid, account.balance, leg['amount'])
|
||||||
exception(f'{e},{leg=}')
|
exception(f'{e},{leg=}')
|
||||||
raise e
|
raise e
|
||||||
# Update used credit
|
# Update used credit
|
||||||
await update_used_credit(sor, accid, abs(new_balance))
|
await update_used_credit(sor, accid, abs(new_balance))
|
||||||
|
else:
|
||||||
|
# Balance is non-negative, reset used credit if any
|
||||||
|
await update_used_credit(sor, accid, 0)
|
||||||
|
|
||||||
subjects = await sor.R('subject', {'id': leg['subjectid']})
|
subjects = await sor.R('subject', {'id': leg['subjectid']})
|
||||||
if len(subjects) > 0:
|
if len(subjects) > 0:
|
||||||
leg['subjectname'] = subjects[0].name
|
leg['subjectname'] = subjects[0].name
|
||||||
# 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}$ for update"""
|
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})
|
||||||
if len(recs) == 0:
|
if len(recs) == 0:
|
||||||
ns = {
|
ns = {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user