Explorar o código

fix: include discount_percent in order metadata snapshot and dedicated column

unknown hai 2 meses
pai
achega
4ef671b2a2

+ 1 - 0
backend/migrations/006_order_pricing_snapshot.sql

@@ -3,3 +3,4 @@
 
 ALTER TABLE `orders` ADD COLUMN `printer_hour_price` decimal(10,2) DEFAULT NULL;
 ALTER TABLE `orders` ADD COLUMN `speed_coeff` decimal(10,2) DEFAULT NULL;
+ALTER TABLE `orders` ADD COLUMN `discount_percent` decimal(5,2) DEFAULT 0.00;

+ 4 - 3
backend/routers/orders.py

@@ -103,6 +103,7 @@ async def create_order(
         "printer_hour_price": float(pricing_metadata['price_per_hour']),
         "speed_coeff": float(pricing_metadata['speed_coeff']),
         "base_fee": float(pricing_metadata['base_fee']),
+        "discount_percent": float(pricing_metadata['discount_percent']),
         "estimated_price": float(estimated_price) if estimated_price is not None else 0.0,
         "quantity": quantity,
         "color_name": color_name,
@@ -120,10 +121,10 @@ async def create_order(
     })
 
     order_query = """
-    INSERT INTO orders (user_id, material_id, first_name, last_name, phone, email, shipping_address, model_link, status, is_company, company_name, company_pib, company_address, allow_portfolio, estimated_price, material_name, material_price, printer_hour_price, speed_coeff, color_name, quantity, notes, original_params)
-    VALUES (%s, %s, %s, %s, %s, %s, %s, %s, 'pending', %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)
+    INSERT INTO orders (user_id, material_id, first_name, last_name, phone, email, shipping_address, model_link, status, is_company, company_name, company_pib, company_address, allow_portfolio, estimated_price, material_name, material_price, printer_hour_price, speed_coeff, discount_percent, color_name, quantity, notes, original_params)
+    VALUES (%s, %s, %s, %s, %s, %s, %s, %s, 'pending', %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)
     """
-    order_params = (user_id, material_id, first_name, last_name, phone, email, shipping_address, model_link, is_company, company_name, company_pib, company_address, allow_portfolio, estimated_price, mat_name, mat_price, hour_price, speed_coeff, color_name, quantity, notes, original_params)
+    order_params = (user_id, material_id, first_name, last_name, phone, email, shipping_address, model_link, is_company, company_name, company_pib, company_address, allow_portfolio, estimated_price, mat_name, mat_price, hour_price, speed_coeff, pricing_metadata['discount_percent'], color_name, quantity, notes, original_params)
     
     try:
         order_insert_id = db.execute_commit(order_query, order_params)