feat(business): preserve full Kingdee order structure
Store expanded Kingdee sales order header, line, and delivery-plan fields in the business facts database while preserving raw JSON at each level. Add migration-safe columns, a delivery-plan table, coverage for the official response shape, and database documentation. Validation: python3 -m unittest discover -v; python3 -m compileall obsidian_wiki tests; git diff --check.
This commit is contained in:
@@ -62,12 +62,15 @@ Tables:
|
||||
|
||||
- `sync_runs`: one row per Kingdee sync attempt, including status, cursor, record counts, and error text.
|
||||
- `raw_snapshots`: content-hashed raw JSON payloads for audit and replay.
|
||||
- `orders`: one normalized row per sales order.
|
||||
- `order_items`: normalized detail lines for product/quantity/line amount analysis.
|
||||
- `orders`: one normalized row per sales order. It keeps the query-critical fields (`order_id`, `order_no`, `order_date`, customer, status, organization, department, operator, currency, total amount, net amount, tax amount, address, comment) plus `raw_json` for the full original order header.
|
||||
- `order_items`: normalized material detail lines. It keeps material number/name/model, quantity, unit, price, tax-inclusive price, net amount, tax-inclusive amount, tax amount, delivery date, project, warehouse, and `raw_json` for the full original line.
|
||||
- `order_deliveries`: normalized delivery-plan rows from `billentry[].orderdeliverentry[]`. It keeps planned demand date, planned delivery date, planned quantity, planned base quantity, unit, receive address/place, remark, transport lead time, and `raw_json` for the full original delivery-plan row.
|
||||
- `customers`: customer lookup data observed from orders.
|
||||
- `products`: product lookup data observed from order lines.
|
||||
|
||||
Order upsert key: `order_id`, falling back to `order_no` when no explicit ID is present. Re-syncing the same order updates the existing row and replaces that order's detail lines.
|
||||
Order upsert key: `order_id`, falling back to `order_no` when no explicit ID is present. Re-syncing the same order updates the existing row and replaces that order's detail lines and delivery-plan rows.
|
||||
|
||||
`total_amount` is the statistic field used by monthly sales queries. For Kingdee sales orders it prefers `totalallamount` (价税合计) and falls back to other total fields only when the tax-inclusive total is absent. `total_net_amount`, `total_tax_amount`, and `total_all_amount` are stored separately so later reports can choose a different accounting basis without re-fetching historical payloads.
|
||||
|
||||
## Counting Basis
|
||||
|
||||
|
||||
Reference in New Issue
Block a user