On the invoice I need the total amount in words (i.e. 10 EURO and 50 Cents).
Currently I use the onchange method on the amount_total field. This does converts it into words but is only called once because amount_total is a so-called functional field. This always results in Zero EURO and Zero Cents.
def onchange_amount(self, cr, uid, ids, amount):
x_text_amount = amount_to_text_en.amount_to_text(amount, 'en', 'EURO')
return {'value': {'x_text_amount': x_text_amount}}
In account_invoice.py I need to change an existing function to update my new field amount_in_words. I thought I could update this field when the user validates an invoice. However I did not get this working.
I created the following to function already.
def _compute_amount_letter(self):
self.x_amount_letter=self._get_amount_letter(self.amount_total)
def _get_amount_letter(self,amount):
return amount_to_text_en(amount)
Could you please help me how to change/update account_invoice.py - so that my field amount_in_words will be updated when the user validates the invoice / the total amount changes.
Many thanks!
Did you try by @api.onchange?
Yes. I tried this: @api.depends('amount_total') def test(self): self.x_amount_letter = amount_to_text_en.amount_to_text(self.amount_total, 'en', 'EURO') But it is not triggered yet. Does not update the x_amount_total field. @Bole Yeah I only need it in the printed report.
I used @api.onchange. In the comment above I copied the wrong code.
Well if you only need that text in printed report, then you have no need for such field in database... simply call _compute_ammount_letter from report parser...