|
|
@@ -73,11 +73,20 @@ async def create_order(
|
|
|
pass
|
|
|
|
|
|
name_col = f"name_{lang}" if lang in ["en", "ru", "me"] else "name_en"
|
|
|
-
|
|
|
- mat_info = db.execute_query(f"SELECT {name_col}, price_per_cm3, price_per_hour FROM materials WHERE id = %s", (material_id,))
|
|
|
+ # Fetch material info including technology-specific hourly price if available
|
|
|
+ mat_query = """
|
|
|
+ SELECT m.name_en, m.name_ru, m.name_ua, m.name_me, m.price_per_cm3,
|
|
|
+ COALESCE(NULLIF(m.price_per_hour, 0), s.price_per_hour, %s) as price_per_hour,
|
|
|
+ m.speed_coeff
|
|
|
+ FROM materials m
|
|
|
+ LEFT JOIN services s ON m.service_id = s.id
|
|
|
+ WHERE m.id = %s
|
|
|
+ """
|
|
|
+ mat_info = db.execute_query(mat_query, (config.DEFAULT_PRINTER_HOUR_PRICE, material_id))
|
|
|
mat_name = mat_info[0][name_col] if mat_info else "Unknown"
|
|
|
mat_price = mat_info[0]['price_per_cm3'] if mat_info else 0.0
|
|
|
- hour_price = mat_info[0]['price_per_hour'] if mat_info and mat_info[0]['price_per_hour'] is not None else config.DEFAULT_PRINTER_HOUR_PRICE
|
|
|
+ hour_price = mat_info[0]['price_per_hour'] if mat_info else config.DEFAULT_PRINTER_HOUR_PRICE
|
|
|
+ speed_coeff = mat_info[0]['speed_coeff'] if mat_info else 1.0
|
|
|
|
|
|
file_sizes = []
|
|
|
if parsed_ids:
|
|
|
@@ -85,13 +94,15 @@ async def create_order(
|
|
|
file_rows = db.execute_query(f"SELECT file_size FROM order_files WHERE id IN ({format_strings})", tuple(parsed_ids))
|
|
|
file_sizes = [r['file_size'] for r in file_rows]
|
|
|
|
|
|
- estimated_price, item_prices = pricing.calculate_estimated_price(material_id, file_sizes, parsed_quantities if parsed_quantities else None, return_details=True)
|
|
|
+ estimated_price, item_prices, pricing_metadata = pricing.calculate_estimated_price(material_id, file_sizes, parsed_quantities if parsed_quantities else None, return_details=True)
|
|
|
|
|
|
# Snapshoting initial parameters
|
|
|
original_params = json.dumps({
|
|
|
"material_name": mat_name,
|
|
|
"material_price": float(mat_price) if mat_price is not None else 0.0,
|
|
|
- "printer_hour_price": float(hour_price),
|
|
|
+ "printer_hour_price": float(pricing_metadata['price_per_hour']),
|
|
|
+ "speed_coeff": float(pricing_metadata['speed_coeff']),
|
|
|
+ "base_fee": float(pricing_metadata['base_fee']),
|
|
|
"estimated_price": float(estimated_price) if estimated_price is not None else 0.0,
|
|
|
"quantity": quantity,
|
|
|
"color_name": color_name,
|
|
|
@@ -228,7 +239,7 @@ async def get_public_reviews():
|
|
|
|
|
|
@router.post("/estimate")
|
|
|
async def get_price_estimate(data: schemas.EstimateRequest):
|
|
|
- estimated_total, file_prices = pricing.calculate_estimated_price(
|
|
|
+ estimated_total, file_prices, metadata = pricing.calculate_estimated_price(
|
|
|
data.material_id,
|
|
|
data.file_sizes,
|
|
|
data.file_quantities,
|