Skip to content

Instantly share code, notes, and snippets.

@aliomattux
Created October 15, 2013 16:30
Show Gist options
  • Save aliomattux/6994428 to your computer and use it in GitHub Desktop.
Save aliomattux/6994428 to your computer and use it in GitHub Desktop.
def ajax_label_request():
response.generic_patterns = ['*']
req = request.vars
qty = req["quantity"]
gen_prod = api_call('product.item', 'read', [int(req['item_id'])])
tmpl_prod = api_call('product.template', 'read', gen_prod[0]["product_tmpl_id"][0])
intid = tmpl_prod["internalid"]
prod_info = api_call('product.item', 'read', tmpl_prod["product_item_ids"])
inv_info = api_call('stock.inventory', 'read', tmpl_prod["stock_inventory_ids"])
nbsku = ""
mwsku = ""
nbbin = ""
mwbin = ""
for prod in prod_info:
if prod["brand_id"][1] == "Northern Brewer":
nbsku = prod["sku"]
if prod["brand_id"][1] == "Midwest Supplies":
mwsku = prod["sku"]
for inv in inv_info:
if inv["storage_type"] != "fixed_pick":
continue
if inv["brand_id"][1] == "Northern Brewer":
nbbin = inv["bin_id"][1]
if inv["brand_id"][1] == "Midwest Supplies":
mwbin = inv["bin_id"][1]
overstock = ""
overstock2 = ""
width = 2.25
#Height in inches
height = 4
w = int( 203 * width)
h = int( 203 * height)
#labelparm = (w, h, nbsku, nbbin, mwsku, mwbin, overstock, overstock2, intid)
labelparm = (w, h, nbsku, nbbin, mwsku, mwbin, intid)
rawlabel = '''N
q%s
Q%s,a6
A,,,,,N,
A,,,,,N,
A400,20,1,4,3,2,N,"N:%s %s"
A300,20,1,4,3,2,N,"M:%s %s"
B50,700,0,1,3,3,72,B,"%s"
P1,1
''' % labelparm
import tempfile, os
from pprint import pprint as pp
f = tempfile.NamedTemporaryFile(delete=False)
f.write(rawlabel)
f.close()
pp(request.env.remote_addr)
if request.env.remote_addr == '10.0.2.9':
print 'Received request to print from Sun'
os.system('scp %s ken@zeus:/tmp/foolabel.epl' % f.name)
os.system('ssh -t ken@zeus "lpr -#%s -P zpl -l /tmp/foolabel.epl" ' % qty)
elif request.env.remote_addr == '10.0.2.91':
print 'Received request to print from Zeus'
os.system('scp %s ken@zeus:/tmp/foolabel.epl' % f.name)
os.system('ssh -t ken@zeus "lpr -#%s -P zpl -l /tmp/foolabel.epl" ' % qty)
#os.system('lpr -#%s -P zpl -l /tmp/%s' % qty)
elif request.env.remote_addr == '10.0.11.25':
os.system('cp %s /tmp/cart1.epl' % f.name)
os.system('perl /home/www-data/epl2cpcl_2X4.pl > /tmp/cart1.cpcl')
os.system('scp /tmp/cart1.cpcl [email protected]:/tmp/cart1.cpcl')
os.system('ssh -t [email protected] "lpr -#%s -P Zebra320USB -l /tmp/cart1.cpcl" ' % qty)
#os.system('scp %s [email protected]:/tmp/label.epl' % f.name)
#os.system('ssh -t 10.0.11.25 "/home/nbrewer/bin/suitebrewprintlabel %s"' % qty)
#os.system('ssh -t 10.0.11.25 "lpr -#%s -P Zebra320USB -l /tmp/newlabel.epl"' % qty)
#operations02 - karl paulsen
elif request.env.remote_addr == '10.0.2.81':
os.system('scp %s nbrewer@quark:/tmp/receiving02.epl' % f.name)
os.system('ssh -t nbrewer@quark "lpr -#%s -P Barcoder -l /tmp/receiving02.epl"' % qty)
elif request.env.remote_addr == '10.0.2.88':
os.system('scp %s nbrewer@quark:/tmp/label.epl' % f.name)
os.system('ssh -t nbrewer@quark "lpr -#%s -P Barcoder -l /tmp/label.epl"' % qty)
elif request.env.remote_addr == '10.0.2.90':
os.system('scp %s nbrewer@newport:/tmp/label.epl' % f.name)
os.system('ssh -t nbrewer@newport "lpr -#%s -P Zebra--TLP2844 -l /tmp/label.epl" ' % qty)
elif request.env.remote_addr == '10.0.2.43':
os.system('scp %s it@receiving04:/tmp/foolabel.epl' % f.name)
os.system('ssh -t it@receiving04 "lpr -#%s -P zebragx420d -l /tmp/foolabel.epl" ' % qty)
#os.system('lpr -#%s -P rec4printer -l /tmp/%s' % qty)
elif request.env.remote_addr == '10.0.11.29':
#mobile receiving cart 2 - RSVD620lt02
os.system('cp %s /tmp/cart2.epl' % f.name)
os.system('perl /home/www-data/epl2cpcl_2X4.pl > /tmp/cart2.cpcl')
os.system('scp /tmp/cart2.cpcl [email protected]:/tmp/cart2.cpcl')
os.system('ssh -t [email protected] "lpr -#%s -P XXQLJ123900750 -l /tmp/cart2.cpcl" ' % qty)
#os.system('lpr -#%s -P rec4printer -l /tmp/carousel-label.epl' % qty)
else:
f = tempfile.NamedTemporaryFile(delete=False)
f.write('\n')
f.write(' ')
f.write(request.env.remote_addr)
f.write('\n')
f.write(' ')
f.write('Unknown IP\n')
f.write(' ')
f.write('SB Mobile')
f.close()
os.system('scp %s ken@zeus:/tmp/suitebrewmobileerror' % f.name)
os.system('ssh -t ken@zeus "lpr -#%s -P zpl /tmp/suitebrewmobileerror" ' % qty)
#os.system('ssh -t ken@zeus "echo foo bar | lpr -#%s -P zpl" ' % qty)
return dict(PrintJobSentToIT=True)
#Working error messenger
#message = 'Item label print job requested from %s. Printer unkown for this host.' % request.env.remote_addr
#return dict(result=message)
#os.system('cat %s | ssh -t ken@zeus "cat > /tmp/testfile && lpr -o page-right=5 -o page-top=10 -P zpl -l /tmp/testfile"' % f.name)
####
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment