~midwest/midwest-dev/stock_print_grouped_picking_v2

« back to all changes in this revision

Viewing changes to report/dev_v1.py

  • Committer: Kyle Waid
  • Date: 2013-05-22 15:09:06 UTC
  • Revision ID: gadgetscentralservice@gmail.com-20130522150906-uswxg9vycu3xn6ld
Updates

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
import json
 
2
import sys
 
3
import os
 
4
import codecs
 
5
import unicodedata
 
6
from tempfile import NamedTemporaryFile
 
7
from pprint import pprint as pp
 
8
 
 
9
 
 
10
class GrainLabeler(object):
 
11
    def __init__(self,orderNumber,itemNumber, crushed='', control_no = '', position = ''):
 
12
        if len(crushed) >=2:
 
13
            print crushed
 
14
            if crushed[:4] == 's:13':
 
15
                if crushed[21:23] == 'Yes':
 
16
                    self.crushed = 'Crushed'
 
17
                else:
 
18
                    self.crushed = 'Unmilled'
 
19
 
 
20
        self.ornum = orderNumber
 
21
        self.itmnum = itemNumber
 
22
        self.control_no = control_no
 
23
        self.position = position
 
24
        self.createHtml()
 
25
        makehtml =  self.getData()
 
26
        with NamedTemporaryFile(delete=False, mode='r+w', suffix='.html') as myFile:
 
27
            myFile.write(makehtml)
 
28
            myFile.close()
 
29
            with NamedTemporaryFile(mode='r+w', suffix='.pdf') as myPdf:
 
30
                foo = myFile.name
 
31
                COM = 'cp %s /tmp/wamp.html' % foo
 
32
                os.system(COM)
 
33
                print myFile.name
 
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)
 
38
                print command
 
39
                os.system(command) 
 
40
 
 
41
 
 
42
 
 
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()
 
46
        htmlFile.close()
 
47
        htmlFile = open('/usr/local/openerp/community/stock_print_grouped_picking/report/footer.html', 'rb')
 
48
        self.footer =  htmlFile.read()
 
49
        htmlFile.close()
 
50
        fulfillmentNumber = self.ornum
 
51
        memberItems = []
 
52
 
 
53
    def getData(self):
 
54
        foo = open('/usr/local/openerp/community/stock_print_grouped_picking/report/memberdb.json', 'rb')
 
55
        bar = json.loads(foo.read())
 
56
        labeltitle = ''
 
57
        #pp(len(labeltitle))
 
58
        if len(labeltitle) >= 0:
 
59
            for x in bar:
 
60
                if len(labeltitle) < 1 and str(x['mwsku']).upper() == self.itmnum:
 
61
                    labeltitle = x['mwname']
 
62
                    #pp('SKU: ' + x['mwsku'])
 
63
 
 
64
        htmllist = self.head
 
65
        htmllist += '<h1>' + labeltitle + '</h1>'
 
66
        #old
 
67
        #htmllist += '<p>' + self.ornum + ' : ' + self.control_no + ' : ' + self.position + '</p>'
 
68
        htmllist += '<p>' + self.crushed + '</p>'
 
69
        htmllist += '<ul>'
 
70
        for x in bar:
 
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'])
 
79
        htmllist += '</ul>'
 
80
        htmllist += '<p>' + self.control_no + '  :  ' + self.ornum + '  :  ' + self.position + '</p>'
 
81
        htmllist += self.footer
 
82
        return htmllist.encode('utf-8')
 
83
        #pp(bar)
 
84
 
 
85
if __name__ == '__main__':
 
86
    foo = GrainLabeler('F123','120AGX')
 
87
    foo.createHtml()
 
88
    bar = foo.getData()
 
89
    myFile = open('myFile.html', 'w')
 
90
    myFile.write(bar)
 
91
    myFile.close()
 
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')
 
95