# Purchase Trade Import Prices Backlog Backlog of potential issues found during a targeted review of the `purchase_trade.import_prices` wizard. ## Findings ### Incomplete auto-created price indexes - Area: `modules/purchase_trade/pricing.py`, `_price_index_values` - Risk: medium - Current behavior: when `create_missing_price_index` is enabled, the wizard creates a `price.price` even if default references cannot be found. - Details: default references are searched by exact names: `Market price`, `USD`, `Argus EU`, and `Mt`. - Possible impact: imported prices may be attached to indexes without unit, currency, type, or calendar, which can later break or distort price conversions. - Suggested action: fail clearly when required defaults are missing, or expose /import a controlled mapping instead of relying on silent best-effort lookup. ### Duplicate price values for the same index and date - Area: `modules/purchase_trade/pricing.py`, `_import_rows`; `modules/price/price_value.py` - Risk: medium - Current behavior: the wizard searches an existing `price.price_value` with `limit=1` for a given `price` and `price_date`. - Details: no uniqueness constraint was found on `price.price_value` for `(price, price_date)`. - Possible impact: if duplicates already exist, only one record is updated, and later price reads may use a non-deterministic record. - Suggested action: add a duplicate detection step in the import wizard. Longer term, consider a unique constraint or a cleanup/migration if the database already contains duplicates. ### Strict forward month term formats - Area: `modules/purchase_trade/pricing.py`, `_as_month_term` - Risk: low to medium - Current behavior: forward month columns accept Excel date values or text in `YYYY-MM` format. - Details: common business labels such as `MAR26`, `Mar-26`, or `March 2026` are rejected. - Possible impact: valid user files may fail with `Invalid month term`. - Suggested action: confirm the real Excel template used by operators. If needed, support month abbreviations while keeping unambiguous validation. ### Fragile text number parsing - Area: `modules/purchase_trade/pricing.py`, `_as_float` - Risk: low to medium - Current behavior: blank values become `None`; comma decimals such as `75,25` are accepted. - Details: formatted text numbers such as `1 234,56`, `1,234.56`, or values with non-breaking spaces are not handled safely. - Possible impact: imports may fail on files where prices are pasted as formatted text instead of stored as numeric Excel cells. - Suggested action: normalize spaces and common thousand separators, or produce a clearer validation error with row/index context. ### Excel 1904 date system is not handled - Area: `modules/purchase_trade/pricing.py`, `_as_date` - Risk: low - Current behavior: numeric Excel dates are interpreted with the 1899-12-30 base. - Details: Excel workbooks using the 1904 date system would be shifted by about four years. - Possible impact: imported `price_date` or forward month terms could be wrong for uncommon workbook settings. - Suggested action: inspect workbook properties for the date system before converting numeric dates. ## Recently Fixed ### Forward prices only populated `price_value` - Area: `modules/purchase_trade/pricing.py`, `_read_forward_price_rows` - Status: fixed locally - Change: forward imports now copy each forward cell value into `price_value`, `open_price`, `low_price`, and `high_price`. - Regression coverage: `test_import_forward_prices_copies_value_to_ohl_fields` in `modules/purchase_trade/tests/test_module.py`.