Account rule module

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) 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

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).