diff --git a/py_app/app/__pycache__/order_labels.cpython-312.pyc b/py_app/app/__pycache__/order_labels.cpython-312.pyc index 07c1241..e547fba 100644 Binary files a/py_app/app/__pycache__/order_labels.cpython-312.pyc and b/py_app/app/__pycache__/order_labels.cpython-312.pyc differ diff --git a/py_app/app/order_labels.py b/py_app/app/order_labels.py index 9ff0bf0..3dc557c 100644 --- a/py_app/app/order_labels.py +++ b/py_app/app/order_labels.py @@ -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() diff --git a/py_app/app/print_module.py b/py_app/app/print_module.py index 62f35e5..0052b3d 100644 --- a/py_app/app/print_module.py +++ b/py_app/app/print_module.py @@ -34,7 +34,7 @@ def get_unprinted_orders_data(limit=100): # Use printed_labels column 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 @@ -46,7 +46,7 @@ def get_unprinted_orders_data(limit=100): # Fallback: get all orders if no printed_labels column 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, created_at, updated_at FROM order_for_labels @@ -63,15 +63,17 @@ def get_unprinted_orders_data(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] }) else: orders.append({ @@ -80,15 +82,17 @@ def get_unprinted_orders_data(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], + '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': 0, # Default to not printed - 'created_at': row[11], - 'updated_at': row[12] + 'created_at': row[13], + 'updated_at': row[14] }) conn.close() diff --git a/py_app/app/templates/main_page_etichete.html b/py_app/app/templates/main_page_etichete.html index cdfd254..dc2ddb2 100644 --- a/py_app/app/templates/main_page_etichete.html +++ b/py_app/app/templates/main_page_etichete.html @@ -12,8 +12,11 @@
View uploaded orders and manage label data for printing.
- View Orders +Upload new orders or view existing orders and manage label data for printing.
+| Comanda Productie | -Cod Articol | -Descr. Com. Prod | +Comanda Productie |
+ Cod Articol |
+ Descr. Com. Prod |
Cantitate | -Com.Achiz.Client | -Nr. Linie com. Client | -Customer Name | -Customer Article Number | -Open for order | +Data Livrare |
+ Dimensiune | +Com.Achiz. Client |
+ Nr. Linie com. Client |
+ Customer Name |
+ Customer Article Number |
+ Open for order |
Line |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| {{ order.get('comanda_productie', '') }} | {{ order.get('cod_articol', '') }} | {{ order.get('descr_com_prod', '') }} | {{ order.get('cantitate', '') }} | +{{ order.get('data_livrare', '') }} | +{{ order.get('dimensiune', '') }} | {{ order.get('com_achiz_client', '') }} | {{ order.get('nr_linie_com_client', '') }} | {{ order.get('customer_name', '') }} | @@ -78,9 +214,10 @@{{ order.get('open_for_order', '') }} | {{ order.get('line_number', '') }} | |||||||||
| No CSV file uploaded yet. | |||||||||||||||||||
| No CSV file uploaded yet. | |||||||||||||||||||
| ID | -Comanda Productie | -Cod Articol | -Descr. Com. Prod | +Comanda Productie |
+ Cod Articol |
+ Descr. Com. Prod |
Cantitate | -Com.Achiz.Client | -Nr. Linie | -Customer Name | -Customer Art. Nr. | -Open Order | +Data Livrare |
+ Dimensiune | +Com.Achiz. Client |
+ Nr. Linie |
+ Customer Name |
+ Customer Art. Nr. |
+ Open Order |
Line | Printed | Created | @@ -72,6 +164,14 @@{{ order.cod_articol or '-' }} | {{ order.descr_com_prod }} | {{ order.cantitate }} | ++ {% if order.data_livrare %} + {{ order.data_livrare.strftime('%Y-%m-%d') if order.data_livrare is not string else order.data_livrare }} + {% else %} + - + {% endif %} + | +{{ order.dimensiune or '-' }} | {{ order.com_achiz_client or '-' }} | {{ order.nr_linie_com_client or '-' }} | {{ order.customer_name or '-' }} |
|---|