# Account rule module

**URL:** https://discuss.tryton.org/t/account-rule-module/4324
**Category:** Feature
**Tags:** accounting, sales
**Created:** [June 15, 2021, 1:21pm UTC](https://discuss.tryton.org/t/account-rule-module/4324 "2021-06-15T13:21:44Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![ced](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/ced/32/1237_2.png) [@ced](https://discuss.tryton.org/u/ced)
#### Post date: [June 15, 2021, 1:21pm UTC](https://discuss.tryton.org/t/account-rule-module/4324/1 "2021-06-15T13:21:45Z")

</div>

## Rational

Some countries have special rules that requires to book account move lines to a different account than the one defined in Tryton. This can happen for the revenue and expense accounts or the payable and receivable accounts or the stock accounts. Usually the criteria does not depend on the product for revenue/expense nor on the party for payable/receivable but on some properties of the order like the tax applied, the kind of order (e.g. [Different account\_revenue for the same product](https://discuss.tryton.org/t/different-account-revenue-for-the-same-product/1655)) or the warehouse.  
We may also have a case where it is the tax account that changes depending of the type of order.

## Proposal

A new module `account_rule` defines a set of rules for each default account property:

### `account.account.rule`

- `company` required
- `type` `Selection`: payable, receivable, expense, revenue, tax, stock
- `start_date`, `end_date`
- `origin_account`
- `warehouse`
- `tax`
- `account` required

The property `*_used` are extended to find a matching rules for their respective type and using the `account_rule` key from the context (which is a `dict`). The `origin_account` is the value returned by `super()`.  
The models that are calling those properties are extended to fill the context.

On the accounting configuration, a relate button for each type is added to let the user fill rules for the type and the company.

## Implementation

- [Account rule module (#10570) · Issues · Tryton / Tryton · GitLab](https://bugs.tryton.org/issue10570)

---

<div class="post-metadata">

### Author: ![ced](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/ced/32/1237_2.png) [@ced](https://discuss.tryton.org/u/ced)
#### Post date: [July 7, 2021, 10:29am UTC](https://discuss.tryton.org/t/account-rule-module/4324/2 "2021-07-07T10:29:38Z")

</div>

I’m wondering if using only the tax (instead of countries and product category) should not cover most of the cases (with maybe the quantity sign).

---

<div class="post-metadata">

### Author: ![ced](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/ced/32/1237_2.png) [@ced](https://discuss.tryton.org/u/ced)
#### Post date: [April 6, 2022, 8:43am UTC](https://discuss.tryton.org/t/account-rule-module/4324/3 "2022-04-06T08:43:22Z")

</div>


