Background Sync Logic
Background Sync & transactional integrity#
One of the core promises of UPH is that every transactional document (Invoice, Order, Entry) is tagged with the correct Party Master.
How it works#
When you link a Party Master to a Customer or Supplier, the system triggers a background synchronization process to ensure data consistency.
1. The Trigger#
The sync is triggered in two main scenarios:
- Linking: When a
Customeris first linked to aParty Master. - Merging: When two
Party Mastersare merged (via the Data Quality Dashboard).
2. The Background Job#
To prevent timeouts on large databases, the update happens via a queued background job (uph.party.controllers.mdm._update_party_master_references or similar).
Logic:
- System identifies all configured Document Types (Sales Invoice, Purchase Order, etc.).
- It queries for documents where
partymatches the changed Customer/Supplier. - It updates the
party_masterfield to the new Party Master ID. - Standard SQL update is used for speed, bypassing heavy framework validation for these maintenance updates.
3. Real-time Hook#
For new documents, a before_validate hook automatically fetches the party_master from the selected Customer/Supplier, ensuring new data is always correct from the moment of creation.