Credit limit amount calculation

We find the following behavior in sale_credit_limit module that we believe should be modified:

  • When a sale is set to 100 units and finally 110 units are invoiced, the credit limit amount is set to the amount of the sale (100), not the amount actually invoiced.


  • Sale line: 100 u. at 0,40€/u. → 40€
  • Invoice line: 110 u. at 0,40€/u. → 44€

The credit limit amount is set as 40€ instead of 44€.

The same behavior happens when fewer units are invoiced than those initially defined in the sale.

We think that the amount is has to be set in the field “Credit limit amount” should always be the invoiced amount, also taking into account the sale lines that are still pending to invoice.

The invoiced quantity is removed from the pending sale lines once the invoice is posted.
So for me the current behavior is correct.

If you post the amount of 110 units, this will be included on the credit limit, so the credit limit amount will be 110. Did you post the invoice?

In such case, the credit limit will include: The amount of the posted invoice plus the quantity not invoiced in the price defined on the sale.

I agree that the current behaviour is correct.

Indeed I think there can be some room for improvement:

  • the computed quantity should not be used if it is negative (invoice more than sale line quantity)
  • the quantity should be deduced for ignored stock moves or invoice lines (depending on the invoice method)

I did post the invoice and with the case I exposed the credit limit amount is not the amount invoiced, maybe because the computed quantity is used when is negative, as Cédric has said.

Filled Improve credit limit computation for processing sales (#12226) · Issues · Tryton / Tryton · GitLab