Ajout des fonctions d'impression des factures sur l'imprimante thermique
This commit is contained in:
parent
6b08464bfc
commit
2d4647e9bf
5 changed files with 133 additions and 11 deletions
28
client.py
28
client.py
|
@ -55,6 +55,34 @@ class Ticket(object):
|
||||||
todo['type'] = 'wifi'
|
todo['type'] = 'wifi'
|
||||||
self.add_entry(todo)
|
self.add_entry(todo)
|
||||||
|
|
||||||
|
def add_facture(self, facture):
|
||||||
|
proprietaire = facture.proprio()
|
||||||
|
chambre = None
|
||||||
|
|
||||||
|
#On vérifie que le propriétaire a une chambre sinon on met EXT
|
||||||
|
if 'chbre' in proprietaire.keys():
|
||||||
|
chambre = proprietaire['chbre'][0].value
|
||||||
|
else:
|
||||||
|
chambre = u'EXT'
|
||||||
|
|
||||||
|
deb_adh = crans_utils.datetime_from_generalized_time_format(facture['debutAdhesion'][0].value)
|
||||||
|
fin_adh = crans_utils.datetime_from_generalized_time_format(facture['finAdhesion'][0].value)
|
||||||
|
fin_co = crans_utils.datetime_from_generalized_time_format(facture['finConnexion'][0].value)
|
||||||
|
|
||||||
|
todo = {
|
||||||
|
'fid' : facture['fid'][0].value,
|
||||||
|
'article' : [ art.value for art in facture['article']],
|
||||||
|
'modePaiement' : facture['modePaiement'][0].value,
|
||||||
|
'recuPaiement' : facture['recuPaiement'][0].value,
|
||||||
|
'debutAdhesion' : deb_adh.strftime('%d/%m/%Y'),
|
||||||
|
'finAdhesion' : fin_adh.strftime('%d/%m/%Y'),
|
||||||
|
'finConnexion' : fin_co.strftime('%d/%m/%Y'),
|
||||||
|
'chbre' : chambre,
|
||||||
|
'nom' : proprietaire['nom'][0].value,
|
||||||
|
'prenom' : proprietaire['prenom'][0].value,
|
||||||
|
}
|
||||||
|
self.add_entry(todo)
|
||||||
|
|
||||||
def reset_password(self, adh):
|
def reset_password(self, adh):
|
||||||
login = adh['uid'][0].value
|
login = adh['uid'][0].value
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -5,3 +5,5 @@ CREDS = pika.credentials.PlainCredentials('oie', '*******', True)
|
||||||
|
|
||||||
PARAMS = pika.ConnectionParameters(host='rabbitmq.crans.org',
|
PARAMS = pika.ConnectionParameters(host='rabbitmq.crans.org',
|
||||||
port=5671, credentials=CREDS, ssl=True)
|
port=5671, credentials=CREDS, ssl=True)
|
||||||
|
|
||||||
|
DEVICE = "/dev/ttyAMA0" #Ou USB0 sur oie
|
||||||
|
|
|
@ -12,12 +12,12 @@ import config
|
||||||
def run():
|
def run():
|
||||||
conn = pika.BlockingConnection(config.PARAMS)
|
conn = pika.BlockingConnection(config.PARAMS)
|
||||||
ch = conn.channel()
|
ch = conn.channel()
|
||||||
ch.queue_declare(queue='CransTicket')
|
ch.queue_declare(queue='CransTicketDebug')
|
||||||
def callback(ch, method, properties, body):
|
def callback(ch, method, properties, body):
|
||||||
print (" [x] Received %r" % (body,))
|
print (" [x] Received %r" % (body,))
|
||||||
dump.print_liste(json.loads(body))
|
dump.print_liste(json.loads(body))
|
||||||
|
|
||||||
ch.basic_consume(callback, queue='CransTicket', no_ack=True)
|
ch.basic_consume(callback, queue='CransTicketDebug', no_ack=True)
|
||||||
ch.start_consuming()
|
ch.start_consuming()
|
||||||
conn.close()
|
conn.close()
|
||||||
# fork en arrière plan + pidfile
|
# fork en arrière plan + pidfile
|
||||||
|
|
91
dump.py
91
dump.py
|
@ -8,10 +8,11 @@ from AdafruitThermal import Adafruit_Thermal as AdafruitThermal
|
||||||
import subprocess, time, Image, socket
|
import subprocess, time, Image, socket
|
||||||
import os
|
import os
|
||||||
import json
|
import json
|
||||||
|
from config import DEVICE
|
||||||
|
|
||||||
#
|
#
|
||||||
CODING='cp437'
|
CODING='cp437'
|
||||||
DEVICE="/dev/ttyUSB0"
|
|
||||||
SAMPLE_MACHINE = {
|
SAMPLE_MACHINE = {
|
||||||
'host': 'nouille',
|
'host': 'nouille',
|
||||||
'macAddress': '<automatique>',
|
'macAddress': '<automatique>',
|
||||||
|
@ -60,6 +61,91 @@ def show_entry(entry):
|
||||||
printer.feed(1)
|
printer.feed(1)
|
||||||
|
|
||||||
|
|
||||||
|
def make_fact_elem(element,nb_car,is_last):
|
||||||
|
|
||||||
|
ligne = u''
|
||||||
|
|
||||||
|
u_elem = unicode(element)
|
||||||
|
if len(u_elem) >= nb_car:
|
||||||
|
ligne += u_elem[0:nb_car]
|
||||||
|
else:
|
||||||
|
if is_last:
|
||||||
|
for i in range(nb_car-len(u_elem)):
|
||||||
|
ligne += u' '
|
||||||
|
ligne += u_elem
|
||||||
|
else:
|
||||||
|
ligne += u_elem
|
||||||
|
for i in range(nb_car-len(u_elem)):
|
||||||
|
ligne += u' '
|
||||||
|
|
||||||
|
if is_last:
|
||||||
|
ligne += u''
|
||||||
|
else:
|
||||||
|
ligne += u'|'
|
||||||
|
|
||||||
|
return ligne
|
||||||
|
|
||||||
|
# Fonction spéciale pour l'impression des factures
|
||||||
|
# ! facture est un dictionnaire, pas un objet LDAP !
|
||||||
|
def show_facture(facture):
|
||||||
|
|
||||||
|
#Impression de l'en-tête
|
||||||
|
printer.justify('L')
|
||||||
|
printer.println(facture['recuPaiement'].encode(CODING))
|
||||||
|
printer.justify('C')
|
||||||
|
printer.println(u'--------------------------------'.encode(CODING))
|
||||||
|
printer.boldOn()
|
||||||
|
fid = u'Facture n°'+ facture['fid']
|
||||||
|
printer.println(fid.encode(CODING))
|
||||||
|
printer.boldOff()
|
||||||
|
printer.println(u'--------------------------------'.encode(CODING))
|
||||||
|
|
||||||
|
#Impression de l'en-tête de la facture
|
||||||
|
proprio = facture.proprio()
|
||||||
|
nom_complet = facture['nom'] + u' ' + facture['prenom']
|
||||||
|
printer.justify('R')
|
||||||
|
printer.println((u'Adhérent : ' + nom_complet).encode(CODING))
|
||||||
|
if facture['chbre'] is u'EXT':
|
||||||
|
printer.println(u'Externe'.encode(CODING))
|
||||||
|
else:
|
||||||
|
printer.println((u'Chambre : ' + facture['chbre']).encode(CODING))
|
||||||
|
|
||||||
|
printer.println((u'Début adhésion : ' + facture['debutAdhesion']).encode(CODING))
|
||||||
|
printer.println((u'Fin adhésion : ' + facture['finAdhesion']).encode(CODING))
|
||||||
|
printer.println((u'Fin connexion : ' + facture['finConnexion']).encode(CODING))
|
||||||
|
|
||||||
|
printer.justify('L')
|
||||||
|
printer.println(u'--------------------------------'.encode(CODING))
|
||||||
|
printer.println(u' Code | Désig. |Qté| P.U '.encode(CODING)) #Code(6c. max.),Désignation(11c. max.),Qté(3c. max),PU(8[+1]c.max)
|
||||||
|
printer.println(u'------|-----------|---|---------'.encode(CODING))
|
||||||
|
|
||||||
|
#Impression du corps de la facture + calcul du prix total
|
||||||
|
total = 0.0
|
||||||
|
for art in facture['article']:
|
||||||
|
row = u''
|
||||||
|
row += make_fact_elem(art['code'],6,False)
|
||||||
|
row += make_fact_elem(art['designation'],11,False)
|
||||||
|
row += make_fact_elem(art['nombre'],3,False)
|
||||||
|
row += make_fact_elem(art['pu']+u'e',9,True)
|
||||||
|
total += float(art['pu'])
|
||||||
|
|
||||||
|
printer.println(row.encode(CODING))
|
||||||
|
|
||||||
|
printer.println(u'--------------------------------'.encode(CODING))
|
||||||
|
|
||||||
|
#On affiche le total
|
||||||
|
printer.justify('R')
|
||||||
|
printer.println((u'---------').encode(CODING))
|
||||||
|
printer.println((u'Total à régler '+ '|' + make_fact_elem(total,8,True) + u'e').encode(CODING))
|
||||||
|
printer.println((u'---------').encode(CODING))
|
||||||
|
printer.justify('L')
|
||||||
|
printer.println((u'Payé par ' + facture['modePaiement']).encode(CODING))
|
||||||
|
|
||||||
|
|
||||||
|
#Fin de la facture
|
||||||
|
printer.feed(1)
|
||||||
|
|
||||||
|
|
||||||
# Do print
|
# Do print
|
||||||
def print_liste(liste):
|
def print_liste(liste):
|
||||||
printer.setDefault() # Restore printer to defaults
|
printer.setDefault() # Restore printer to defaults
|
||||||
|
@ -72,6 +158,9 @@ def print_liste(liste):
|
||||||
# print_carac('','')
|
# print_carac('','')
|
||||||
first = False
|
first = False
|
||||||
|
|
||||||
|
if 'fid' in m.keys():
|
||||||
|
show_facture(m) # Si le champ fid est présent, c'est une facture -> on utilise la fonction adaptée
|
||||||
|
else:
|
||||||
show_entry(m)
|
show_entry(m)
|
||||||
|
|
||||||
printer.println(u'Veuillez conserver ces'.encode(CODING))
|
printer.println(u'Veuillez conserver ces'.encode(CODING))
|
||||||
|
|
|
@ -62,7 +62,10 @@ else:
|
||||||
ticket = Ticket()
|
ticket = Ticket()
|
||||||
if 'uid' in item and conf_reset_password:
|
if 'uid' in item and conf_reset_password:
|
||||||
ticket.reset_password(item)
|
ticket.reset_password(item)
|
||||||
if hasattr(item, 'machines'):
|
|
||||||
|
if item.ldap_name is 'facture':
|
||||||
|
ticket.add_facture(item)
|
||||||
|
elif hasattr(item, 'machines'):
|
||||||
for m in item.machines():
|
for m in item.machines():
|
||||||
if not conf_wifi_only or 'machineWifi' in m['objectClass']:
|
if not conf_wifi_only or 'machineWifi' in m['objectClass']:
|
||||||
ticket.add_machine(m)
|
ticket.add_machine(m)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue