Odoo Help

0

[Solved] How to print to PosBox proxy from python (or regular OpenERP module)

By
Mario Arias Badila
on 8/26/14, 3:10 PM 3,722 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)

0
Jose Vasquez
On 4/30/15, 3:45 PM

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.

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

Mario Arias Badila
on 4/30/15, 9:08 PM

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

Jose Vasquez
on 5/2/15, 4:10 PM
0
Mario Arias Badila
On 8/27/14, 1:34 PM

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)

 

 

About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

Register

Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

2 follower(s)

Stats

Asked: 8/26/14, 3:10 PM
Seen: 3722 times
Last updated: 4/30/15, 3:54 PM