- Updated core.py, init.py, opportunity_core.py, mysql.ddl.sql - Updated UI: base.ui, opportunity_management.ui - Added: opportunity.json, opportunity_stage_history.json - Added API files: opportunities CRUD, sales_stages_list, check_tables - Added UI/DSPY: opportunity_edit, opportunity_list, sales_stages_list
31 lines
1.0 KiB
Python
31 lines
1.0 KiB
Python
#!/usr/bin/env python3
|
|
# -*- coding: utf-8 -*-
|
|
"""Opportunity list API"""
|
|
import json
|
|
|
|
result = {'success': False, 'rows': [], 'total': 0}
|
|
|
|
try:
|
|
dbname = get_module_dbname('opportunity_management')
|
|
ns = {
|
|
'page': int(params_kw.get('page', 1)),
|
|
'rows': int(params_kw.get('rows', 20)),
|
|
'sort': 'created_at desc'
|
|
}
|
|
sql = "SELECT id, customer_id, customer_name, opportunity_name, estimated_amount, current_stage, expected_close_date, owner_id, owner_name, region, probability, status, created_at FROM opportunities"
|
|
|
|
async with DBPools().sqlorContext(dbname) as sor:
|
|
data = await sor.sqlExe(sql, ns)
|
|
if isinstance(data, dict):
|
|
result['total'] = data.get('total', 0)
|
|
result['rows'] = [dict(r) for r in data.get('rows', [])]
|
|
else:
|
|
result['rows'] = [dict(r) for r in (data or [])]
|
|
result['total'] = len(result['rows'])
|
|
result['success'] = True
|
|
|
|
except Exception as e:
|
|
result['error'] = str(e)
|
|
|
|
return json.dumps(result, ensure_ascii=False, default=str)
|