## ADDED Requirements

### Requirement: Product search offers a unit choice per matching entry
When a cashier searches the POS by product name (not exact barcode) and a matched product has multiple configured units, the search results SHALL list one selectable entry per unit (base unit plus every configured conversion unit), each showing that unit's own price, rather than a single entry priced at only the default unit.

#### Scenario: Product with multiple units shows one entry per unit
- **WHEN** a cashier searches by name and a matched product has a base unit and 2 configured conversion units
- **THEN** the results list 3 entries for that product, each showing its own unit label and price

#### Scenario: Product with no configured units shows a single entry
- **WHEN** a cashier searches by name and a matched product has no `product_units` records
- **THEN** the results list a single entry for that product, at its base unit, matching current behavior

#### Scenario: Exact barcode match is unaffected
- **WHEN** a cashier's scan exactly matches a product's code
- **THEN** the product is added immediately at its default unit, without showing a per-unit choice, matching current behavior

### Requirement: A product may have more than one simultaneous cart line, one per unit
The POS cart SHALL allow the same product to appear as more than one line at the same time, provided each such line is at a different unit. Adding a product at a unit that already has a line for that product SHALL increment that line's quantity; adding it at a unit with no existing line SHALL create a new line. The system SHALL NOT automatically convert or merge quantities across two different units of the same product on add.

#### Scenario: Adding the same product at a new unit creates a separate line
- **WHEN** a cart already has a line for a product at its base unit ("Chai"), and the cashier adds the same product at a different configured unit ("Viên")
- **THEN** the cart shows two separate lines for that product — one at "Chai", one at "Viên" — rather than one converted/merged line

#### Scenario: Adding the same product at an already-present unit increments that line
- **WHEN** a cart already has a line for a product at unit "Viên", and the cashier adds the same product again at "Viên"
- **THEN** that line's quantity increases by 1, and no new line is created

#### Scenario: Reloading a draft order with multiple lines for one product preserves them
- **WHEN** a saved draft order has two lines for the same product at two different units, and a cashier reopens it in the POS
- **THEN** both lines are restored as separate cart lines, not collapsed into one

### Requirement: Order submission and persistence support multiple lines per product
`OrderController` SHALL accept and persist more than one submitted line for the same product within a single order, each with its own quantity, unit, and price, as separate `order_product` rows — without one line silently overwriting another because they share a product code or product id.

#### Scenario: Two lines for the same product persist as two rows
- **WHEN** an order submission includes two items for the same product code at two different `unit_id`s
- **THEN** the created order has two separate `order_product` rows for that product, each with its own submitted `qty` and `unit_id`, and the order's subtotal reflects both

#### Scenario: Editing an order preserves multiple lines for the same product
- **WHEN** an existing order with two lines for the same product (different units) is resubmitted via `update()`, including via the `create_now_mode` draft-to-done path
- **THEN** both lines are preserved as two separate rows after the update, not collapsed into one

## MODIFIED Requirements

### Requirement: Changing a cart line's unit recalculates its price and subtotal
Selecting a different unit on an existing POS cart line SHALL immediately recompute that line's unit price and subtotal, using the currently-selected customer's type to determine retail vs. wholesale pricing, without requiring the item to be re-added. The line's quantity SHALL NOT be converted or scaled when its unit changes — the quantity number is left exactly as it was; only price, subtotal, and unit label are recomputed at the newly-selected unit. If the target unit already has its own separate cart line for the same product, switching SHALL merge the two lines into one by summing their quantities directly (no conversion needed, since both lines are then in the same unit) into the target line, removing the line being switched from.

#### Scenario: Switching unit recalculates price for a retail customer
- **WHEN** a cashier switches a cart line from the base unit to a configured "Vỉ" conversion unit, with no wholesale customer selected
- **THEN** the line's unit price updates to `sale_price / conversion_qty` for "Vỉ" and its subtotal updates to that price times the line's quantity

#### Scenario: Switching unit recalculates price for a wholesale customer
- **WHEN** a wholesale-type customer is selected on the order and a cashier switches a cart line to a configured conversion unit
- **THEN** the line's unit price updates using that customer's wholesale price divided by the unit's conversion quantity

#### Scenario: Switching a line's unit does not change its quantity number
- **WHEN** a cart line holds quantity 5 (added via repeated scans at the base unit "Hộp"), and the cashier switches its unit to a configured unit "Viên"
- **THEN** the line's quantity stays 5, its unit becomes "Viên", and its price/subtotal recompute using "Viên"'s price — the cashier may then adjust the quantity directly via the existing quantity input if 5 was not the number intended in the new unit

#### Scenario: Switching to a unit with an existing separate line merges them by direct addition
- **WHEN** a cart has a line for a product at "Chai" (quantity 2) and a separate line for the same product at "Viên" (quantity 3), and the cashier switches the "Chai" line's unit to "Viên"
- **THEN** the two lines merge into a single "Viên" line with quantity 5 (2 + 3, summed directly with no conversion), and the "Chai" line no longer exists
