From b44cb0c222c0a646b26d30ce2c731656a6b079b3 Mon Sep 17 00:00:00 2001 From: AlexSserb Date: Wed, 11 Sep 2024 19:32:03 +0400 Subject: [PATCH] fix: replace locale setting with months constant --- constants.py | 15 +++++++++++++++ services/billing.py | 11 +++++------ 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/constants.py b/constants.py index e2698e1..18c2019 100644 --- a/constants.py +++ b/constants.py @@ -14,3 +14,18 @@ allowed_telegram_ids = [ 502869937, # Sasha 7326211785 ] + +MONTHS = ( + 'января', + 'февраля', + 'марта', + 'апреля', + 'мая', + 'июня', + 'июля', + 'августа', + 'сентября', + 'октября', + 'ноября', + 'декабря' +) diff --git a/services/billing.py b/services/billing.py index cb03a21..075ebf0 100644 --- a/services/billing.py +++ b/services/billing.py @@ -1,6 +1,3 @@ -import datetime -import locale -from ast import Bytes from io import BytesIO from pathlib import Path from typing import List @@ -14,6 +11,7 @@ from starlette import status from weasyprint import HTML import backend.config +from constants import MONTHS from external.billing import BillingClient, CreateBillingRequestValue, CreateBillRequestSchema, CreateBillRequestItems, \ BillStatusUpdateRequest, NotificationChannel, NotifyReceivedBillRequestSchema, DeleteBillRequestSchema from models import DealBillRequest, Deal, DealProduct, DealService as DealServiceModel @@ -21,8 +19,6 @@ from schemas.billing import * from services.base import BaseService from services.deal import DealService -locale.setlocale(locale.LC_TIME, "ru_RU.UTF-8") - env = Environment(loader=FileSystemLoader(Path("templates") / Path("documents"))) @@ -185,12 +181,15 @@ class BillingService(BaseService): deal_price = sum((service.price for service in services)) deal_price_words = get_string_by_number(deal_price)[0:-10] template = env.get_template("bill-of-payment.html") + + now = datetime.datetime.now() + curr_date = f"{now.day} {MONTHS[now.month - 1]} {now.year} г." return template.render({ "services": services, "deal_price": deal_price, "deal_price_words": deal_price_words, "deal": deal, - "curr_date": datetime.datetime.now().strftime("%d %B %Y г.") + "curr_date": curr_date }) async def create_billing_document_pdf(self, deal_id) -> BytesIO: