From cc8cb54a8a6563e5386bf6a6d4e735f611f3ccdc Mon Sep 17 00:00:00 2001 From: yumoqing Date: Fri, 10 Apr 2026 22:40:52 +0800 Subject: [PATCH] bugfix --- accounting/accounting_config.py | 14 +++++++++++++- accounting/test_accounting.py | 14 ++++++++------ 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/accounting/accounting_config.py b/accounting/accounting_config.py index d2f7867..216d1f1 100644 --- a/accounting/accounting_config.py +++ b/accounting/accounting_config.py @@ -199,6 +199,13 @@ class Accounting: async def leg_accounting(self, sor, leg): # print(f'leg_accounting(), {leg=}') accid = leg['accid'] + sql = "select * from account where id=${accid}$ for update" + accounts = await sor.sqlExe(sql, {'accid': accid}) + if len(accounts) == 0: + e = Exception(f'{accid} account not exist') + exception(f'{e}') + raise e + account = accounts[0] if leg['amount'] < 0.00001: return subjects = await sor.R('subject', {'id': leg['subjectid']}) @@ -255,6 +262,7 @@ where accountid=${accid}$ ns = { 'id':getID(), 'accountid':accid, + 'acc_no': account.max_detailno + 1, 'acc_date':self.curdate, 'acc_timestamp':self.timestamp, 'acc_dir':leg['acc_dir'], @@ -264,5 +272,9 @@ where accountid=${accid}$ 'acclogid':logid } await sor.C('acc_detail', ns.copy()) - await sor.U('account', {'id': accid, 'balance': new_balance}) + await sor.U('account', { + 'id': accid, + 'max_detailno': account.max_detailno + 1, + 'balance': new_balance + }) diff --git a/accounting/test_accounting.py b/accounting/test_accounting.py index 9980e34..f36b955 100644 --- a/accounting/test_accounting.py +++ b/accounting/test_accounting.py @@ -21,11 +21,13 @@ async def get_orgid_by_username(sor, username): async def accounting(username): env = ServerEnv() - async with get_sor_context(env, 'accounting') as sor: - customerid = await get_orgid_by_username(sor, username) + customerid = None + for i in range(10): resellerid = '0' - ais = [] - for i in range(10): + async with get_sor_context(env, 'accounting') as sor: + ais = [] + if customerid is None: + customerid = await get_orgid_by_username(sor, username) d = DictObject() d.customerid = customerid d.resellerid = '0' @@ -40,8 +42,8 @@ async def accounting(username): "交易手续费": 0 } ais.append(d) - orderid = 'test_orderid' - await consume_accounting(sor, orderid, ais) + orderid = 'test_orderid' + await consume_accounting(sor, orderid, ais) async def main(): if len(sys.argv) < 2: