fix: DBPools() not in __init__, sqlorContext uses module name not default
This commit is contained in:
parent
4154d22ed2
commit
635f71ea52
@ -103,11 +103,16 @@
|
||||
"updated_at",
|
||||
"predicted_revenue"
|
||||
],
|
||||
"editable": {
|
||||
"new_data_url": "{{entire_url('../api/opportunities_create.dspy')}}",
|
||||
"update_data_url": "{{entire_url('../api/opportunities_update.dspy')}}",
|
||||
"delete_data_url": "{{entire_url('../api/opportunities_delete.dspy')}}"
|
||||
},
|
||||
"subtables": [
|
||||
{
|
||||
"field": "opportunity_id",
|
||||
"title": "阶段变更历史",
|
||||
"url": "{{entire_url('stage_history_list')}}",
|
||||
"url": "{{entire_url('../stage_history_list')}}",
|
||||
"subtable": "opportunity_stage_history"
|
||||
}
|
||||
]
|
||||
|
||||
@ -3,6 +3,11 @@
|
||||
"alias": "opportunities_edit",
|
||||
"title": "编辑商机",
|
||||
"params": {
|
||||
"editable": {
|
||||
"new_data_url": "{{entire_url('../api/opportunities_create.dspy')}}",
|
||||
"update_data_url": "{{entire_url('../api/opportunities_update.dspy')}}",
|
||||
"delete_data_url": "{{entire_url('../api/opportunities_delete.dspy')}}"
|
||||
},
|
||||
"formfields": {
|
||||
"exclouded": ["id", "customer_id", "owner_id", "org_id", "created_at", "updated_at"],
|
||||
"alters": {
|
||||
|
||||
@ -19,7 +19,7 @@ async def create_opportunity(
|
||||
) -> Dict:
|
||||
"""创建商机"""
|
||||
db = DBPools()
|
||||
async with db.sqlorContext('default') as sor:
|
||||
async with db.sqlorContext('opportunity_management') as sor:
|
||||
opportunity_id = str(uuid.uuid4()).replace('-', '')
|
||||
|
||||
# 验证客户是否存在
|
||||
@ -71,7 +71,7 @@ async def update_opportunity_stage(
|
||||
) -> Dict:
|
||||
"""更新商机阶段"""
|
||||
db = DBPools()
|
||||
async with db.sqlorContext('default') as sor:
|
||||
async with db.sqlorContext('opportunity_management') as sor:
|
||||
opportunity_records = await sor.R("opportunities", {"filters": [{"field": "id", "op": "=", "value": opportunity_id}]})
|
||||
if not opportunity_records or len(opportunity_records) == 0:
|
||||
raise ValueError("商机不存在")
|
||||
@ -123,7 +123,7 @@ async def assign_opportunity(
|
||||
) -> Dict:
|
||||
"""分配商机给销售人员"""
|
||||
db = DBPools()
|
||||
async with db.sqlorContext('default') as sor:
|
||||
async with db.sqlorContext('opportunity_management') as sor:
|
||||
opportunity_records = await sor.R("opportunities", {"filters": [{"field": "id", "op": "=", "value": opportunity_id}]})
|
||||
if not opportunity_records or len(opportunity_records) == 0:
|
||||
raise ValueError("商机不存在")
|
||||
@ -164,7 +164,7 @@ async def get_opportunity_funnel(
|
||||
) -> Dict:
|
||||
"""获取销售漏斗数据"""
|
||||
db = DBPools()
|
||||
async with db.sqlorContext('default') as sor:
|
||||
async with db.sqlorContext('opportunity_management') as sor:
|
||||
filters = []
|
||||
if start_date and end_date:
|
||||
filters.append({"field": "created_at", "op": ">=", "value": start_date})
|
||||
@ -211,7 +211,7 @@ async def get_sales_performance(
|
||||
) -> Dict:
|
||||
"""获取销售业绩数据"""
|
||||
db = DBPools()
|
||||
async with db.sqlorContext('default') as sor:
|
||||
async with db.sqlorContext('opportunity_management') as sor:
|
||||
# 查询已关闭的商机(赢单)
|
||||
won_filters = [
|
||||
{"field": "status", "op": "=", "value": "won"},
|
||||
|
||||
@ -24,7 +24,7 @@ async def create_opportunity(
|
||||
) -> Dict:
|
||||
"""创建商机"""
|
||||
db = DBPools()
|
||||
async with db.sqlorContext('default') as sor:
|
||||
async with db.sqlorContext('opportunity_management') as sor:
|
||||
opportunity_id = str(uuid.uuid4()).replace('-', '')
|
||||
|
||||
# 验证客户是否存在
|
||||
@ -76,7 +76,7 @@ async def update_opportunity_stage(
|
||||
) -> Dict:
|
||||
"""更新商机阶段"""
|
||||
db = DBPools()
|
||||
async with db.sqlorContext('default') as sor:
|
||||
async with db.sqlorContext('opportunity_management') as sor:
|
||||
opportunity_records = await sor.R("opportunities", {"filters": [{"field": "id", "op": "=", "value": opportunity_id}]})
|
||||
if not opportunity_records or len(opportunity_records) == 0:
|
||||
raise ValueError("商机不存在")
|
||||
@ -128,7 +128,7 @@ async def assign_opportunity(
|
||||
) -> Dict:
|
||||
"""分配商机给销售人员"""
|
||||
db = DBPools()
|
||||
async with db.sqlorContext('default') as sor:
|
||||
async with db.sqlorContext('opportunity_management') as sor:
|
||||
opportunity_records = await sor.R("opportunities", {"filters": [{"field": "id", "op": "=", "value": opportunity_id}]})
|
||||
if not opportunity_records or len(opportunity_records) == 0:
|
||||
raise ValueError("商机不存在")
|
||||
@ -169,7 +169,7 @@ async def get_opportunity_funnel(
|
||||
) -> Dict:
|
||||
"""获取销售漏斗数据"""
|
||||
db = DBPools()
|
||||
async with db.sqlorContext('default') as sor:
|
||||
async with db.sqlorContext('opportunity_management') as sor:
|
||||
filters = []
|
||||
if start_date and end_date:
|
||||
filters.append({"field": "created_at", "op": ">=", "value": start_date})
|
||||
@ -216,7 +216,7 @@ async def get_sales_performance(
|
||||
) -> Dict:
|
||||
"""获取销售业绩数据"""
|
||||
db = DBPools()
|
||||
async with db.sqlorContext('default') as sor:
|
||||
async with db.sqlorContext('opportunity_management') as sor:
|
||||
# 查询已关闭的商机(赢单)
|
||||
won_filters = [
|
||||
{"field": "status", "op": "=", "value": "won"},
|
||||
@ -273,7 +273,7 @@ async def predict_revenue(start_date: str, end_date: str):
|
||||
|
||||
async def update_opportunity(opportunity_id: str, **updates):
|
||||
db = DBPools()
|
||||
async with db.sqlorContext('default') as sor:
|
||||
async with db.sqlorContext('opportunity_management') as sor:
|
||||
updates["updated_at"] = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
||||
await sor.U(
|
||||
"opportunities",
|
||||
@ -284,7 +284,7 @@ async def update_opportunity(opportunity_id: str, **updates):
|
||||
|
||||
async def delete_opportunity(opportunity_id: str):
|
||||
db = DBPools()
|
||||
async with db.sqlorContext('default') as sor:
|
||||
async with db.sqlorContext('opportunity_management') as sor:
|
||||
await sor.D(
|
||||
"opportunities",
|
||||
{"filters": [{"field": "id", "op": "=", "value": opportunity_id}]}
|
||||
@ -293,13 +293,13 @@ async def delete_opportunity(opportunity_id: str):
|
||||
|
||||
async def get_opportunity_by_id(opportunity_id: str):
|
||||
db = DBPools()
|
||||
async with db.sqlorContext('default') as sor:
|
||||
async with db.sqlorContext('opportunity_management') as sor:
|
||||
records = await sor.R("opportunities", {"filters": [{"field": "id", "op": "=", "value": opportunity_id}]})
|
||||
return records[0] if records else None
|
||||
|
||||
async def list_opportunities(**filters):
|
||||
db = DBPools()
|
||||
async with db.sqlorContext('default') as sor:
|
||||
async with db.sqlorContext('opportunity_management') as sor:
|
||||
filter_list = []
|
||||
for field, value in filters.items():
|
||||
filter_list.append({"field": field, "op": "=", "value": value})
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user