def rubles(self, sum): "Transform sum number in rubles to text" text_rubles = numeral.rubles(int(sum)) copeck = round((sum - int(sum)) * 100) text_copeck = numeral.choose_plural( int(copeck), (u"копейка", u"копейки", u"копеек")) return ("%s %02d %s") % (text_rubles, copeck, text_copeck)
def rubles(amount, zero_for_kopeck=False): """Converts float value to in-words representation (for money)""" try: res = numeral.rubles(amount, zero_for_kopeck) except Exception, err: # because filter must die silently res = default_value % {'error': err, 'value': str(amount)}
def generateNakl(order, order_date, order_price, request, t): template_filename = 'torg12_0.xls' fullname = str('ООО санаторий "Хопровские зори"') vendor = str('КПП 581701001 ') + fullname + str(' Пензенская обл., п.Колышлей, ул.Лесная 1а') if order.patient.address is None: client = order.patient.fio() else: client = order.patient.fio() + ',' + order.patient.address dir = gavnetso.getEmployerByRoleNameAndDate('Директор', order.start_date).__unicode__() gb = gavnetso.getEmployerByRoleNameAndDate('Главный бухгалтер', order.start_date).__unicode__() kassir = gavnetso.getEmployerByRoleNameAndDate('Кассир', order.start_date).__unicode__() rub = numeral.rubles(float(order_price), True) tel = {'PORTRAIT': False, 'NUMPAGES': 1, 'PIZDEZ': fullname, 'NUMBER': order.code, 'FILENAME': 'nakladnaya-' + str(order.code), 'CLIENT': client, 'VENDOR': vendor, 'DIRECTOR': dir, 'GBUH': gb, 'KASSIR': kassir, 'SP': rub, 'DATE': order_date, 'QTYSUM': 1, 'AMOUNTSUM': order_price, 'AMOUNTNDSSUM': order_price, 'ALLAMOUNTSUM': order_price, 'TOVAR': t} return fill_excel_template(template_filename, tel, request)
def rubles(amount, zero_for_kopeck=False): """Converts float value to in-words representation (for money)""" try: ures = numeral.rubles(amount, zero_for_kopeck) res = pseudo_str(ures, encoding, default_value) except Exception, err: # because filter must die silently res = default_value % {"error": err, "value": str(amount)}
def spellTotal(total): template = u"{rubles} {kopnum:02d} {kopstr}" from pytils import numeral n = {} n['rubles'] = numeral.rubles(int(total)).capitalize() n['kopnum'] = int(total * 100) - int(total) * 100 n['kopstr'] = numeral.choose_plural( n['kopnum'], (u"копейка", u"копейки", u"копеек")) return template.format(**n)
def _get_amount_in_words(self, cr, uid, ids, field_name, arg, context=None): res = {} for row in self.browse(cr, uid, ids, context): rubles = numeral.rubles(int(row.amount_total)) copek_num = round(row.amount_total - int(row.amount_total)) copek = numeral.choose_plural(int(copek_num), (u"копейка", u"копейки", u"копеек")) res[row.id] = ("%s %02d %s")%(rubles, copek_num, copek) return res
def spellTotal(total): template = u"{rubles} {kopnum:02d} {kopstr}" from pytils import numeral n = {} n['rubles'] = numeral.rubles(int(total)).capitalize() n['kopnum'] = int(total * 100) - int(total)*100 n['kopstr'] = numeral.choose_plural( n['kopnum'], (u"копейка", u"копейки", u"копеек") ) return template.format(**n)
def get_rubles(self): return rubles(self.pay, True)
def print_(s): # pytils всегда возвращает юникод (строка в Py3.x) # обычно это ОК выводить юникод в терминал # но если это неинтерактивный вывод # (например, использования модуля subprocess) # то для Py2.x нужно использовать перекодировку в utf-8 from pytils.third import six if six.PY3: out = s else: out = s.encode('UTF-8') print(out) # rubles служит для формирования строк с деньгами print_(numeral.rubles(10)) #-> десять рублей # если нужно, то даже 0 копеек можно записать словами print_(numeral.rubles(10, zero_for_kopeck=True)) #-> десять рублей ноль копеек print_(numeral.rubles(2.35)) #-> два рубля тридцать пять копеек # в случае чего, копейки округляются print_(numeral.rubles(3.95754)) #-> три рубля девяносто шесть копеек
#!/usr/bin/env python # -*- coding: utf-8 -*- from pytils import numeral # rubles служит для формирования строк с деньгами :) print numeral.rubles(10) #-> десять рублей # если нужно, то даже 0 копеек можно записать словами print numeral.rubles(10, zero_for_kopeck=True) #-> десять рублей ноль копеек print numeral.rubles(2.35) #-> два рубля тридцать пять копеек # в случае чего, копейки округляются print numeral.rubles(3.95754) #-> три рубля девяносто шесть копеек
def rubles(self, sum): "Transform sum number in rubles to text" text_rubles = numeral.rubles(int(sum)) copeck = round((sum - int(sum))*100) text_copeck = numeral.choose_plural(int(copeck), (u"копейка", u"копейки", u"копеек")) return ("%s %02d %s")%(text_rubles, copeck, text_copeck)
def rubles(self): return rubles(self.in_total)