feat(business): exclude intercompany transfer orders
Allow operators to configure internal company names and identifiers, then apply the filter consistently across business templates and query routing. Preserve direct external-customer orders and provide explicit CLI and environment overrides for internal-flow audits. Validation: python -m unittest tests.test_business_facts tests.test_wiki_skills tests.test_user_ops -v (25 tests)
This commit is contained in:
@@ -97,6 +97,8 @@ Order upsert key: `order_id`, falling back to `order_no` when no explicit ID is
|
||||
|
||||
`wiki-query` decides semantically whether a user question needs business facts. When it does, it loads `obsidian-wiki business schema --json`, chooses a template if one fits, and only then uses guarded SQL for gaps. For hybrid questions about customers, products, salespeople, projects, delivery risk, anomalies, rankings, or quality impact, it runs two tracks: ordinary wiki retrieval for context/citations and business facts retrieval for structured metrics, then fuses the results in one answer.
|
||||
|
||||
For multi-company sales architectures, configure `OBSIDIAN_BUSINESS_INTERNAL_PARTIES` and/or `OBSIDIAN_BUSINESS_INTERNAL_PARTY_IDS` in `.env`. Templates then exclude intercompany transfer orders by default: an order is excluded only when both the sales organization and the ordering customer match configured internal parties. This keeps true external orders placed directly with a factory, while removing internal flow such as a sales company ordering from a factory. Set `OBSIDIAN_BUSINESS_INCLUDE_INTERNAL_ORDERS=true` or pass `--include-internal-orders` only when auditing internal transfers.
|
||||
|
||||
Template families include:
|
||||
|
||||
- Order totals: `order_count`, `sales_amount`, `customer_count`, `product_count`, `quantity_sum`, `avg_order_amount`.
|
||||
@@ -113,6 +115,7 @@ Core counting basis:
|
||||
- Ordered quantity: `SUM(order_items.quantity)` by `orders.order_date`.
|
||||
- Delivery-plan quantity: `SUM(order_deliveries.plan_qty)` by `order_deliveries.plan_date`.
|
||||
- Staff templates join `orders` to `order_staff`, defaulting to `primary_sales`.
|
||||
- When internal parties are configured, all built-in templates apply the intercompany dedupe filter before counting, summing, ranking, listing, or joining staff/delivery rows.
|
||||
|
||||
Every answer includes the statistic, counting basis, data source, and last successful sync time. If the last successful sync is before the query date, the answer warns that newer data may be missing.
|
||||
|
||||
@@ -126,6 +129,8 @@ If no template matches, `wiki-query` may generate guarded SQL and execute it thr
|
||||
- no write, schema, attach, pragma, or vacuum statements
|
||||
- default result limit is 100 rows, capped at 1000
|
||||
|
||||
When using guarded SQL for normal customer-facing sales metrics, apply the same intercompany dedupe rule manually unless the question is explicitly about internal transfer flow.
|
||||
|
||||
## Incremental Sync
|
||||
|
||||
`scripts/obsidian-wiki-ops.py kingdee sync --incremental` uses Kingdee `start_modifytime`.
|
||||
|
||||
Reference in New Issue
Block a user