How to update 'in_words' value after submit of PO?

Hi guys,
After submit of Purchase Order i am updating the qty through custom button ‘Update Qty’ after updating the qty rate and tax amount updating automatically but total amount ‘in_words’ are not updated. how to update ‘in_words’ automatically?

Regards
Nivedha

Hey @Nivedha, You can python method money_in_words on submit after updating qty.

IN PYTHON FILE

def num_to_word(total_amount, company_currency):
	total_amount_in_words = money_in_words(total_amount, company_currency)
	return total_amount_in_words

IN JS FILE

frappe.ui.form.on('Doctype Name', {
    on_submit: function (frm) {
        frappe.call({
            method: "erpnext.buying.doctype.'Doctype Name.'Doctype Name.num_to_word",
            args: {"total_amount": cur_frm.doc.grand_total, "company_currency": "INR"},
            async: false,
            callback: function (inWords) {
                if (inWords.message != undefined) {
                    cur_frm.set_value("in_words", inWords.message)
                }
            }
        })
    }
})

Hi @ROHAN_JAIN1, thanks for your kind response. I have tried your code and method gets called but it shows NameError: name ‘money_in_words’ is not defined.

Just Import money_in_words

from frappe.utils import money_in_words

Tried @ROHAN_JAIN1 problem is not updating the value in field ‘in_words’ and i am getting the response message in console but that two existing value of ‘in_words’ field not the current one changed total amount value.

Any idea @ROHAN_JAIN1 currently changed qty rate amount is not updated ‘in_words’ field.

Okay try to set qty rate before submit do it one after_save

Hi @ROHAN_JAIN1, i resolved this by doing slight changes from your code

self = frappe.get_doc(‘Purchase Order’,docid)
from frappe.utils import money_in_words
inWords = money_in_words(self.grand_total)

frappe.db.set_value(“Purchase Order”,self.name,“in_words”,inWords)

it is working fine now. sorry for posting the solution late.

Regards,
Nivedha

Would u please let me know where have u put this code? I would be so grateful to u if u describe this in a bit details.

Hi @tusar75, I have done this on validate.