From 17539fa343dbc991a1820df1c253e2afe0fe43ff Mon Sep 17 00:00:00 2001 From: Olivier Dony Date: Tue, 18 Oct 2011 19:03:14 +0200 Subject: [PATCH] [IMP] edi: make EDI PDF download button work (needs styling) bzr revid: odo@openerp.com-20111018170314-3akjjiyboeb957hy --- addons/edi/controllers/main.py | 18 ++++++++++ addons/edi/static/src/css/edi.css | 4 +++ addons/edi/static/src/js/edi.js | 7 +++- addons/edi/static/src/xml/edi.xml | 9 +++-- addons/edi/static/src/xml/edi_account.xml | 44 +++++++++++------------ 5 files changed, 54 insertions(+), 28 deletions(-) diff --git a/addons/edi/controllers/main.py b/addons/edi/controllers/main.py index 03aa457e160..715eaaa74d5 100644 --- a/addons/edi/controllers/main.py +++ b/addons/edi/controllers/main.py @@ -60,6 +60,24 @@ class EDI(openerpweb.Controller): response = werkzeug.wrappers.Response( result, headers=[('Content-Type', 'text/html; charset=utf-8'), ('Content-Length', len(result))]) return response + @openerpweb.httprequest + def download_attachment(self, req, db, token): + result = req.session.proxy('edi').get_edi_document(db, token) + doc = json.loads(result)[0] + attachment = doc['__attachments'] and doc['__attachments'][0] + if attachment: + result = attachment["content"].decode('base64') + import email.Utils as utils + + # Encode as per RFC 2231 + filename_utf8 = attachment['file_name'] + filename_encoded = "%s=%s" % ('filename*', + utils.encode_rfc2231(filename_utf8, 'utf-8')) + response = werkzeug.wrappers.Response( result, headers=[('Content-Type', 'application/pdf'), + ('Content-Disposition', 'inline; ' + filename_encoded), + ('Content-Length', len(result))]) + return response + @openerpweb.jsonrequest def get_edi_document(self, req, db, token): result = req.session.proxy('edi').get_edi_document(db, token) diff --git a/addons/edi/static/src/css/edi.css b/addons/edi/static/src/css/edi.css index b83e2d2d6b6..0db97871b90 100644 --- a/addons/edi/static/src/css/edi.css +++ b/addons/edi/static/src/css/edi.css @@ -19,6 +19,10 @@ div.oe_edi_center { margin-right: 5px; } +button.edi_action_print { + font-size: 1.5em; +} + /** EDI Sidebar **/ .oe_edi_sidebar_title { diff --git a/addons/edi/static/src/js/edi.js b/addons/edi/static/src/js/edi.js index eaf380796f2..c9a8aa58576 100644 --- a/addons/edi/static/src/js/edi.js +++ b/addons/edi/static/src/js/edi.js @@ -27,9 +27,14 @@ openerp.edi.EdiView = openerp.web.Widget.extend({ this.center = openerp.web.qweb.render(template, param); //console.log(this.center); this.right = ""; - this.$element.html(openerp.web.qweb.render("EdiView", param )); + this.$element.html(openerp.web.qweb.render("EdiView", param)); + this.$element.find('button#edi_action_print').bind('click', this.do_print) //self.$element.delegate('button.oe_edi_button_import', 'click', this.do_import); }, + do_print: function(e){ + l = window.location; + window.location = l.protocol + '//' + l.host + "/edi/download_attachment?db=" + this.db + "&token=" + this.token; + }, do_import: function(e){ $element = $(e.view.document.body) token = e.data.edi.token diff --git a/addons/edi/static/src/xml/edi.xml b/addons/edi/static/src/xml/edi.xml index 5b50a018181..d31021618ce 100644 --- a/addons/edi/static/src/xml/edi.xml +++ b/addons/edi/static/src/xml/edi.xml @@ -7,29 +7,28 @@
-
+

+

- -

Push this document into your enterprise management system

- +

http://

- +

.my.openerp.com

diff --git a/addons/edi/static/src/xml/edi_account.xml b/addons/edi/static/src/xml/edi_account.xml index 64ef22caefb..aa517c34df9 100644 --- a/addons/edi/static/src/xml/edi_account.xml +++ b/addons/edi/static/src/xml/edi_account.xml @@ -1,6 +1,6 @@