diff --git a/json/opportunities.json b/json/opportunities.json index 7852af0..9e8f5ac 100644 --- a/json/opportunities.json +++ b/json/opportunities.json @@ -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" } ] diff --git a/json/opportunities_edit.json b/json/opportunities_edit.json index 0959fd5..f8fe716 100644 --- a/json/opportunities_edit.json +++ b/json/opportunities_edit.json @@ -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": { diff --git a/opportunity_management/core.py b/opportunity_management/core.py index eee20c3..e6feccb 100644 --- a/opportunity_management/core.py +++ b/opportunity_management/core.py @@ -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"}, diff --git a/opportunity_management/opportunity_core.py b/opportunity_management/opportunity_core.py index 2779a18..889a7fb 100644 --- a/opportunity_management/opportunity_core.py +++ b/opportunity_management/opportunity_core.py @@ -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})