Skip to content

Instantly share code, notes, and snippets.

@aliomattux
Created October 16, 2013 16:22
Show Gist options
  • Save aliomattux/7010645 to your computer and use it in GitHub Desktop.
Save aliomattux/7010645 to your computer and use it in GitHub Desktop.
def api_report_call(*args):
""" Send the report request to SuiteBrew """
uid = session.username
pwd = session.password
url = 'http' + (secure and 's' or '') + '://' + server + ':' + port
report_conn = xmlrpclib.ServerProxy(url + '/xmlrpc/report')
try:
report_conn.report(dbname, 1, 'admin', *args)
except xmlrpclib.Fault as err:
return dict(err=err.faultCode)
def ajax_label_request():
""" Send a product id to SuiteBrew to print a label
This feature assumes the user has a report printer defined
"""
response.generic_patterns = ['*']
req = request.vars
product_id = int(req['item_id'])
#If the quantity is greater than 50
qty = req["quantity"]
if int(qty) > 50:
qty="50"
#The name of the report takes place of Model name
model = 'threebytwo.receiver.label'
#FIXME: Is it possible to send one request instead of many?
for x in range(int(qty)):
#Sleep is required to not overload the server
sleep(1)
api_report_call(model, [product_id], {'model': model, 'id': product_id, \
'report_type': 'pdf'})
return dict(PrintJobSentToIT=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment