如何将发票的总价转换为 odoo 11 中的字母?
How can I convert the total price of an invoice to letters in odoo 11?
我创建了一个名为 'custom_report_module' 的模块,我在其中制作个性化发票...发票效果很好,但我想用字母添加总金额..例如..如果购买达到我用字母"are: five hundred thousand guaranies "或"打印的500,000是:五十万"
class account_invoice(models.Model):
_inherit = "account.invoice"
@api.multi
def amount_to_text(self, amount, currency='rupee'):
return amount_to_text(amount, currency)
我的xml
<span t-esc="l.amount_to_text(l.price_unit, l.price_unit)"/>
请看一下这段代码
@api.multi
def amount_to_text(self, amount):
self.ensure_one()
def _num2words(number, lang):
try:
return num2words(number, lang=lang).title()
except NotImplementedError:
return num2words(number, lang='en').title()
if num2words is None:
logging.getLogger(__name__).warning("The library 'num2words' is missing, cannot render textual amounts.")
return ""
formatted = "%.{0}f".format(self.decimal_places) % amount
parts = formatted.partition('.')
integer_value = int(parts[0])
fractional_value = int(parts[2] or 0)
lang_code = self.env.context.get('lang') or self.env.user.lang
lang = self.env['res.lang'].search([('code', '=', lang_code)])
amount_words = tools.ustr('{amt_value} {amt_word}').format(
amt_value=_num2words(integer_value, lang=lang.iso_code),
amt_word=self.currency_unit_label,
)
if not self.is_zero(amount - integer_value):
amount_words += ' ' + _('and') + tools.ustr(' {amt_value} {amt_word}').format(
amt_value=_num2words(fractional_value, lang=lang.iso_code),
amt_word=self.currency_subunit_label,
)
return amount_words
我创建了一个名为 'custom_report_module' 的模块,我在其中制作个性化发票...发票效果很好,但我想用字母添加总金额..例如..如果购买达到我用字母"are: five hundred thousand guaranies "或"打印的500,000是:五十万"
class account_invoice(models.Model):
_inherit = "account.invoice"
@api.multi
def amount_to_text(self, amount, currency='rupee'):
return amount_to_text(amount, currency)
我的xml
<span t-esc="l.amount_to_text(l.price_unit, l.price_unit)"/>
请看一下这段代码
@api.multi
def amount_to_text(self, amount):
self.ensure_one()
def _num2words(number, lang):
try:
return num2words(number, lang=lang).title()
except NotImplementedError:
return num2words(number, lang='en').title()
if num2words is None:
logging.getLogger(__name__).warning("The library 'num2words' is missing, cannot render textual amounts.")
return ""
formatted = "%.{0}f".format(self.decimal_places) % amount
parts = formatted.partition('.')
integer_value = int(parts[0])
fractional_value = int(parts[2] or 0)
lang_code = self.env.context.get('lang') or self.env.user.lang
lang = self.env['res.lang'].search([('code', '=', lang_code)])
amount_words = tools.ustr('{amt_value} {amt_word}').format(
amt_value=_num2words(integer_value, lang=lang.iso_code),
amt_word=self.currency_unit_label,
)
if not self.is_zero(amount - integer_value):
amount_words += ' ' + _('and') + tools.ustr(' {amt_value} {amt_word}').format(
amt_value=_num2words(fractional_value, lang=lang.iso_code),
amt_word=self.currency_subunit_label,
)
return amount_words