Every Monday someone at the warehouse copied the week's orders by hand from two Excel files, a CSV and a WhatsApp chat. This script does it in under a second and sets aside whatever a person should look at.
This is what each sales rep sends. Same business, same products, four different ways of writing them down. The files are in Spanish, as the reps wrote them, and product and customer names stay in Spanish throughout because matching them is the job.
This is the actual log the script wrote while processing the files above. Replay it to see the order of the steps.
python consolidar_pedidos.pyAn Excel file with five sheets: the clean orders, what needs review, totals by customer, totals by product and the log. Here are the first rows.
The script doesn't guess. When something doesn't add up, it sets the row aside with the reason and its exact position in the original file.
The sales reps don't have to change how they work. They keep sending their files as usual.
Each rep drops their file in a Google Drive or OneDrive folder synced to the warehouse computer.
Windows Task Scheduler runs the script at 11 p.m. Nobody has to open anything.
First thing, the consolidated file is in the reports folder, ready for invoicing or for feeding the sales dashboard.
# Each rep names the same column differently. This dictionary maps them together. SINONIMOS = { 'fecha': ['fecha', 'fecha pedido', 'fec', 'dia'], 'producto': ['producto', 'referencia', 'descripcion', 'item'], 'cantidad': ['cant', 'cantidad', 'und', 'unidades'], 'precio_unit': ['valor unit', 'precio', 'vr unit'], 'total': ['vr total', 'total', 'valor total'], } # A hand-typed product is accepted only if it is at least 80% similar to the catalog. UMBRAL_PRODUCTO = 80