Started setting up conversion_imports. Not entirely sure how it ultimatly works. Need to grab some real data for a while first
This commit is contained in:
@@ -39,6 +39,7 @@ from .alpinebits_server import (
|
||||
from .auth import generate_unique_id, validate_api_key
|
||||
from .config_loader import load_config
|
||||
from .const import HttpStatusCode
|
||||
from .conversion_service import ConversionService
|
||||
from .customer_service import CustomerService
|
||||
from .db import Base, get_database_url
|
||||
from .db import Customer as DBCustomer
|
||||
@@ -1222,9 +1223,16 @@ async def handle_xml_upload(
|
||||
request: Request,
|
||||
filename: str,
|
||||
credentials_tupel: tuple = Depends(validate_basic_auth),
|
||||
db_session=Depends(get_async_session),
|
||||
):
|
||||
"""Endpoint for receiving XML files for conversion processing via PUT.
|
||||
|
||||
Processes conversion data from hotel PMS:
|
||||
- Parses reservation and daily sales XML data
|
||||
- Matches to existing reservations using truncated tracking IDs (fbclid/gclid)
|
||||
- Links conversions to customers and hashed_customers
|
||||
- Stores daily sales revenue data
|
||||
|
||||
Requires basic authentication and saves XML files to log directory.
|
||||
Supports gzip compression via Content-Encoding header.
|
||||
|
||||
@@ -1294,13 +1302,38 @@ async def handle_xml_upload(
|
||||
filename,
|
||||
)
|
||||
|
||||
# Process the conversion XML and save to database
|
||||
conversion_service = ConversionService(db_session)
|
||||
processing_stats = await conversion_service.process_conversion_xml(xml_content)
|
||||
|
||||
_LOGGER.info(
|
||||
"Conversion processing complete for %s: %s", filename, processing_stats
|
||||
)
|
||||
|
||||
response_headers = {
|
||||
"Content-Type": "application/xml; charset=utf-8",
|
||||
"X-AlpineBits-Server-Accept-Encoding": "gzip",
|
||||
}
|
||||
|
||||
# Return processing stats in response
|
||||
response_content = f"""<?xml version="1.0" encoding="UTF-8"?>
|
||||
<response>
|
||||
<status>success</status>
|
||||
<message>Conversion data processed successfully</message>
|
||||
<stats>
|
||||
<totalReservations>{processing_stats['total_reservations']}</totalReservations>
|
||||
<deletedReservations>{processing_stats['deleted_reservations']}</deletedReservations>
|
||||
<totalDailySales>{processing_stats['total_daily_sales']}</totalDailySales>
|
||||
<matchedToReservation>{processing_stats['matched_to_reservation']}</matchedToReservation>
|
||||
<matchedToCustomer>{processing_stats['matched_to_customer']}</matchedToCustomer>
|
||||
<matchedToHashedCustomer>{processing_stats['matched_to_hashed_customer']}</matchedToHashedCustomer>
|
||||
<unmatched>{processing_stats['unmatched']}</unmatched>
|
||||
<errors>{processing_stats['errors']}</errors>
|
||||
</stats>
|
||||
</response>"""
|
||||
|
||||
return Response(
|
||||
content="Xml received", headers=response_headers, status_code=200
|
||||
content=response_content, headers=response_headers, status_code=200
|
||||
)
|
||||
|
||||
except HTTPException:
|
||||
|
||||
Reference in New Issue
Block a user