# Account Determination Rules

Group: Inventory

[Open in the interactive reference](https://docs.api.lensing.ai/lensing/v1/groups/inventoryAccountDeterminationRules)

An account determination rule tells an inventory document's journal entry which general ledger accounts to use.

When an inventory document such as a receipt, shipment, or inventory increase is committed, a journal entry is created for it. Account determination rules decide which general ledger accounts that journal entry uses. Each rule has two parts: the situations it applies to, and the accounts to use in them.

The situations are described by dimensions. A dimension is something a rule can check about the line being recorded: its legal entity, the accounting book the journal entry is for, the item's type and category, the warehouse location, and the transaction type. Every new rule must have a legal entity and an accounting book. If a rule has no value for one of the other dimensions, it applies to every value of that dimension. For example, a rule with no warehouse location applies to every location.

A line that has no value for a dimension matches only rules that leave that dimension empty. For example, a vendor bill line has no location, so only rules with no location apply to it.

Within a legal entity, no two rules (including inactive ones) can have the same combination of transaction type, item type, item category, and location.

Leaving dimensions empty lets you start with general rules and add more specific ones where you need different accounts. When several rules match, the most specific one is used. The dimensions count in this order, from most to least:

1. Item type
2. Item category. A rule for a parent category also matches items in the categories below it, but a rule for the item's own category counts for more.
3. Warehouse location
4. Accounting book
5. Transaction type

When two matching rules are equally specific, the one with the lower priority number wins.

For example, a general rule for 'SHIPMENT' uses cost of goods sold account 5010, and a beverages rule for 'SHIPMENT' and the item category Beverages uses account 5010-BEV. A shipment of a beverage uses the beverages rule, because it is more specific. Every other shipment uses the general rule.

Have a general rule for each combination of legal entity and accounting book: a rule with no item type, item category, or location. Some lines depend on it. For example, a receipt line with no item, such as a service entered only as a description, takes its services-received-not-invoiced account from the general rule. If there is no general rule with that account, the journal entry for the receipt cannot be created.

Some documents can name their own account for part of the journal entry. That account is then used instead of the rule's account:

- An inventory increase or decrease created by manufacturing can have its own offset account, which is used instead of the inventory adjustment gain or loss account.
- A receipt line for a service or expense entered in the application can have its own account, which is used instead of the expense account.
- An inventory revaluation with the `costingValuationType` 'directCostCapitalisation' uses its `capitalisationExpenseAccountId` instead of the revaluation gain or loss account.

Six of the accounts can be replaced by a different account when the document line has a reason code: inventory adjustment gain and loss, sales return, goods returned not credited, and purchase return variance gain and loss. These are the rule's reason-code overrides. For example, stock written off as damaged can go to a separate loss account. Reason codes themselves are created and changed with the inventory/reason-codes endpoints.

## Endpoints

- [List account determination rules](https://docs.api.lensing.ai/reference/lensing/v1/endpoints/accountDeterminationRules.html): `GET /inventory/account-determination-rules`
- [Create an account determination rule](https://docs.api.lensing.ai/reference/lensing/v1/endpoints/createAccountDeterminationRule.html): `POST /inventory/account-determination-rules`
- [Bulk create account determination rules](https://docs.api.lensing.ai/reference/lensing/v1/endpoints/bulkCreateAccountDeterminationRules.html): `POST /inventory/account-determination-rules/bulk`
- [Bulk delete account determination rules](https://docs.api.lensing.ai/reference/lensing/v1/endpoints/bulkDeleteAccountDeterminationRules.html): `POST /inventory/account-determination-rules/bulk-delete`
- [Search account determination rules](https://docs.api.lensing.ai/reference/lensing/v1/endpoints/searchAccountDeterminationRules.html): `POST /inventory/account-determination-rules/search`
- [Retrieve an account determination rule](https://docs.api.lensing.ai/reference/lensing/v1/endpoints/getAccountDeterminationRule.html): `GET /inventory/account-determination-rules/{id}`
- [Update an account determination rule](https://docs.api.lensing.ai/reference/lensing/v1/endpoints/updateAccountDeterminationRule.html): `PATCH /inventory/account-determination-rules/{id}`
- [Delete an account determination rule](https://docs.api.lensing.ai/reference/lensing/v1/endpoints/deleteAccountDeterminationRule.html): `DELETE /inventory/account-determination-rules/{id}`
