# Backlog - Market Price Import

Scope: code changes related only to `BR-PT-004 - Market Price Import`.

## PT-BL-001 - Enforce uniqueness at model level

- Status: done
- Implementation commit: `eaae2e5`
- Priority: high
- Source: [business rules/market-price-import.md](../business%20rules/market-price-import.md)
- Requirement: enforce uniqueness of `(price, price_date)` at model level without adding a database constraint yet.
- Work done:
  - added model-level validation on `price.price_value`
  - added Tryton message `price.msg_price_value_unique`
  - added targeted tests for duplicate create and duplicate write validation
- Validation status:
  - `git diff --check` passed
  - automated Python tests still need to be run in a working Tryton Python environment
- Expected code impact:
  - `modules/purchase_trade/pricing.py`
  - possibly `modules/price/price_value.py` if the validation belongs on the target model
- Expected tests:
  - importing a row for an existing `(price, price_date)` skips or updates according to `Overwrite existing price`
  - creating/editing duplicate `price.price_value` records at model level is rejected if validation is implemented on `price.price_value`

## PT-BL-002 - Use locale-aware slash date parsing

- Status: open
- Priority: medium
- Source: [business rules/market-price-import.md](../business%20rules/market-price-import.md)
- Requirement: prefer the user's/default locale date format for ambiguous slash dates, then fall back to the current parsing order only if no locale preference is available.
- Current behavior: `DD/MM/YYYY` is tried before `MM/DD/YYYY`.
- Expected code impact:
  - `modules/purchase_trade/pricing.py`
- Expected tests:
  - slash dates follow the configured/default locale when available
  - slash dates keep a deterministic fallback when locale is unavailable
  - existing accepted formats still work

## PT-BL-003 - Reject missing price_value

- Status: open
- Priority: high
- Source: [business rules/market-price-import.md](../business%20rules/market-price-import.md)
- Requirement: `price_value` is mandatory for imported rows. Missing `price_value` must be reported as a row error.
- Current behavior: empty `price_value` is imported as an empty value.
- Expected code impact:
  - `modules/purchase_trade/pricing.py`
- Expected tests:
  - missing `price_value` is reported in `errors`
  - missing `high_price`, `low_price`, and `open_price` remain allowed
  - valid `price_value` still imports and updates correctly

## PT-BL-004 - Detect duplicate rows inside the same Excel file

- Status: open
- Priority: high
- Source: [business rules/market-price-import.md](../business%20rules/market-price-import.md)
- Requirement: duplicate rows for the same `(price_index, price_date)` inside the same Excel file must be reported as row errors. The duplicate row must not import or update data.
- Expected code impact:
  - `modules/purchase_trade/pricing.py`
- Expected tests:
  - duplicate `(price_index, price_date)` rows in the same import produce row errors
  - first occurrence behavior remains unchanged
  - duplicate rows do not overwrite previous imported or updated values

## PT-BL-005 - Categorize import result errors

- Status: open
- Priority: medium
- Source: [business rules/market-price-import.md](../business%20rules/market-price-import.md)
- Requirement: distinguish business validation errors from file, parsing, and technical errors in the import result.
- Current behavior: row errors are grouped under one `Errors` section.
- Expected code impact:
  - `modules/purchase_trade/pricing.py`
  - `modules/purchase_trade/view/import_prices_result_form.xml` only if the result display needs more structure
- Expected tests:
  - result message separates business validation errors from parsing/technical errors
  - invalid workbook and missing required columns remain blocking `UserError`
  - row-level errors still let the import continue

## PT-BL-006 - Fix missing default currency on created price index

- Status: open
- Priority: high
- Source bug: [BUG-PT-001](../bugs.md#bug-pt-001---missing-default-currency-in-price-index-automatic-creation)
- Source rule: [business rules/market-price-import.md](../business%20rules/market-price-import.md)
- Requirement: when the market price import automatically creates a missing `price.price`, the created price index must have default currency `USD`.
- Current behavior: the created price index can miss the default currency even though the import specification expects `USD`.
- Expected code impact:
  - `modules/purchase_trade/pricing.py`
- Expected tests:
  - automatic price index creation assigns `price_currency` to the `USD` currency record
  - if the `USD` currency record cannot be found, behavior remains aligned with the rule for optional default references
