[IMP] edi: make EDI PDF download button work (needs styling)

bzr revid: odo@openerp.com-20111018170314-3akjjiyboeb957hy
This commit is contained in:
Olivier Dony 2011-10-18 19:03:14 +02:00
parent afb0460478
commit 17539fa343
5 changed files with 54 additions and 28 deletions

View File

@ -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)

View File

@ -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 {

View File

@ -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

View File

@ -7,29 +7,28 @@
<tr>
<td colspan="2" valign="top" id="oe_header" class="header">
<div> <a href="/" class="company_logo_link"> <div class="company_logo" /> </a> </div>
<div class="header_corner"> <button type="button" name="action_print">View/Print PDF</button> </div>
</td>
</tr>
<tr>
<td class="oe_edi_view">
<p class="oe_form_paragraph"><t t-raw="widget.center"/></p>
<p><button type="button" id="edi_action_print" class="edi_action_print">View/Print PDF</button></p>
</td>
<td class="oe_edi_sidebar_container">
<button type="button" name="action_print">View/Print PDF</button>
<p class="oe_edi_sidebar_title">
Push this document into your enterprise management system
</p>
<p>
<input type="radio" id="oe_edi_rd_import_openerp" name="oe_edi_rd_import" value="oe_edi_import_openerp"/>
<label for="oe_edi_rd_import_openerp">Import it into my existing OpenERP instance</label>
<label for="oe_edi_rd_import_openerp">Import it into an existing OpenERP instance</label>
<p class="oe_edi_nested_block">
<label for="oe_edi_txt_saas_url">OpenERP instance address:</label> http://<input type="text" id="oe_edi_txt_server_url"/>
</p>
</p>
<p>
<input type="radio" id="oe_edi_rd_import_saas_account" name="oe_edi_rd_import" value="oe_edi_create_saas_account"/>
<label for="oe_edi_rd_import_saas_account">Create a new OpenERP instance for me:</label>
<label for="oe_edi_rd_import_saas_account">Create a new OpenERP instance:</label>
<p class="oe_edi_nested_block"><label for="oe_edi_txt_saas_url">Company:</label><input type="text" name="oe_edi_txt_saas_url"/>.my.openerp.com</p>
<p class="oe_edi_nested_block"><label for="oe_edi_txt_saas_password">Password:</label><input type="password" name="oe_edi_txt_saas_password"/></p>
<p class="oe_edi_nested_block"><label for="oe_edi_txt_saas_email">Email:</label><input type="text" name="oe_edi_txt_saas_email"/></p>

View File

@ -1,6 +1,6 @@
<template>
<t t-name="Edi.account.invoice">
<t t-if="!invoice.reconciled">
<t t-if="!doc.reconciled">
<table width="100%">
<tr>
<td>
@ -22,19 +22,19 @@
</tr>
</table>
</t>
<h1>Invoice <t t-esc="invoice.internal_number"/>: <t t-esc="invoice.amount_total"/><t t-esc="invoice.currency_id[1]"/></h1>
<h1>Invoice <t t-esc="doc.internal_number"/>: <t t-esc="doc.amount_total"/><t t-esc="doc.currency_id[1]"/></h1>
<p>
<b><t t-esc="invoice.company_id[1]"/></b><br/>
<t t-if="invoice.company_address">
<t t-esc="invoice.company_address.zip"/> <t t-esc="invoice.company_address.street"/><br/>
<t t-esc="invoice.company_address.city"/><br/>
<t t-if="invoice.company_address.country_id" t-esc="invoice.company_address.country_id[1]"/><br/>
Phone: <t t-esc="invoice.company_address.phone"/>
<b><t t-esc="doc.company_id[1]"/></b><br/>
<t t-if="doc.company_address">
<t t-esc="doc.company_address.zip"/> <t t-esc="doc.company_address.street"/><br/>
<t t-esc="doc.company_address.city"/><br/>
<t t-if="doc.company_address.country_id" t-esc="doc.company_address.country_id[1]"/><br/>
Phone: <t t-esc="doc.company_address.phone"/>
</t>
</p>
<p align="right">
<b><t t-esc="invoice.partner_id[1]"/></b><br/>
<t t-esc="invoice.address_invoice_id[1]"/>
<b><t t-esc="doc.partner_id[1]"/></b><br/>
<t t-esc="doc.address_invoice_id[1]"/>
</p>
<table width="100%">
<tr>
@ -44,10 +44,10 @@
<th align="left">Your Reference</th>
</tr>
<tr>
<td align="left"><t t-esc="invoice.name"/><t t-esc="invoice.comment"/></td>
<td align="left"><t t-esc="invoice.date_invoice"/></td>
<td align="left"><t t-esc="invoice.origin"/></td>
<td align="left"><t t-esc="invoice.reference"/></td>
<td align="left"><t t-esc="doc.name"/><t t-esc="doc.comment"/></td>
<td align="left"><t t-esc="doc.date_invoice"/></td>
<td align="left"><t t-esc="doc.origin"/></td>
<td align="left"><t t-esc="doc.reference"/></td>
</tr>
</table>
<table width="100%" >
@ -58,13 +58,13 @@
<th align="left">Discount</th>
<th align="right">Price</th>
</tr>
<t t-if="invoice.invoice_line" t-foreach="invoice.invoice_line" t-as="invoice_line">
<t t-if="doc.invoice_line" t-foreach="doc.invoice_line" t-as="invoice_line">
<tr>
<td align="left"><t t-esc="invoice_line.name"/><br/><t t-esc="invoice_line.note"/></td>
<td align="left"><t t-esc="invoice_line.quantity"/><t t-esc="invoice_line.uos_id[1]"/></td>
<td align="left"><t t-esc="invoice_line.price_unit"/></td>
<td align="left"><t t-esc="invoice_line.discount"/></td>
<td align="right"><t t-esc="invoice_line.price_subtotal"/><t t-esc="invoice.currency_id[1]"/></td>
<td align="right"><t t-esc="invoice_line.price_subtotal"/><t t-esc="doc.currency_id[1]"/></td>
</tr>
</t>
<tr>
@ -74,12 +74,12 @@
<tr>
<td colspan="3"></td>
<td>Net Total: </td>
<td align="right"><t t-esc="invoice.amount_untaxed"/><t t-esc="invoice.currency_id[1]"/></td>
<td align="right"><t t-esc="doc.amount_untaxed"/><t t-esc="doc.currency_id[1]"/></td>
</tr>
<tr>
<td colspan="3"></td>
<td>Taxes: </td>
<td align="right"><t t-esc="invoice.amount_tax"/><t t-esc="invoice.currency_id[1]"/></td>
<td align="right"><t t-esc="doc.amount_tax"/><t t-esc="doc.currency_id[1]"/></td>
</tr>
<tr>
<td colspan="3"></td>
@ -88,7 +88,7 @@
<tr>
<td colspan="3"></td>
<td>Total: </td>
<td align="right"><t t-esc="invoice.amount_total"/><t t-esc="invoice.currency_id[1]"/></td>
<td align="right"><t t-esc="doc.amount_total"/><t t-esc="doc.currency_id[1]"/></td>
</tr>
<tr>
<td colspan="3">
@ -98,11 +98,11 @@
<th align="right">Base Amount</th>
<th align="right">Amount</th>
</tr>
<t t-if="invoice.tax_line"><t t-foreach="invoice.tax_line" t-as="tax_line">
<t t-if="doc.tax_line"><t t-foreach="doc.tax_line" t-as="tax_line">
<tr>
<td align="left"><t t-esc="tax_line.name"/></td>
<td align="right"><t t-esc="tax_line.base_amount"/><t t-esc="invoice.currency_id[1]"/></td>
<td align="right"><t t-esc="tax_line.amount"/><t t-esc="invoice.currency_id[1]"/></td>
<td align="right"><t t-esc="tax_line.base_amount"/><t t-esc="doc.currency_id[1]"/></td>
<td align="right"><t t-esc="tax_line.amount"/><t t-esc="doc.currency_id[1]"/></td>
</tr>
</t>
</t>