updated correct label and collumns in te database for label

This commit is contained in:
2025-09-18 21:56:31 +03:00
parent dfc60a9725
commit 282d311e6a
7 changed files with 437 additions and 138 deletions

View File

@@ -68,6 +68,22 @@ def validate_order_row(row_data):
except ValueError:
errors.append(f"{field} must be a valid number")
# Validate data_livrare (optional date field)
data_livrare = row_data.get('data_livrare', '').strip()
if data_livrare:
try:
# Try to parse common date formats
for date_format in ['%Y-%m-%d', '%d/%m/%Y', '%m/%d/%Y', '%d.%m.%Y']:
try:
datetime.strptime(data_livrare, date_format)
break
except ValueError:
continue
else:
errors.append("data_livrare must be a valid date (YYYY-MM-DD, DD/MM/YYYY, MM/DD/YYYY, or DD.MM.YYYY)")
except Exception:
errors.append("data_livrare date format error")
# Validate string length limits
field_limits = {
'comanda_productie': 15,
@@ -96,11 +112,29 @@ def add_order_to_database(order_data):
cursor = conn.cursor()
# Prepare data with proper types and limits
# Handle date conversion for data_livrare
data_livrare_value = None
data_livrare_str = order_data.get('data_livrare', '').strip()
if data_livrare_str:
try:
# Try to parse common date formats and convert to YYYY-MM-DD
for date_format in ['%Y-%m-%d', '%d/%m/%Y', '%m/%d/%Y', '%d.%m.%Y']:
try:
parsed_date = datetime.strptime(data_livrare_str, date_format)
data_livrare_value = parsed_date.strftime('%Y-%m-%d')
break
except ValueError:
continue
except Exception:
pass # Leave as None if parsing fails
insert_data = {
'comanda_productie': order_data.get('comanda_productie', '').strip()[:15],
'cod_articol': order_data.get('cod_articol', '').strip()[:15] or None,
'descr_com_prod': order_data.get('descr_com_prod', '').strip()[:50],
'cantitate': int(order_data.get('cantitate', 0)),
'data_livrare': data_livrare_value,
'dimensiune': order_data.get('dimensiune', '').strip()[:10] or None,
'com_achiz_client': order_data.get('com_achiz_client', '').strip()[:25] or None,
'nr_linie_com_client': int(order_data.get('nr_linie_com_client', 0)) if order_data.get('nr_linie_com_client', '').strip() else None,
'customer_name': order_data.get('customer_name', '').strip()[:50] or None,
@@ -111,10 +145,10 @@ def add_order_to_database(order_data):
sql = """
INSERT INTO order_for_labels
(comanda_productie, cod_articol, descr_com_prod, cantitate,
(comanda_productie, cod_articol, descr_com_prod, cantitate, data_livrare, dimensiune,
com_achiz_client, nr_linie_com_client, customer_name,
customer_article_number, open_for_order, line_number, printed_labels)
VALUES (%(comanda_productie)s, %(cod_articol)s, %(descr_com_prod)s, %(cantitate)s,
VALUES (%(comanda_productie)s, %(cod_articol)s, %(descr_com_prod)s, %(cantitate)s, %(data_livrare)s, %(dimensiune)s,
%(com_achiz_client)s, %(nr_linie_com_client)s, %(customer_name)s,
%(customer_article_number)s, %(open_for_order)s, %(line_number)s, 0)
"""
@@ -156,6 +190,9 @@ def process_csv_file(file_path):
'cod articol': 'cod_articol',
'descr. com. prod': 'descr_com_prod',
'cantitate': 'cantitate',
'datalivrare': 'data_livrare',
'data livrare': 'data_livrare',
'dimensiune': 'dimensiune',
'com.achiz.client': 'com_achiz_client',
'nr. linie com. client': 'nr_linie_com_client',
'customer name': 'customer_name',
@@ -279,7 +316,7 @@ def upload_orders_handler():
flash(report, "success" if failed_count == 0 else "warning")
return redirect(url_for('main.upload_orders') + '#imported')
return redirect(url_for('main.view_orders'))
# Load data from session if available
elif 'orders_csv_data' in session:
@@ -304,7 +341,7 @@ def get_orders_from_database(limit=100):
cursor.execute("""
SELECT id, comanda_productie, cod_articol, descr_com_prod, cantitate,
com_achiz_client, nr_linie_com_client, customer_name,
data_livrare, dimensiune, com_achiz_client, nr_linie_com_client, customer_name,
customer_article_number, open_for_order, line_number,
printed_labels, created_at, updated_at
FROM order_for_labels
@@ -320,15 +357,17 @@ def get_orders_from_database(limit=100):
'cod_articol': row[2],
'descr_com_prod': row[3],
'cantitate': row[4],
'com_achiz_client': row[5],
'nr_linie_com_client': row[6],
'customer_name': row[7],
'customer_article_number': row[8],
'open_for_order': row[9],
'line_number': row[10],
'printed_labels': row[11],
'created_at': row[12],
'updated_at': row[13]
'data_livrare': row[5],
'dimensiune': row[6],
'com_achiz_client': row[7],
'nr_linie_com_client': row[8],
'customer_name': row[9],
'customer_article_number': row[10],
'open_for_order': row[11],
'line_number': row[12],
'printed_labels': row[13],
'created_at': row[14],
'updated_at': row[15]
})
conn.close()