Qeasy Cloud
Get Started

Inventory Loss Sync in Practice: Posting Stocktake Differences from Jky to Kingdee Cloud

· 钟家寿· Integration Solutions· 7 views· 4 min read

What This Strategy Solves

The inventory loss document is what officially books the gap between physical stocktake results and on-hand inventory in the ERP ledger. On a real project, after a warehouse count, several hundred thousand in goods were still sitting under "in-transit" or "available" with no reconciliation — the root cause was that stocktake variances were not auto-generated into downstream documents, so warehouse staff had to key them in by hand. What we built on Qeasy (the data integration platform) was a single-strategy pipeline that pulls Jky's loss data in incremental windows and writes Kingdee Cloud inventory loss documents automatically, so variances are posted before the next day's books open.

Data Flow and Field Mapping

The pipeline is one-way: Jky → Qeasy → Kingdee Cloud.

On the source side, the stocktake query API is paginated. The time window is controlled by startPdDate and endPdDate, and a typical config uses "go back 2 days" as the incremental anchor to avoid missing records. In the response, stocktakeId is the business document number, stocktakeDate is the count date, and warehouseCode is the warehouse code.

On the target side, batchSave is called to write the entire inventory loss document along with its line entries. The table below shows the key field mapping:

MeaningSource (Jky)Target (Kingdee Cloud)Handling
Document numberstocktakeIdFBillNoDirect mapping
WarehousewarehouseCodeFStockOrgId / FDeptIdLookup via code mapping collection
Count datestocktakeDate (ms timestamp)FDateFROM_UNIXTIME → YYYY-MM-DD HH:mm:ss
Document type—FBillTypeIDHardcoded PK01_SYS
Line itemsBody arrayBody arrayHeader/body handled in stages

Note that warehouseCode on the Kingdee side maps to two dimensions: inventory organization and department. You need to look up a code mapping collection to translate the warehouse code into both organization and department internal IDs — otherwise saving fails with "organization is empty."

How to Configure in Qeasy

Source strategy: Pick the Jky platform, API wms.stocktake.get, type QUERY. In the request, set pageSize to 20 and startPdDate to _function DATE_FORMAT(DATE_ADD(NOW(),INTERVAL -2 DAY),'%Y-%m-%d 00:00:00') so the platform computes the window automatically each day. Turn on idCheck and set the number field to stocktakeId — Qeasy then deduplicates by document number for idempotency.

Target strategy: Pick the Kingdee Cloud platform, API batchSave, type EXECUTE. FBillNo uses {{stocktakeId}} directly from upstream. FStockOrgId and FDeptId both pull values via _findCollection find ... from {collection ID} where textField_l2ib4q9p={{warehouseCode}} — this is Qeasy's typical "centralized code mapping" pattern, where all warehouse mappings live in a single independent collection shared by both ends, so one change propagates across the whole pipeline.

FDate conversion is another common pitfall: stocktakeDate is a millisecond timestamp, and you have to use _function FROM_UNIXTIME(({{stocktakeDate}}/1000),'%Y-%m-%d %T') to convert it into the string format Kingdee recognizes.

Implementation Steps

Roll out in three phases for stability.

Phase 1: Anchor the incremental starting point. Pull all of Jky's inventory loss documents from the past 30 days into Kingdee in one full sync, so both ledgers align first. In Qeasy, use a temporary "full sync trigger" button to run this manually — don't put it on a schedule right away.

Phase 2: Attach the schedule. Source crontab: 10 2 * * * (2:10 AM daily). Target crontab: 30 2 * * * (2:30 AM daily). The 20-minute gap lets the source finish pulling and deduplicating before the target starts writing. Staggering is mandatory — otherwise the target writes while the source is still pulling, and you get "yesterday's documents only arriving today."

Phase 3: Trial run and cutover. Keep dual tracks for the first two weeks: don't close the manual Kingdee entry path, and let Qeasy-synced documents use a different document-type prefix. After reconciliation looks clean, switch to the formal type. The typical Qeasy customer pattern is exactly this "dual-track incremental/full": incremental runs automatically every day, and full sync is triggered manually as a monthly or on-demand fallback.

Pitfalls from Real Projects

  1. Code mapping only resolves organization, not department. The first launch only configured FStockOrgId, so saving failed with "department is empty." In Kingdee, a warehouse is bound to both inventory organization and department — both must be looked up. The safe approach is to list both dimensions when building the mapping table.

  2. Timestamp not converted. Passing stocktakeDate straight into FDate made Kingdee interpret it as 1970, so all document posting dates were wrong. Milliseconds → seconds, then FROM_UNIXTIME to a string — every step is required.

  3. Header and body sent in one shot. Inventory loss documents have line items, so we recommend processing header and body in two stages in Qeasy: confirm the header lands successfully first, then loop to write the body. A one-shot batchSave with a large body is prone to partial failures, and rollback is painful.

  4. Wrong idempotency key. Initially we used id as the idempotency key, but on the source side the lines under the same loss document number can be updated, which caused repeated writes. Switching to stocktakeId (the business document number) stabilized it.

  5. Count-time window too narrow. Setting the incremental anchor to "yesterday" caused all stocktake documents generated after midnight to be missed. Going back 2 days and extending the window to 23:59:59 is what actually works.

When This Applies — and When It Doesn't

Applies: warehouses doing daily counts, where T+1 posting to the financial ledger is required, and both systems expose full APIs in a private-deployment setup. Doesn't apply: when variance must be reflected in real time (use the live inventory adjustment interface instead of the loss document), when unapproved source data is being pushed downstream, or when the document type isn't enabled on the Kingdee side.

Original content. Please credit the source when reposting: https://www.qeasy.cloud/insights/solutions/strat-p2ea595-kingdee-cloud-8502-jy-bds-46505b84

Comments