Automatic post of generated invoices

Rational

Continuing the discussion from Automatic validation of invoices from subscriptions:
We have many documents that generate invoices (ex: sale, subscription, project etc.). For now they always create draft invoices with the idea that accountant must verify them (if accounts and taxes are correct, the selling price is not too low, etc.).
But when dealing with large number it can take a lot of time for a very small benefit.
Indeed what is interesting for an accountant to check is the new stuffs not the usual or recurring invoices.

Proposal

The idea is to setup a configuration for each document creating invoices to define if it should try to post them or not.
When trying to post an invoice different criteria will be checked and all of them must be true to post the invoice:

  • There are other posted invoice of same type for the party (with possible configured exception for web shop sales). Same type meaning the same schema composed of a JSON like:
    {
      'lines': [{
          'account': `id`,
          'taxes': [`id`],
          }],
      'taxes': [{
         'account': `id`,
         'manual': `boolean`,
         'tax': `id`,
        }],
    }
    
    When it is a web shop sales, the party clause is removed.
    When account_tax_rule_country is activated, from_country and to_country are added.
  • There are posted invoice lines with the same couple (product, account)
  • For customer invoice, the unit price is greater than the cost price of the product

The JSON is stored on the Dict field of the invoice when it is posted.
The search is limited to 1 year in the past by default.

Implementation

I think this should be part of a new module, as not everybody will be interested on having such configuration.

I think that should be configurable on the rule instead of just hard code for sales.
One may just want to post all subscription invoices because all the party fields are checked by custom code on quotation of the subscription.

What does it mean the criteria “is checked”? You say:

What if the invoices are already paid? What if one invoice is cancelled because a refund is created?

It is not clear when the check passes (so the invoice is posted) and when the check fails (the invoice should not be posted).

That will fail for all credit notes generated by sales. I do not think they should be excluded once we validated we have the right invoice information for the party.

Also I think the posting should be done on the queue and probably some delay should be configured.

It can not because it needs to be plugged everywhere an invoice it created.

We have extra_depends for that :wink:

If it is an other module than third party module in which document create invoices will probably not implement it.
But on the other side it adds more options and code to the already bloated account_invoice.

The odds that it is not implemented on the third party module are exactly the same no mather if it’s in a separate module or not.

If the module implementer requires automatic post usage (or event knows about it). Then it will be implemented. Otherwise probably not.