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