financial_management/wwwroot/api/receivables_create.dspy
yumoqing e3c19bc359 sync: local modifications to financial_management
- Updated financial_core.py
- Updated models/receivables.json
- Added mysql.ddl.sql
- Added API files: debug_receivables, receivables CRUD, test_env
- Added UI files: financial_vouchers, index, payments, receipts, receivable_edit, receivables
2026-04-28 18:53:13 +08:00

39 lines
2.1 KiB
Python

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""Receivable create API"""
import json, uuid, time
result = {'widgettype': 'Message', 'options': {'title': 'Error', 'message': 'Invalid request', 'type': 'error'}}
try:
contract_id = params_kw.get('contract_id', '').strip()
customer_id = params_kw.get('customer_id', '').strip()
receivable_amount = params_kw.get('receivable_amount', '0').strip()
due_date = params_kw.get('due_date', '').strip()
if not due_date:
result['options'] = {'title': 'Error', 'message': '到期日不能为空', 'type': 'error'}
else:
dbname = get_module_dbname('financial_management')
new_id = str(uuid.uuid4()).replace('-', '')
now = time.strftime('%Y-%m-%d %H:%M:%S')
async with DBPools().sqlorContext(dbname) as sor:
await sor.sqlExe("""INSERT INTO receivables (id, order_id, contract_id, customer_id, receivable_amount, received_amount, due_date, status, description, org_id, created_at, updated_at)
VALUES (${id}$, ${order_id}$, ${contract_id}$, ${customer_id}$, ${receivable_amount}$, ${received_amount}$, ${due_date}$, ${status}$, ${description}$, ${org_id}$, ${created_at}$, ${updated_at}$)""", {
'id': new_id, 'order_id': params_kw.get('order_id', '').strip(),
'contract_id': contract_id, 'customer_id': customer_id,
'receivable_amount': float(receivable_amount) if receivable_amount else 0,
'received_amount': 0, 'due_date': due_date,
'status': params_kw.get('status', 'pending').strip(),
'description': params_kw.get('description', '').strip(),
'org_id': params_kw.get('org_id', '').strip(),
'created_at': now, 'updated_at': now
})
result = {'widgettype': 'Message', 'options': {'title': 'Success', 'message': '应收账款创建成功', 'type': 'success'}}
except Exception as e:
result['options'] = {'title': 'Error', 'message': f'创建失败: {str(e)}', 'type': 'error'}
return json.dumps(result, ensure_ascii=False)