feat: new stuff

This commit is contained in:
2024-11-12 11:49:44 +03:00
parent b98e98cabd
commit 1e260f2e42

View File

@@ -77,51 +77,34 @@ class BillingService(BaseService):
billing_client = BillingClient(backend.config.BILLING_API_KEY)
basic_deal: Deal = await deal_service.get_by_id(user, request.deal_id, return_raw=True)
deals = await deal_service.get_deals_grouped(basic_deal)
if basic_deal.group:
deals = await self._get_deals_by_group_id(basic_deal.group.id)
else:
deals = [basic_deal]
(services, products, is_size_needed) = await self._get_products_for_deal(deals)
services: dict[str, ServiceBillingDocumentPdf]
products: dict[str, ProductBillingDocumentPdf]
is_size_needed: bool
billing_request_values: List[CreateBillingRequestValue] = []
psq = defaultdict(lambda: defaultdict(lambda: 0))
sq = defaultdict(lambda: 0)
services_dict = {}
products_dict = {}
for deal in deals:
for product in deal.products:
product: DealProduct
for service in product.services:
service: DealProductService
psq[product.product_id][service.service_id] += product.quantity
products_dict[product.product_id] = product.product
services_dict[service.service_id] = service
for deal in deals:
for service in deal.services:
service: models.DealService
services_dict[service.service_id] = service
sq[service.service_id] += service.quantity
for product_id, services_ids in psq.items():
product: models.Product = products_dict[product_id]
for service_id in services_ids:
service = services_dict[service_id]
quantity = psq[product_id][service_id]
billing_request_values.append(
CreateBillingRequestValue(
name=f'[{product.name}] - {service.service.name}',
price=service.price,
amount=quantity
)
)
for service_id, quantity in sq.items():
service = services_dict[service_id]
for product in products.values():
billing_request_values.append(
CreateBillingRequestValue(
name=f'{service.service.name}',
price=service.price,
amount=quantity
name=f'{product.article} {product.size}',
price=product.price,
quantity=product.quantity
)
)
for service in services.values():
billing_request_values.append(
CreateBillingRequestValue(
name=service.name,
price=service.price,
quantity=service.quantity
)
)
deal = basic_deal
create_bill_request = CreateBillRequestSchema(
listener_transaction_id=deal.id,