import pandas as pd import random import datetime # # Specify the file path of the XLS document # file_path = 'consumuri.xlsx' # # Read the XLS file # data = pd.read_excel(file_path) # data = data.fillna('') pd.set_option('display.max_rows', None) # Display all rows pd.set_option('display.max_columns', None) # Display all columns pd.set_option('display.width', 1000) # Set the display width for showing more information pd.set_option('display.colheader_justify', 'center') # Center justify column headers pd.set_option('display.precision', 3) # Set precision for decimal values def format_items(dictionary): "pretty string" formatted_string = "Item Details:\n" for key, value in dictionary.items(): formatted_string += f"{key}: {value}\n" return formatted_string def cantitati_piesa(file, denumire_id, cantitate): """ Calculeaza cate piese trebuie sa fie facute de fiecare data cand intlaneste id d epiese ii aduaga cantitatea.. :param file: :type file: :param denumire_id: :type denumire_id: :param cantitate: :type cantitate: :return: :rtype: """ data=pd.read_excel(file) products = {} for index, row in data.iterrows(): denumire = row[denumire_id] if denumire not in ['Consumuri', '']: if denumire not in products: products[denumire] = row[cantitate] else: products[denumire] += row[cantitate] p={"produs":[], "cantitate":[]} for k in products.keys(): p["produs"].append(k) p["cantitate"].append(products[k]) df=pd.DataFrame.from_dict(p) # Generate a random number and get the current date random_number = random.randint(1000, 9999) current_date = datetime.datetime.now().strftime("%Y%m%d") filename = f"{file.name}_cantitate_{current_date}_{random_number}.xlsx" df.to_excel(filename, index=False) # Generate a summary string for display summary_string = "Canitati produse:\n" + "\n".join(f"{prod}: {qty}" for prod, qty in products.items()) # Return the summary string and the path to the Excel file return summary_string, filename return df