Repository navigation
Expand file tree
/
Copy pathtest_multiple.py
More file actions
executable file
·103 lines (78 loc) · 2.62 KB
/
Copy pathtest_multiple.py
File metadata and controls
executable file
·103 lines (78 loc) · 2.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#!/usr/bin/env python3
"""Imprime plusieurs tickets de suite pour tester les doublons."""
from escpos.printer import Usb
from datetime import datetime
import time
VENDOR_ID = 0x04b8 # Epson
PRODUCT_ID = 0x0e28 # TM-T20III
def print_receipt(printer, num):
"""Imprime un ticket de test."""
now = datetime.now()
printer.hw('INIT')
# En-tête
printer.set(align='center')
printer.text(f"=== TICKET TEST #{num} ===\n")
printer.text("Magasin de Test\n")
printer.text("123 Rue Example, 75001 Paris\n")
printer.text("Tel: 01 23 45 67 89\n")
printer.text("TVA: FR12345678901\n")
printer.text("\n")
# Infos
printer.set(align='left')
printer.text(f"Date: {now.strftime('%d/%m/%Y %H:%M:%S')}\n")
printer.text(f"Ticket: TKT-{num:04d}\n")
printer.text("\n")
# Header tableau
printer.set(bold=True)
printer.text("ARTICLE QTE PRIX\n")
printer.set(bold=False)
printer.text("--------------------------------\n")
# Articles
articles = [
("Pomme Bio", 3, "2.50"),
("Pain Complet", 2, "1.80"),
("Fromage Comte", 1, "8.90"),
("Eau 1L", 4, "0.75"),
]
for name, qty, price in articles:
name_padded = name[:20].ljust(20)
line = f"{name_padded} {qty:3d} {price:>6s}\n"
printer.text(line)
printer.text("--------------------------------\n")
# Total
printer.set(align='right', bold=True)
printer.text("TOTAL: 17.45 EUR\n")
printer.set(bold=False)
printer.text("\n")
# Footer
printer.set(align='center')
printer.text("PAIEMENT: Especes\n\n")
printer.text("Merci de votre visite!\n")
printer.text("www.exemple.com\n\n\n")
# Coupe
printer.cut()
print(f" ✓ Ticket #{num} imprimé")
def main():
"""Imprime plusieurs tickets."""
nb_tickets = 5
print(f"Impression de {nb_tickets} tickets de test...")
print("=" * 50)
try:
printer = Usb(VENDOR_ID, PRODUCT_ID)
print("✓ Connecté à l'imprimante\n")
for i in range(1, nb_tickets + 1):
print(f"Impression ticket {i}/{nb_tickets}...")
print_receipt(printer, i)
# Petite pause entre les tickets
if i < nb_tickets:
time.sleep(0.5)
print("\n" + "=" * 50)
print(f"✓ {nb_tickets} tickets imprimés avec succès!")
print("\nVérifiez CHAQUE ticket pour des lignes doublées.")
print("Notez les numéros des tickets qui ont des doublons.")
except Exception as e:
print(f"Erreur: {e}")
return 1
return 0
if __name__ == "__main__":
exit(main())