# SalesPriceRule

## Description

SalesPriceRule is the actual commercial pricing condition resolved during sales-order entry. It captures the item scope, optional customer or channel scope, minimum quantity, effective dates, unit of measure, currency, explicit priority, and selling price that determine whether the rule is applicable to a draft order line.

## Domain Model Definitions

### Model type

Stateful

#### State Transitions

```mermaid
stateDiagram-v2
    [*] --> Draft: createSalesPriceRule
    Draft --> Active: activateSalesPriceRule
    Active --> Inactive: deactivateSalesPriceRule
```

| Operation | From | To | Command |
|-----------|------|----|---------|
| activate | DRAFT | ACTIVE | [activateSalesPriceRule](../command/ActivateSalesPriceRule.md) |
| deactivate | ACTIVE | INACTIVE | [deactivateSalesPriceRule](../command/DeactivateSalesPriceRule.md) |

### Command Definitions

- [createSalesPriceRule](../command/CreateSalesPriceRule.md) - Create a draft pricing rule inside a company-scoped price list.
- [updateSalesPriceRule](../command/UpdateSalesPriceRule.md) - Adjust scope, price, dates, or quantity break before or after activation under controlled rules.
- [activateSalesPriceRule](../command/ActivateSalesPriceRule.md) - Make the rule eligible for deterministic price selection.
- [deactivateSalesPriceRule](../command/DeactivateSalesPriceRule.md) - Remove the rule from future matching without rewriting history.

### Query Definitions

- [getApplicableSalesPrice](../query/GetApplicableSalesPrice.md) - Resolve the best matching rule and effective unit price for a draft sales-order context.
- [listSalesPriceRulesByPriceList](../query/ListSalesPriceRulesByPriceList.md) - List rules maintained under a selected price list.

### Models

- SalesPriceRule

### Invariants

- Every rule belongs to exactly one sales price list and one company context.
- A rule must specify a non-negative minimum quantity, a positive unit price, a valid currency, and a valid sellable item scope.
- If both effective start and end dates are present, the end date cannot precede the start date.
- Two ACTIVE rules with indistinguishable precedence for the same commercial context are not allowed without an explicit tie-breaker priority.

### Relationships

- **Belongs To SalesPriceList**: `salesPriceListId` assigns the rule to a reusable pricing set.
- **References Item (cross-module)**: `itemId` points to the sellable item being priced.
- **References BusinessPartner (cross-module)**: `customerId` is optional for customer-specific commercial agreements.
- **References Channel**: `channelId` is optional for marketplace or storefront-specific pricing.
- **References primitives**: `currencyId` and `uomId` must align with primitives conversion support.
