61 lines
1.7 KiB
Plaintext
61 lines
1.7 KiB
Plaintext
|
|
ns = params_kw.copy()
|
|
supplier_id = ns.get('supplier_id', '')
|
|
amount = ns.get('amount', 0)
|
|
payment_method = ns.get('payment_method', '')
|
|
transaction_no = ns.get('transaction_no', '')
|
|
remark = ns.get('remark', '')
|
|
|
|
if not supplier_id:
|
|
return json.dumps({'success': False, 'error': '请选择供应商'}, ensure_ascii=False)
|
|
if not amount or float(amount) <= 0:
|
|
return json.dumps({'success': False, 'error': '充值金额必须大于0'}, ensure_ascii=False)
|
|
|
|
acc_dbname = get_module_dbname('accounting')
|
|
userorgid = await get_userorgid()
|
|
acc_id = getID()
|
|
bill_id = getID()
|
|
|
|
# 创建充值记录到accounting_log
|
|
log_data = {
|
|
'id': acc_id,
|
|
'accountid': supplier_id,
|
|
'acc_date': curDateString(),
|
|
'acc_dir': 'C',
|
|
'amount': float(amount),
|
|
'summary': f'供应商充值 - {payment_method} {transaction_no}',
|
|
'business_op': '供应商充值',
|
|
'billid': bill_id,
|
|
'created_at': timestampstr()
|
|
}
|
|
|
|
# 创建bill记录
|
|
bill_data = {
|
|
'id': bill_id,
|
|
'customerid': supplier_id,
|
|
'resellerid': userorgid,
|
|
'business_op': '供应商充值',
|
|
'amount': float(amount),
|
|
'bill_date': curDateString(),
|
|
'bill_timestamp': timestampstr(),
|
|
'bill_state': '1'
|
|
}
|
|
|
|
db = DBPools()
|
|
try:
|
|
async with db.sqlorContext(acc_dbname) as sor:
|
|
await sor.C('bill', bill_data)
|
|
await sor.C('accounting_log', log_data)
|
|
|
|
debug(f'provider_recharge: created {acc_id}, supplier={supplier_id}, amt={amount}')
|
|
return json.dumps({
|
|
'success': True,
|
|
'message': f'充值记录已创建,金额: {amount}',
|
|
'id': acc_id,
|
|
'bill_id': bill_id
|
|
}, ensure_ascii=False, default=str)
|
|
|
|
except Exception as e:
|
|
debug(f'provider_recharge error: {format_exc()}')
|
|
return json.dumps({'success': False, 'error': f'充值失败: {str(e)}'}, ensure_ascii=False)
|