fix: _get_exchange_rates/_load_usage_log_bills直接用传入sor,去掉get_sor_context(None)导致的NoneType错误
This commit is contained in:
parent
ed0107347e
commit
5030e0640c
@ -118,11 +118,8 @@ async def _load_usage_log_bills(sor, last_sync):
|
|||||||
product_usage_log 通过 source_ref_table='llmusage' + source_ref_id=<luid> 关联 llmusage。
|
product_usage_log 通过 source_ref_table='llmusage' + source_ref_id=<luid> 关联 llmusage。
|
||||||
返回 {llmusage.id: {'sell_price': float, 'purchase_currency': str|None}, ...}
|
返回 {llmusage.id: {'sell_price': float, 'purchase_currency': str|None}, ...}
|
||||||
"""
|
"""
|
||||||
from sqlor.dbpools import get_sor_context
|
|
||||||
usage_log_map = {}
|
usage_log_map = {}
|
||||||
try:
|
try:
|
||||||
async with get_sor_context(sor.env if hasattr(sor, 'env') else None,
|
|
||||||
'product_management') as pm_sor:
|
|
||||||
sql = """
|
sql = """
|
||||||
SELECT pul.source_ref_id,
|
SELECT pul.source_ref_id,
|
||||||
pul.sell_price,
|
pul.sell_price,
|
||||||
@ -132,7 +129,7 @@ async def _load_usage_log_bills(sor, last_sync):
|
|||||||
WHERE pul.source_ref_table = 'llmusage'
|
WHERE pul.source_ref_table = 'llmusage'
|
||||||
AND pul.use_time >= ${last_sync}$
|
AND pul.use_time >= ${last_sync}$
|
||||||
"""
|
"""
|
||||||
rows = await pm_sor.sqlExe(sql, {'last_sync': last_sync})
|
rows = await sor.sqlExe(sql, {'last_sync': last_sync})
|
||||||
for r in rows:
|
for r in rows:
|
||||||
ref_id = r.source_ref_id if hasattr(r, 'source_ref_id') else r['source_ref_id']
|
ref_id = r.source_ref_id if hasattr(r, 'source_ref_id') else r['source_ref_id']
|
||||||
sell_price = r.sell_price if hasattr(r, 'sell_price') else r['sell_price']
|
sell_price = r.sell_price if hasattr(r, 'sell_price') else r['sell_price']
|
||||||
@ -148,15 +145,13 @@ async def _load_usage_log_bills(sor, last_sync):
|
|||||||
|
|
||||||
|
|
||||||
async def _get_exchange_rates(sor, stat_date):
|
async def _get_exchange_rates(sor, stat_date):
|
||||||
"""从 sage 库获取汇率表,返回 {currency: mid_rate} 字典"""
|
"""查询汇率表,返回 {currency: mid_rate} 字典"""
|
||||||
from sqlor.dbpools import get_sor_context
|
|
||||||
rates = {'CNY': 1.0}
|
rates = {'CNY': 1.0}
|
||||||
try:
|
try:
|
||||||
async with get_sor_context(sor.env if hasattr(sor, 'env') else None, 'accounting') as sage_sor:
|
|
||||||
sql = """SELECT from_currency, mid_rate FROM exchange_rate
|
sql = """SELECT from_currency, mid_rate FROM exchange_rate
|
||||||
WHERE to_currency = 'CNY' AND effective_date <= ${d}$
|
WHERE to_currency = 'CNY' AND effective_date <= ${d}$
|
||||||
ORDER BY effective_date DESC"""
|
ORDER BY effective_date DESC"""
|
||||||
rows = await sage_sor.sqlExe(sql, {'d': stat_date})
|
rows = await sor.sqlExe(sql, {'d': stat_date})
|
||||||
for r in rows:
|
for r in rows:
|
||||||
cur = r.from_currency if hasattr(r, 'from_currency') else r['from_currency']
|
cur = r.from_currency if hasattr(r, 'from_currency') else r['from_currency']
|
||||||
rate = r.mid_rate if hasattr(r, 'mid_rate') else r['mid_rate']
|
rate = r.mid_rate if hasattr(r, 'mid_rate') else r['mid_rate']
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user