Files
gzth/docx_report_custom/rus_docs/report_helper.py
T
2025-04-14 09:28:56 +08:00

53 lines
1.4 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import re
from datetime import datetime
from pytils import dt, numeral
class Helper:
def numer(self, name):
if name:
numeration = re.findall(r"\d+$", name)
if numeration:
return numeration[0]
return ""
def ru_date(self, date):
if date and date != "False":
return dt.ru_strftime(
'"%d" %B %Y года',
date=datetime.strptime(str(date), "%Y-%m-%d"),
inflected=True,
)
return ""
def ru_date2(self, date):
if date and date != "False":
return dt.ru_strftime(
"%d %B %Y г.",
date=datetime.strptime(str(date), "%Y-%m-%d %H:%M:%S"),
inflected=True,
)
return ""
def in_words(self, number):
return numeral.in_words(number)
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), ("копейка", "копейки", "копеек")
)
return ("%s %02d %s") % (text_rubles, copeck, text_copeck)
def initials(self, fio):
if fio:
return (
fio.split()[0]
+ " "
+ "".join([fio[0:1] + "." for fio in fio.split()[1:]])
).strip()
return ""