[IMP] edi: improve EDI preview sidebar + add payment options for invoices

bzr revid: odo@openerp.com-20111028134724-1nkpg8srghbznpov
This commit is contained in:
Olivier Dony 2011-10-28 15:47:24 +02:00
parent 5fa1a6dd06
commit 59c6a000cb
7 changed files with 88 additions and 22 deletions

View File

@ -24,7 +24,7 @@ from osv import fields, osv
class res_company(osv.osv):
_inherit = "res.company"
_columns = {
'paypal_account': fields.char("Paypal Account", size=128, help="the paypal username (usually email)"),
'paypal_account': fields.char("Paypal Account", size=128, help="Paypal username (usually email) for receiving online payments."),
'overdue_msg': fields.text('Overdue Payments Message', translate=True),
'property_reserve_and_surplus_account': fields.property(
'account.account',

View File

@ -46,5 +46,9 @@ class res_company(osv.osv):
result = res_partner_address.edi_export(cr, uid, [address], edi_struct=edi_address_struct, context=context)[0]
if company.logo:
result['logo'] = company.logo # already base64-encoded
if company.paypal_account:
result['paypal_account'] = company.paypal_account
# bank info
if company.bank_ids:
result['bank_ids'] = res_partner_address.edi_m2m(cr, uid, company.bank_ids, context=context)
return result

View File

@ -59,5 +59,17 @@ class res_partner_address(osv.osv, EDIMixin):
edi_struct or dict(RES_PARTNER_ADDRESS_EDI_STRUCT),
context=context)
class res_partner_bank(osv.osv, EDIMixin):
_inherit = "res.partner.bank"
def edi_import(self, cr, uid, edi_document, context=None):
# handle bank info, if any
edi_bank_ids = edi_document.pop('bank_ids', None)
result = super(res_partner_address,self).edi_import(cr, uid, edi_document, context=context)
if edi_bank_ids:
partner = self._edi_get_object_by_external_id(cr, uid, edi_document['partner_id'][0],
'res.partner', context=context)
assert partner is not None
import_ctx = dict(context, default_partner_id=partner.id)
bank_ids = []
for ext_bank_id, bank_name in edi_bank_ids:
bank_ids.append(self.edi_import_relation(cr, uid, 'res.partner.bank',
bank_name, ext_bank_id, context=import_ctx))
return

View File

@ -30,9 +30,8 @@ button.oe_edi_action_print img {
font-weight: bold;
font-size: 1.3em;
}
.oe_edi_nested_block {
.oe_edi_nested_block, .oe_edi_nested_block_import, .oe_edi_nested_block_pay {
margin: 0px 40px;
padding: 0px;
display: none; /* made visible by click on parent input/label */
}
.oe_edi_right_top .oe_edi_nested_block label {
@ -57,6 +56,12 @@ button.oe_edi_action_print img {
font-size: 90%;
}
/** Sidebar bottom **/
.oe_edi_paypal_button {
margin: 6px;
}
/** Paperbox, from http://www.sitepoint.com/pure-css3-paper-curl/ **/
body {
background: #EEE; /* contrast with paper */

View File

@ -39,7 +39,8 @@ openerp.edi.EdiView = openerp.web.Widget.extend({
this.$element.find('button#oe_edi_import_existing').bind('click', this.do_import_existing);
this.$element.find('button#oe_edi_import_create').bind('click', this.do_import_create);
this.$element.find('button#oe_edi_download').bind('click', this.do_download);
this.$element.find('.oe_edi_import_choice, .oe_edi_import_choice_label').bind('click', this.toggle_choice);
this.$element.find('.oe_edi_import_choice, .oe_edi_import_choice_label').bind('click', this.toggle_choice('import'));
this.$element.find('.oe_edi_pay_choice, .oe_edi_pay_choice_label').bind('click', this.toggle_choice('pay'));
this.$element.find('#oe_edi_download_show_code').bind('click', this.show_code);
},
show_code: function($event) {
@ -51,10 +52,27 @@ openerp.edi.EdiView = openerp.web.Widget.extend({
var url_prefix = l.protocol + '//' + l.host;
return url_prefix +'/edi/download?db=' + this.db + '&token=' + this.token;
},
toggle_choice: function($e) {
$('.oe_edi_nested_block').hide();
$('.'+$e.target.id+'_nested').show();
return true;
get_paypal_url: function(document_type, ref_field) {
comp_name = encodeURIComponent(this.doc.company_id[1]);
doc_ref = encodeURIComponent(this.doc[ref_field]);
paypal_account = encodeURIComponent(this.doc.company_address.paypal_account);
amount = encodeURIComponent(this.doc.amount_total);
cur_code = encodeURIComponent(this.doc.currency.code);
paypal_url = "https://www.paypal.com/cgi-bin/webscr?cmd=_xclick" +
"&business=" + paypal_account +
"&item_name=" + document_type + "%20" + comp_name + "%20" + doc_ref +
"&invoice=" + doc_ref +
"&amount=" + amount +
"&currency_code=" + cur_code +
"&button_subtype=services&no_note=1&bn=OpenERP_PayNow_" + cur_code;
return paypal_url;
},
toggle_choice: function(mode) {
return function($e) {
$('.oe_edi_nested_block_'+mode).hide();
$('.'+$e.target.id+'_nested').show();
return true;
}
},
do_print: function(e){
var l = window.location;

View File

@ -29,7 +29,7 @@
<input type="radio" id="oe_edi_import_openerp" name="oe_edi_import" class="oe_edi_import_choice"/>
<label for="oe_edi_import_openerp" id="oe_edi_import_openerp" class="oe_edi_import_choice_label">Import it into an existing OpenERP instance</label>
</div>
<p class="oe_edi_nested_block oe_edi_import_openerp_nested">
<p class="oe_edi_nested_block_import oe_edi_import_openerp_nested">
<label for="oe_edi_txt_server_url">OpenERP instance address:</label>
<br/>
http://<input type="text" id="oe_edi_txt_server_url"/><br/>
@ -40,7 +40,7 @@
<input type="radio" id="oe_edi_import_saas" name="oe_edi_import" class="oe_edi_import_choice"/>
<label for="oe_edi_import_saas" id="oe_edi_import_saas" class="oe_edi_import_choice_label">Import it into a new OpenERP Online instance:</label>
</div>
<p class="oe_edi_nested_block oe_edi_import_saas_nested">
<p class="oe_edi_nested_block_import oe_edi_import_saas_nested">
<button type="button" class="oe_edi_import_button" id="oe_edi_import_create">Create my new OpenERP instance</button>
</p>
@ -48,7 +48,7 @@
<input type="radio" id="oe_edi_import_download" name="oe_edi_import" class="oe_edi_import_choice"/>
<label for="oe_edi_import_download" id="oe_edi_import_download" class="oe_edi_import_choice_label">Import into another application</label>
</div>
<p class="oe_edi_nested_block oe_edi_small oe_edi_import_download_nested">
<p class="oe_edi_nested_block_import oe_edi_small oe_edi_import_download_nested">
OpenERP's Electronic Data Interchange documents are based on a generic and language
independent <a href="http://json.org">JSON</a> serialization of the document's attribute.
It is usually very quick and straightforward to create a small plug-in for your preferred
@ -58,13 +58,13 @@
<br/>
To get started immediately, <a href="#" id="oe_edi_download_show_code">see is all it takes to use this EDI document in Python</a>.
</p>
<div class="python oe_edi_nested_block oe_edi_small" id="oe_edi_download_code">
<div class="python oe_edi_nested_block_import oe_edi_small" id="oe_edi_download_code">
<ol><li class="li1"><div class="de1"><span class="kw1">import</span> <span class="kw3">urllib2</span><span class="sy0">,</span> simplejson</div></li>
<li class="li1"><div class="de1">edi_document <span class="sy0">=</span> <span class="kw3">urllib2</span>.<span class="me1">urlopen</span><span class="br0">(</span><span class="st0">'<t t-esc="widget.get_download_url()"/>'</span><span class="br0">)</span>.<span class="me1">read</span><span class="br0">(</span><span class="br0">)</span></div></li>
<li class="li2"><div class="de2">document_data <span class="sy0">=</span> simplejson.<span class="me1">loads</span><span class="br0">(</span>edi_document<span class="br0">)</span><span class="br0">[</span><span class="nu0">0</span><span class="br0">]</span></div></li>
<li class="li1"><div class="de1"><span class="kw1">print</span> <span class="st0">"Amount: "</span><span class="sy0">,</span> document_data<span class="br0">[</span><span class="st0">'amount_total'</span><span class="br0">]</span></div></li>
</ol></div>
<p class="oe_edi_nested_block oe_edi_small oe_edi_import_download_nested">
<p class="oe_edi_nested_block_import oe_edi_small oe_edi_import_download_nested">
You can download the raw EDI document here:<br/>
<input type="text" readonly="readonly" t-att-value="widget.get_download_url()"/>
<button type="button" class="oe_edi_import_button" id="oe_edi_download">Download</button>

View File

@ -125,12 +125,39 @@
</t>
<t t-name="Edi.account.invoice.sidebar">
<t t-if="!doc.reconciled">
<p class="oe_edi_sidebar_title">Pay Online</p>
<!-- TODO replace this with correct <form>s to payement gw -->
<input type="radio" id="oe_edi_invoice_rd_pay_paypal" name="oe_edi_invoice_rd_pay" value="paypal">Paypal</input>
<input type="radio" id="oe_edi_invoice_rd_pay_google_checkout" name="oe_edi_invoice_rd_pay" value="google">Google Checkout</input>
<input type="radio" id="oe_edi_invoice_rd_pay_bank" name="oe_edi_invoice_rd_pay" value="bank">Bank wire Transfer</input>
<button type="button" id="oe_edi_invoice_button_pay" name="oe_edi_invoice_button_pay">Pay</button>
<t t-if="doc.company_address.paypal_account || doc.company_address.bank_ids">
<p class="oe_edi_sidebar_title">Pay Online</p>
<t t-if="doc.company_address.paypal_account">
<div class="oe_edi_option">
<input type="radio" id="oe_edi_paypal" name="oe_edi_pay"/>
<label for="oe_edi_paypal" id="oe_edi_paypal" class="oe_edi_pay_choice_label">Paypal</label>
</div>
<p class="oe_edi_nested_block_pay oe_edi_paypal_nested">
You may directly pay this invoice online via Paypal's secure payment gateway:<br/>
<a t-att-href="widget.get_paypal_url('Invoice','internal_number')" target="_new">
<img class="oe_edi_paypal_button" src="https://www.paypal.com/en_US/i/btn/btn_paynowCC_LG.gif"/>
</a>
</p>
</t>
<t t-if="doc.company_address.bank_ids">
<div class="oe_edi_option">
<input type="radio" id="oe_edi_pay_wire" name="oe_edi_pay"/>
<label for="oe_edi_pay_wire" id="oe_edi_pay_wire" class="oe_edi_pay_choice_label">Bank Wire Transfer</label>
</div>
<p class="oe_edi_nested_block_pay oe_edi_pay_wire_nested">
Please transfer <strong><t t-esc="doc.amount_total"/> <t t-esc="doc.currency_code"/></strong> to
<strong><t t-esc="doc.company_id[1]"/></strong> (postal address on the invoice header)
using one of the following bank accounts. Be sure to mention the invoice
reference <strong><t t-esc="doc.internal_number"/></strong> on the transfer:
<br/><br/>
</p>
<ul class="oe_edi_nested_block_pay oe_edi_pay_wire_nested">
<t t-foreach="doc.company_address.bank_ids" t-as="bank_info">
<li><t t-esc="bank_info[1]"/></li>
</t>
</ul>
</t>
</t>
</t>
</t>
</template>