From e6cb771db0d12edc876a8c9e6c291648ad10ede5 Mon Sep 17 00:00:00 2001 From: AlexSserb Date: Fri, 20 Sep 2024 20:14:02 +0400 Subject: [PATCH] fix: bill of payment generation refactoring --- services/billing.py | 7 +- static/css/bill-of-payment.css | 122 ++++++++++++++++++++ templates/documents/bill-of-payment.html | 137 +---------------------- 3 files changed, 131 insertions(+), 135 deletions(-) create mode 100644 static/css/bill-of-payment.css diff --git a/services/billing.py b/services/billing.py index 0e442ef..4b87c2d 100644 --- a/services/billing.py +++ b/services/billing.py @@ -1,16 +1,15 @@ from io import BytesIO -from pathlib import Path from typing import List from fastapi import HTTPException -from jinja2 import Environment, FileSystemLoader from number_to_string import get_string_by_number from sqlalchemy import select from sqlalchemy.orm import selectinload from starlette import status -from weasyprint import HTML +from weasyprint import HTML, CSS import backend.config +import constants from constants import MONTHS, ENV from external.billing import BillingClient, CreateBillingRequestValue, CreateBillRequestSchema, CreateBillRequestItems, \ BillStatusUpdateRequest, NotificationChannel, NotifyReceivedBillRequestSchema, DeleteBillRequestSchema @@ -195,6 +194,6 @@ class BillingService(BaseService): async def create_billing_document_pdf(self, deal_id) -> BytesIO: doc = await self._create_billing_document_html(deal_id) pdf_file = BytesIO() - HTML(string=doc).write_pdf(pdf_file) + HTML(string=doc).write_pdf(pdf_file, stylesheets=[CSS(constants.APP_PATH + '/static/css/bill-of-payment.css')]) return pdf_file diff --git a/static/css/bill-of-payment.css b/static/css/bill-of-payment.css new file mode 100644 index 0000000..5ae898e --- /dev/null +++ b/static/css/bill-of-payment.css @@ -0,0 +1,122 @@ +@media print { + #header, + #footer, + #nav { + display: none !important; + } +} + +.doc-container { + padding: 10px 15px; + font-size: 13px; + font-family: sans-serif; +} + +.info-line { + padding-bottom: 6px; +} + +.title { + font-size: 16px; + margin-top: 20px; + margin-bottom: 2px; +} + +.footer { + margin-top: 8px; + display: flex; + justify-content: space-between; +} + +.footer-block { + justify-content: space-between; + +} + +.footer-line { + font-size: medium; + font-weight: bolder; + margin: 2px 0; +} + +table { + width: 100%; + border-collapse: separate; + border-spacing: 0; + border: solid black 2px; + border-radius: 15px; +} + +thead { + display: table-header-group; +} + +tfoot { + display: table-footer-group; +} + +td:nth-child(5) { + border-right: 1px solid white; +} + +table tbody tr:nth-child(odd) { + background-color: #dbdbdb; +} + +tr { + page-break-inside: avoid; +} + +td, th { + padding: 16px 13px; +} + +td:first-child, th:first-child { + padding-left: 50px; +} + +td:last-child, th:last-child { + padding-right: 50px; +} + +td:first-child, th:first-child { + text-align: left; +} + +td:first-child { + white-space: normal; + word-wrap: break-word; +} + +td:not(:first-child), th:not(:first-child) { + text-align: right; +} + +td:not(:first-child) { + white-space: nowrap; + overflow: hidden; + text-overflow: ellipsis; +} + +img { + width: 170px; + margin-bottom: 15px; +} + +table tfoot { + border-top: 2px solid black; +} + +.footer-line-right { + font-size: medium; + font-weight: bolder; + margin: 2px 0; + width: 100%; + text-align: right; +} + +.footer-words { + width: 100%; + flex-direction: column-reverse; + justify-content: flex-end; +} \ No newline at end of file diff --git a/templates/documents/bill-of-payment.html b/templates/documents/bill-of-payment.html index 6c85e5d..9fd999d 100644 --- a/templates/documents/bill-of-payment.html +++ b/templates/documents/bill-of-payment.html @@ -6,130 +6,6 @@ content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"> Расчет стоимости услуг -
@@ -137,7 +13,6 @@
Логотип DENCO -
Юридический адрес: 156619, Россия, Москва, ул. Промышленная 11. стр. 3, пом. 542
@@ -168,12 +43,12 @@ {% for service in services %} - - {{ service.name }} - {{ '{:,}'.format(service.amount) }} шт. - {{ '{:,}'.format(service.price).replace(',', ' ') }} ₽ - {{ '{:,}'.format(service.price * service.amount).replace(',', ' ') }} ₽ - + + {{ service.name }} + {{ '{:,}'.format(service.amount) }} шт. + {{ '{:,}'.format(service.price).replace(',', ' ') }} ₽ + {{ '{:,}'.format(service.price * service.amount).replace(',', ' ') }} ₽ + {% endfor %}