Skip to Content
Menu
This question has been flagged
3 Replies
10080 Views

I am trying to send from regular OpenERP session a "POS cashier close report" (a small receipt to be printed in the same PosBox proxy).

I tried with following python code, but the proxy complaints that it expects two parameters...  Any suggestions or pointers?

 

import urllib

import urllib2

import json

xdata = {"receipt": '<receipt align="center" font="a" value-thousands-separator="," width="30"><h1>Alias Accesorios</h1><br/><div font="a"><div>Ced.Juridica: 3-101-680968</div></div></receipt>',"timeout":4000}

json_data = json.dumps(xdata)

url = 'http://localhost:8069/hw_proxy/print_xml_receipt'

req = urllib2.Request(url,json_data, headers={"Content-Type":"application/json",})

result = urllib2.urlopen(req)

Avatar
Discard
Author Best Answer

Got it working, thanks to help from Nhomar !

 

Keep in mind that if your odoo server is on the internet, you will need to use port forwarding at your firewall to access the local PosBox proxy...

 

            import urllib2
            import json

            url = 'http://my.ip.address.here:8069/hw_proxy/print_xml_receipt'
            data = {
                "jsonrpc": "2.0",
                "params": {"receipt": u'<receipt align="center" font="a" value-thousands-separator="," width="30"><h1>Company</h1><br/><div font="a"><br/>' + \
                                        u'</div></receipt>'},
            }
            req = urllib2.Request(url,json.dumps(data), headers={"Content-Type":"application/json",})
            result = urllib2.urlopen(req)

 

 

Avatar
Discard
Best Answer

I am trying to get this to work in Odoo CE 12 but without success. My code is given below. Can anyone provide any suggestion?

def button(self):
_logger.info('Button for printing')
url = 'http://192.168.2.121:8069/hw_proxy/print_xml_receipt'
data = {
"jsonrpc": "2.0",
"params": {
'receipt': '<receipt><h1>Company</h1><br/><div font="a"><br/>Test</div></receipt>'}
}
result = urllib.request.Request(url, json.dumps(data), headers={"Content-Type":"application/json"})
Avatar
Discard
Best Answer

Help me Mario.

have a problem, my code is following suit. As follow: .

import urllib2 
import json

def prinPdf(self,cr,uid,context=None):
url = 'http://10.0.137.46:8069/hw_proxy/print_xml_receipt' data = { "jsonrpc": "2.0", "params": {"receipt": "<h1>Company</h1>"}, } req = urllib2.Request(url,json.dumps(data), headers={"Content-Type":"application/json",}) result = urllib2.urlopen(req)
return result

I got an error of the following type:

2015-04-30 18:54:22,561 8891 ERROR None openerp.http: Exception during JSON request handling.
Traceback (most recent call last):
  File "/opt/odoo/ferca/openerp/http.py", line 530, in _handle_exception
    return super(JsonRequest, self)._handle_exception(exception)
  File "/opt/odoo/ferca/openerp/http.py", line 1399, in _dispatch_nodb
    func, arguments = self.nodb_routing_map.bind_to_environ(request.httprequest.environ).match()
  File "/usr/lib/python2.7/dist-packages/werkzeug/routing.py", line 1433, in match
    raise NotFound()
NotFound: 404: Not Found

My configuration file is:

[options]
; This is the password that allows database operations:
admin_passwd = admin
db_host = False
db_port = False
db_user = testdb
db_password = 123123
addons_path = /opt/odoo/test/addons xmlrpc_port = 8069 logfile = /var/log/odoo/odoo-test.log log_level = debug

Some guidance please? Thanks.

Avatar
Discard
Author

the url must point to a running "POSBOX" instance, not your regular odoo server...

my server is currently running at the same time as poxbox. This url is running my server, and posbox.