Hardware Integration & Weights
Relevant source files
The following files were used as context for generating this wiki page:
DRX utilizes a sophisticated weight-based system designed for retail environments where products are sold in fractional quantities (e.g., grams or ounces). This system integrates hardware-centric logic for precise inventory tracking, automated cost-per-gram calculations, and random inventory checks to ensure physical stock matches digital records. The architecture supports both canonical stock management and dynamic unit conversions to maintain high accuracy during high-speed mobile POS operations.
Sources: README.md:14-16, scripts/help-center-data.ts:246-252, db/migrations/20250228000001_pos_weight_shrinkage_loyalty_consolidated.sql:1-10
Weight-Based Sales Architecture
The weight-based system is built upon a schema that extends standard inventory items with metric-specific fields. Products are categorized by measurement type—liquids in ounces (oz) and solids in grams (g)—allowing the system to automatically determine the appropriate unit during transaction processing.
Inventory Schema Extensions
The database is extended to support high-precision decimal values for weights and costs. Key columns added to the inventory table include:
base_unit: Defaults to 'g'.inventory_in_grams: Tracks the total weight of physical stock.price_per_gram: Enables dynamic calculation of line item totals based on weight.allow_fractional_weight: A boolean flag allowing or restricting precise weighing at checkout.
Sources: db/migrations/20250228000001_pos_weight_shrinkage_loyalty_consolidated.sql:50-55, README.md:126-130
Transaction Logic Flow
When a weight-based item is sold, the system executes a specialized Remote Procedure Call (RPC) to calculate pricing and deduct weight from the inventory.
This flow ensures that inventory levels are updated in real-time, preventing "Negative Inventory" scenarios where more weight is sold than recorded.
Sources: db/migrations/20250228000001_pos_weight_shrinkage_loyalty_consolidated.sql:530-560, scripts/help-center-data.ts:380-385
Inventory Intake and Cost Tracking
The inventory intake workflow is the primary method for adding new stock and establishing the cost basis for products. It utilizes a calculated "Cost Per Gram" model to ensure profitability tracking.
Intake Calculation Logic
The system calculates the cost per unit automatically during the intake process using the following variables:
- Total Product Cost: The bulk price paid.
- Total Weight Received: The physical mass added to stock.
- Cost Per Gram: Calculated as
Total Cost / Total Weight.
Sources: app/(app)/inventory/intake/page.tsx:64-70, test-inventory-intake.sh:65-70
Intake Validation and Approvals
Intakes that deviate significantly from historical averages (e.g., >50% deviation) may trigger a manager approval requirement to prevent data entry errors.
| Field | Requirement | Description |
|---|---|---|
inventory_id | Required | Unique identifier for the product. |
total_cost | Required | Must be > 0. |
total_weight_grams | Required | Minimum value of 0.01g. |
delivery_cost | Optional | Not included in the cost-per-gram calculation. |
Sources: app/(app)/inventory/intake/page.tsx:83-100, test-inventory-intake.sh:85-95
Random Inventory Checks & Shrinkage
To ensure compliance and accuracy, DRX implements hardware-triggerable random inventory checks. This system prompts staff to weigh physical products at specified intervals to verify digital records.
Random Check Mechanism
A transaction counter monitors sales activity. Once the random_inventory_check_frequency threshold is met, the system identifies a product for verification.
The logic uses a random_check_tolerance_percentage (default 5.0%) to determine if a discrepancy is significant enough to flag.
Sources: db/migrations/20250228000001_pos_weight_shrinkage_loyalty_consolidated.sql:430-450, db/migrations/20250228000001_pos_weight_shrinkage_loyalty_consolidated.sql:515-528
Shrinkage and Variance Handling
If a discrepancy is found during a check where measured weight is less than expected weight, the system automatically records a shrinkage_event with the type inventory_variance.
- Shrinkage Types: Personal Use, Comps, Damaged, Theft, and Inventory Variance.
- Audit Trail: Every shrinkage event records the user ID, weight lost, and the calculated cost value of that loss.
Sources: db/migrations/20250228000001_pos_weight_shrinkage_loyalty_consolidated.sql:23-35, db/migrations/20250228000001_pos_weight_shrinkage_loyalty_consolidated.sql:370-390
Bulk Pricing Rules
DRX supports tiered pricing based on weight, allowing businesses to offer discounts for larger quantities automatically.
Pricing Tiers Configuration
Rules are evaluated based on the weight entered at the POS. The system searches for the most specific rule (Inventory ID + Weight Range) before falling back to business-wide defaults.
-- Example Pricing Tiers from Business Settings
'[
{"min_grams": 1, "max_grams": 3.4, "tier_name": "1g"},
{"min_grams": 3.5, "max_grams": 6.9, "tier_name": "3.5g"},
{"min_grams": 7, "max_grams": 9.9, "tier_name": "7g"},
{"min_grams": 10, "max_grams": null, "tier_name": "10g+"}
]'
Sources: db/migrations/20250228000001_pos_weight_shrinkage_loyalty_consolidated.sql:75-80, db/migrations/20250228000001_pos_weight_shrinkage_loyalty_consolidated.sql:475-485
Technical Implementation Summary
The weight engine relies on transactional integrity provided by PostgreSQL. All inventory adjustments, whether via sale, intake, or shrinkage, are logged in the stock_movements table to provide a complete audit trail of the physical-to-digital state.
| Feature | Implementation | Source |
|---|---|---|
| Stock Movement | stock_movements table | db/migrations/20250228000001_pos_weight_shrinkage_loyalty_consolidated.sql:100-110 |
| Drawer Events | drawer_events table | db/migrations/20250228000001_pos_weight_shrinkage_loyalty_consolidated.sql:12-20 |
| Intake Logic | /api/inventory/intake | app/(app)/inventory/intake/page.tsx:112-120 |
| Security | Row Level Security (RLS) | db/migrations/20250228000001_pos_weight_shrinkage_loyalty_consolidated.sql:130-150 |
The integration of weights into the core POS and Inventory modules ensures that high-precision retail operations remain accurate, auditable, and performant on mobile hardware.