6
from tempfile import NamedTemporaryFile
7
from pprint import pprint as pp
10
class GrainLabeler(object):
11
def __init__(self,orderNumber,itemNumber, crushed='', control_no = '', position = ''):
14
if crushed[:4] == 's:13':
15
if crushed[21:23] == 'Yes':
16
self.crushed = 'Crushed'
18
self.crushed = 'Unmilled'
20
self.ornum = orderNumber
21
self.itmnum = itemNumber
22
self.control_no = control_no
23
self.position = position
25
makehtml = self.getData()
26
with NamedTemporaryFile(delete=False, mode='r+w', suffix='.html') as myFile:
27
myFile.write(makehtml)
29
with NamedTemporaryFile(mode='r+w', suffix='.pdf') as myPdf:
31
COM = 'cp %s /tmp/wamp.html' % foo
34
command = 'xvfb-run -a -s "-screen 0 640x480x16" \
35
wkhtmltopdf -B 1mm -L 1mm -T 3mm -R 1mm --page-height 2in --page-width 3in %s %s\
36
&& lpr -o media=Custom.3x2in -P mwgrainlabeler %s' % (myFile.name, myPdf.name, myPdf.name)
37
#&& lpr -o media=Custom.3x2in -P PDF %s' % (myFile.name, myPdf.name, myPdf.name)
43
def createHtml(self,**args):
44
htmlFile = open('/usr/local/openerp/community/stock_print_grouped_picking/report/header.html', 'rb')
45
self.head = htmlFile.read()
47
htmlFile = open('/usr/local/openerp/community/stock_print_grouped_picking/report/footer.html', 'rb')
48
self.footer = htmlFile.read()
50
fulfillmentNumber = self.ornum
54
foo = open('/usr/local/openerp/community/stock_print_grouped_picking/report/memberdb.json', 'rb')
55
bar = json.loads(foo.read())
58
if len(labeltitle) >= 0:
60
if len(labeltitle) < 1 and str(x['mwsku']).upper() == self.itmnum:
61
labeltitle = x['mwname']
62
#pp('SKU: ' + x['mwsku'])
65
htmllist += '<h1>' + labeltitle + '</h1>'
67
#htmllist += '<p>' + self.ornum + ' : ' + self.control_no + ' : ' + self.position + '</p>'
68
htmllist += '<p>' + self.crushed + '</p>'
71
if str(x['mwsku']).upper() == self.itmnum:
72
#pp(str(x['memberquantity']) + ' ' + x['membermwsku'] + ' ' + x['membermwname'].encode('utf-8').strip())
73
pp(str(x['memberquantity']) + ' ' + x['membermwsku'] + ' ' + unicodedata.normalize('NFKD', x['membermwname']).encode('ascii', 'ignore'))
74
#htmllist += '<li>' + str(x['memberquantity']) + ' ' + str(x['membermwsku']) + ' ' + x['membermwname'].encode('utf-8').strip() + '</li>'
75
name = unicodedata.normalize('NFKD', x['membermwname']).encode('ascii', 'ignore')
76
htmllist += '<li>' + str(x['memberquantity']) + ' ' + str(x['membermwsku']) + ' ' + name + '</li>'
77
#htmllist += '<li>' + x['memberquantity'] + ' ' + x['membermwsku'] + ' ' + x['membermwname'] + '</li>'
78
#pp(str(x['memberquantity']) + ' ' + x['membermwsku'] + ' ' + x['membermwname'])
80
htmllist += '<p>' + self.control_no + ' : ' + self.ornum + ' : ' + self.position + '</p>'
81
htmllist += self.footer
82
return htmllist.encode('utf-8')
85
if __name__ == '__main__':
86
foo = GrainLabeler('F123','120AGX')
89
myFile = open('myFile.html', 'w')
92
os.system('xvfb-run -a -s "-screen 0 640x480x16" wkhtmltopdf -B 1mm -L 1mm -T 7mm -R 1mm --page-height 2in --page-width 3in myFile.html testpdf.pdf')
93
#os.system('evince testpdf.pdf')
94
os.system('lpr -o media=Custom.3x2in -P mwgrainlabeler testpdf.pdf')