diff --git a/external/billing/schemas.py b/external/billing/schemas.py index cc1df9d..96f8485 100644 --- a/external/billing/schemas.py +++ b/external/billing/schemas.py @@ -87,3 +87,16 @@ class BillStatusUpdateRequest(BaseSchema): listener_transaction_id: int channel: NotificationChannel info: BillPaymentInfo | BillPaymentStatus + + +class ServiceBillingDocumentPdf(BaseSchema): + name: str = "" + price: int + quantity: int + + +class ProductBillingDocumentPdf(BaseSchema): + article: str = "" + size: str = "" + price: int + quantity: int diff --git a/services/billing.py b/services/billing.py index d3e29de..05d2850 100644 --- a/services/billing.py +++ b/services/billing.py @@ -12,7 +12,8 @@ import backend.config import constants from constants import MONTHS, ENV from external.billing import BillingClient, CreateBillingRequestValue, CreateBillRequestSchema, CreateBillRequestItems, \ - BillStatusUpdateRequest, NotificationChannel, NotifyReceivedBillRequestSchema, DeleteBillRequestSchema + BillStatusUpdateRequest, NotificationChannel, NotifyReceivedBillRequestSchema, DeleteBillRequestSchema, \ + ProductBillingDocumentPdf, ServiceBillingDocumentPdf from models import DealBillRequest, Deal, DealProduct, DealService as DealServiceModel from schemas.billing import * from services.base import BaseService @@ -138,28 +139,41 @@ class BillingService(BaseService): except Exception as e: return CancelDealBillResponse(ok=False, message=str(e)) - async def _get_services_for_deal(self, deal: Deal) -> List[CreateBillingRequestValue]: - services: List[CreateBillingRequestValue] = [] + async def _get_products_for_deal(self, deal: Deal) -> tuple[list, list, bool]: + services: list[ServiceBillingDocumentPdf] = [] + products: list[ProductBillingDocumentPdf] = [] + is_size_needed: bool = False for product in deal.products: + product_price = 0 for service in product.services: services.append( - CreateBillingRequestValue( + ServiceBillingDocumentPdf( name=f'[{product.product.name}] - {service.service.name}', price=service.price, - amount=product.quantity + quantity=product.quantity ) ) + product_price += service.price + is_size_needed = is_size_needed | bool(product.product.size) + products.append( + ProductBillingDocumentPdf( + article=product.product.article, + size=product.product.size if product.product.size else "", + price=product_price, + quantity=product.quantity, + ) + ) for service in deal.services: services.append( - CreateBillingRequestValue( + ServiceBillingDocumentPdf( name=f'{service.service.name}', price=service.price, - amount=service.quantity + quantity=service.quantity ) ) - return services + return services, products, is_size_needed async def _create_billing_document_html(self, deal_id: int): deal: Deal | None = await self.session.scalar( @@ -176,9 +190,9 @@ class BillingService(BaseService): if not deal: return "" - services = await self._get_services_for_deal(deal) + (services, products, is_size_needed) = await self._get_products_for_deal(deal) - deal_price = sum((service.price * service.amount for service in services)) + deal_price = sum((service.price * service.quantity for service in services)) deal_price_words = get_string_by_number(deal_price)[0:-10] deal_price = to_locale_number(deal_price) template = ENV.get_template("bill-of-payment.html") @@ -186,7 +200,9 @@ class BillingService(BaseService): now = datetime.datetime.now() curr_date = f"{now.day} {MONTHS[now.month - 1]} {now.year} г." return template.render({ + "products": products, "services": services, + "is_size_needed": is_size_needed, "deal_price": deal_price, "deal_price_words": deal_price_words, "deal": deal, diff --git a/templates/documents/bill-of-payment.html b/templates/documents/bill-of-payment.html index 5c55890..eacc1e0 100644 --- a/templates/documents/bill-of-payment.html +++ b/templates/documents/bill-of-payment.html @@ -39,10 +39,38 @@
+ + + + {% if is_size_needed %} + + {% endif %} + + + + + + + + + {% for product in products %} + + + {% if is_size_needed %} + + {% endif %} + + + + + {% endfor %} + +
АртикулРазмерКол-воЦенаСумма
{{ product.article }}{{ product.size }}{{ '{:,}'.format(product.quantity) }} шт.{{ '{:,}'.format(product.price).replace(',', ' ') }} ₽{{ '{:,}'.format(product.price * product.quantity).replace(',', ' ') }} ₽
+ - + @@ -53,9 +81,9 @@ {% for service in services %} - + - + {% endfor %}
Наименование товара (работы, услуги)КоличествоКол-во Цена Сумма
{{ service.name }}{{ '{:,}'.format(service.amount) }} шт.{{ '{:,}'.format(service.quantity) }} шт. {{ '{:,}'.format(service.price).replace(',', ' ') }} ₽{{ '{:,}'.format(service.price * service.amount).replace(',', ' ') }} ₽{{ '{:,}'.format(service.price * service.quantity).replace(',', ' ') }} ₽