Field ratio in payment terms is None


we have migrated successfully our tryton solution to 5.0. Sadly, we did not made it to post automatically the invoices, which are created from a sale. In the past solution, the coding worked correctly.

For the usecase, we override the method create_invoice and wrote:

    invoice = super(Sale, self).create_invoice()
    invoice.reference = self.reference
    invoice.invoice_date = self.sale_date
    Invoice = Pool().get('account.invoice')
    if != 'standard':[invoice])

Within the posting process, we found out, that the payment-term method “get_value” of cannot compute correctly, because the attribute of ratio is None.

File “/opt/projekte/git/tryton2018/EBBTryton2018/trytond/modules/account_invoice/”, line 1367, in post
move = invoice.get_move()
File “/opt/projekte/git/tryton2018/EBBTryton2018/trytond/modules/account_invoice/”, line 948, in get_move
total,, self.invoice_date)
File “/opt/projekte/git/tryton2018/EBBTryton2018/trytond/modules/account_invoice/”, line 70, in compute
value = line.get_value(remainder, amount, currency)
File “/opt/projekte/git/tryton2018/EBBTryton2018/trytond/modules/account_invoice/”, line 223, in get_value
return currency.round(amount * self.ratio)
TypeError: unsupported operand type(s) for *: ‘decimal.Decimal’ and ‘NoneType’

Actual I cannot see, how the payment_term.ratio will be read correctly, or what I am missing.

Thank you and best regards,

I don’t get this. ratio is required on payment term lines when their type is percentage or something like that.
How comes that its value is None? Do you have additional code that change this behaviour?

No, there is no additional code on this. Furthermore, I get the same error, when I try to post the invoices within the accounting module.

But: I found out, that the history-table of the account payment terms has not been updated correctly. The field “ratio” has been left on null and percentages has not been moved correctly. As far as I understand the coding, first the columns of the history will be inspect and than the cache will be updated. (, Line 1288ff ).

My ( not so good ) solution: I deleted all records within the history table and created new history entries for each payment term. This works!

After this, also the creation of invoices out of sale and the automatical post of them works correctly.

Thanks and best regards,

P.S.: The former title “Automatically post invoices when creating from sale” is not so perfect, so I changed it.

When did you activate the account_invoice_history module?

Could you show how was the data?

By the way, I found that line delta was not historized, it may be linked: Missing history on relative delta (#7866) · Issues · Tryton / Tryton · GitLab

This was a long time ago - before 4.0…we made a big step :wink:

Yes, I have saved the data before, I have it within the database and as CSV.