kelvin
February 6, 2021, 10:02am
#1
I want to have the amount displayed both in words and in number. I have searched but am not getting something which is clear. Help please!
When in doubt, look at the existing code for hints:
doc.outstanding_amount = doc.grand_total
else:
doc.rounded_total = round_based_on_smallest_currency_fraction(doc.grand_total,
doc.currency, doc.precision("rounded_total"))
doc.rounding_adjustment += flt(doc.rounded_total - doc.grand_total,
doc.precision("rounding_adjustment"))
doc.outstanding_amount = doc.rounded_total or doc.grand_total
doc.in_words = money_in_words(doc.grand_total, doc.currency)
doc.base_in_words = money_in_words(doc.base_grand_total, erpnext.get_company_currency(doc.company))
doc.set_payment_schedule()
def make_regional_gl_entries(gl_entries, doc):
country = frappe.get_cached_value('Company', doc.company, 'country')
if country != 'India':
return gl_entries
if doc.reverse_charge == 'Y':
def set_total_in_words(self):
from frappe.utils import money_in_words
if self.meta.get_field("base_in_words"):
base_amount = abs(self.base_grand_total
if self.is_rounded_total_disabled() else self.base_rounded_total)
self.base_in_words = money_in_words(base_amount, self.company_currency)
if self.meta.get_field("in_words"):
amount = abs(self.grand_total if self.is_rounded_total_disabled() else self.rounded_total)
self.in_words = money_in_words(amount, self.currency)
def calculate_commission(self):
if self.meta.get_field("commission_rate"):
self.round_floats_in(self, ["base_net_total", "commission_rate"])
if self.commission_rate > 100.0:
throw(_("Commission rate cannot be greater than 100"))
self.total_commission = flt(self.base_net_total * self.commission_rate / 100.0,
self.precision("total_commission"))
I have tried this code but not getting the amount in word! would you help me to resolve the issue?
Can you share what you tried?
Here’s an example:
In print format, enter the following in HTML:
{{ frappe.utils.money_in_words(doc.grand_total) }}
This will reflect on your print format as follows:
1 Like
I want to do this in custom script or in material_request.py file to show the in word in the form view. I have tried the following in the .py file
def set_total_in_words (self):
from frappe.utils import money_in_words
from erpnext.setup.utils import get_company_currency
if self.company:
company_currency = get_company_currency(self.company)
self.in_word = money_in_words(self.total, company_currency)
here in_word is the field where i want to show the in word of the total field.
For money_in_words both js and php script are required. I have solved my problem. thanks the forum members who tried to give solution! Because from one post from one of the forum members gave me the idea!
1 Like