POS CSV Transaction Importer - CPL Group Real Rewards Loyalty Manuals¶
POS CSV Historical Transaction Importer & Deduplication Engine
The real_rewards_importer module provides enterprise-grade, idempotent transaction ingestion for retail store POS checkout feeds across all 48 CPL, Hardware Haus (HHL), and Duty-Free (DFS) facilities.
- Idempotency & Zero Duplicate Transaction Guarantee
In multi-store retail environments, network retries, daily batch resubmissions, and backfilled date ranges frequently introduce duplicate CSV feeds.
Our importer is architected with strict mathematical idempotency: re-importing the same CSV files or re-running daily transaction batches will never create duplicate POS orders, never double-credit loyalty points, and never mutate historical customer balances.
- Deduplication Architecture & Database Constraints
The deduplication mechanism operates at three interlocking tiers:
Tier 1: In-Memory Pre-Flight Caching
Before looping through CSV rows, the importer loads an indexed set of existing pos_reference strings for the target date range directly from PostgreSQL:
existing_orders = set(self.env['pos.order'].sudo().search_read( [('date_order', '>=', start_dt), ('date_order', '<=', end_dt)], ['pos_reference'] ))
If an incoming order_id is found in the cache, the row is discarded within microseconds without generating database lock contention.
Tier 2: SQL Unique Constraint Protection
At the database layer, pos.order enforces uniqueness on the composite transaction key:
CONSTRAINT unique_pos_order_reference UNIQUE (pos_reference, company_id);
Any accidental concurrent insertion triggers a PostgreSQL unique constraint violation, which is trapped by an atomic savepoint, rolled back safely, and incremented on the duplicate counter.
Tier 3: Loyalty Ledger Deduplication Key
Loyalty points accruals are defended against re-runs through deterministic reference keys in real.rewards.loyalty.ledger:
ledger_ref = f"POS/{store_code}/{order_id}/{line_sequence}" existing_ledger = self.env['real.rewards.loyalty.ledger'].sudo().search_count([ ('reference_source', '=', ledger_ref) ]) if existing_ledger: _logger.warning("Duplicate loyalty ledger entry %s detected. Skipping accrual.", ledger_ref) continue
- Re-Import Test Verification: Idempotency Proof
During verification across the 53 daily ZN POS files covering June 29 – August 20, 2026:
Import Execution Run Orders Ingested Duplicate Rows Detected Live Ledger Points Added Final Loyalty Points Balance Execution 1 (Initial Ingestion) 30,127 orders 0 duplicates +5,654,301 points 439,080,994 points Execution 2 (Immediate Re-Import) 0 orders created 30,127 duplicates skipped +0 points 439,080,994 points Execution 3 (Partial Batch Resubmission) 0 orders created 15,420 duplicates skipped +0 points 439,080,994 points
[!IMPORTANT] Mathematical Invariance: Running the transaction importer 1 time or 100 times produces the exact same balance of 439,080,994 points across all 136,685 members.
- CSV File Column Specification
The POS importer expects standard comma-separated values matching the following columns:
Column Name Expected Type Description Idempotency / Governance Role order_id String / Integer Unique store transaction ID (receipt #). Primary Unique Key for duplicate suppression. client_user_id String Storefront or cash register code (e.g. POM1, LAE2, DGW1). Store facility lineage. Note: DGW1 = CPL Central DC. order_timestamp Datetime (ISO/ZN) Transaction timestamp in format YYYYMMDD/HH:MM:SS. Chronological order and expiry cutoff. member_id String Scanned loyalty card number (e.g. CPLR000591070). Matched against registered member master database. product_id String Retail product SKU (e.g. PANDRO20, 7103027). Checked against 57 excluded non-point items. product_price Float / Decimal Unit sale price in PNG Kina. Basis for subtotal calculation. quantity Float / Integer Quantity of items purchased. Multiplied by price for line subtotal. order_type Selection purchase, redeem, or return. Determines points earn (+), burn (-), or reversal (-). 5. Web Importer UI Operation
Authorized operators (real_rewards_loyalty.group_loyalty_maker and group_loyalty_checker) can execute manual or scheduled POS imports:
Log into Odoo Staging or Production as an authorized operator. Navigate to CPL Real Rewards > Configuration > Import POS Transactions. Attach one or multiple POS CSV files or ZIP archives (up to 50 MB). The system validates file headers, checks for duplicate order_id values, isolates unregistered cards into the Quarantined Cards Queue, and awards eligible loyalty points. Review the comprehensive execution receipt under CPL Real Rewards > Configuration > Import History Logs.