[IMP] payment: UI changes & Fix 500 errors

- Fixed 500 errors when trying to display payment form because of variables partner_id/acquirer_id missing.
- Accepted credit cards are now display next to the acquirer name on the payment form
This commit is contained in:
tbe-odoo
2017-08-25 15:29:20 +02:00
parent ddfa0a7042
commit aba509d651
7 changed files with 63 additions and 8 deletions
+2 -1
View File
@@ -17,7 +17,8 @@ class WebsitePayment(http.Controller):
'pms': payment_tokens,
'acquirers': acquirers,
'return_url': return_url,
'bootstrap_formatting': True
'bootstrap_formatting': True,
'partner_id': partner.id
}
return request.render("payment.pay_methods", values)
+10 -1
View File
@@ -5,7 +5,7 @@ import logging
import datetime
from odoo import api, exceptions, fields, models, _
from odoo.tools import consteq, float_round, image_resize_images, ustr, pycompat
from odoo.tools import consteq, float_round, image_resize_images, image_resize_image, ustr, pycompat
from odoo.addons.base.module import module
from odoo.exceptions import ValidationError
@@ -420,14 +420,23 @@ class PaymentOption(models.Model):
"resized as a 64x64px image, with aspect ratio preserved. "
"Use this field anywhere a small image is required.")
image_payment_form = fields.Binary(
"Image displayed on the payment form", attachment=True)
@api.model
def create(self, vals):
image_resize_images(vals)
if 'image' in vals:
self.image_payment_form = image_resize_image(vals['image'], size=(45,30))
return super(PaymentOption, self).create(vals)
@api.multi
def write(self, vals):
image_resize_images(vals)
if 'image' in vals:
self.image_payment_form = image_resize_image(vals['image'], size=(45,30))
return super(PaymentOption, self).write(vals)
class PaymentTransaction(models.Model):
@@ -316,12 +316,17 @@ odoo.define('payment.payment_form', function (require){
},
start: function() {
this.updateNewPaymentDisplayStatus();
$('[data-toggle="tooltip"]').tooltip();
},
});
$(document).ready(function (){
if (!$('.o_payment_form').length) {
return $.Deferred().reject("DOM doesn't contain '.o_payment_form'");
}
var form = new PaymentForm();
form.attachTo($('.o_payment_form'));
});
@@ -33,4 +33,18 @@
border-top: 1px solid #ddd;
padding: 1.14em !important;
}
.payment_option_list {
li {
padding-left: 5px !important;
padding-right: 0px !important;
}
.more_option {
font-size:10px;
}
margin-top: 0px !important;
margin-bottom: -5px !important;
}
}
+29 -5
View File
@@ -50,18 +50,27 @@
</t>
<span class="payment_option_name" t-esc="acq.name"/>
</label>
<!-- <ul class="pull-right list-inline">
<ul class="pull-right list-inline payment_option_list">
<t t-set="i" t-value="0"/>
<t t-foreach="acq.payment_option_ids" t-as="pm_option">
<li>
<span t-field="pm_option.image_small"
<li t-if="i &lt; 3">
<span t-field="pm_option.image_payment_form"
t-options='{"widget": "image", "alt-field": "name"}' />
</li>
<li t-if="i==3" style="display:block;">
<span class="pull-right more_option text-info">
<a href="#" data-toggle="tooltip" t-att-title="', '.join([opt.name for opt in acq.payment_option_ids[3:]])">and more</a>
</span>
</li>
<t t-set="i" t-value="i+1"/>
</t>
</ul> -->
</ul>
</div>
<div t-attf-id="o_payment_add_token_acq_{{acq.id}}" t-attf-class="panel-footer {{'hidden' if (len(s2s_acquirers)&gt;1 and len(pms)==0 and s2s_acquirers[0]!=acq) else 'hidden' if len(pms)&gt;0 else ''}}">
<div class="clearfix">
<t t-call="{{acq.sudo().get_s2s_form_name()}}"/>
<t t-call="{{acq.sudo().get_s2s_form_name()}}">
<t t-set="id" t-value="acq.id"/>
</t>
</div>
</div>
</t>
@@ -76,6 +85,21 @@
name="pm_id" t-attf-value="form_{{acq.id}}"/>
<span class="payment_option_name" t-esc="acq.name"/>
</label>
<ul class="pull-right list-inline payment_option_list">
<t t-set="i" t-value="0"/>
<t t-foreach="acq.payment_option_ids" t-as="pm_option">
<li t-if="i &lt; 3">
<span t-field="pm_option.image_payment_form"
t-options='{"widget": "image", "alt-field": "name"}' />
</li>
<li t-if="i==3" style="display:block;">
<span class="pull-right more_option text-info">
<a href="#" data-toggle="tooltip" t-att-title="', '.join([opt.name for opt in acq.payment_option_ids[3:]])">and more</a>
</span>
</li>
<t t-set="i" t-value="i+1"/>
</t>
</ul>
</div>
<div t-attf-id="o_payment_form_acq_{{acq.id}}" class="panel-footer hidden">
<p>You'll be redirected to the <t t-esc="acq.provider"/> website after clicking on the payment button.</p>
+2 -1
View File
@@ -61,7 +61,8 @@ class sale_quote(http.Controller):
'need_payment': order_sudo.invoice_status == 'to invoice' and Transaction.state in ['draft', 'cancel', 'error'],
'token': token,
'return_url': '/shop/payment/validate',
'bootstrap_formatting': True
'bootstrap_formatting': True,
'partner_id': order_sudo.partner_id.id,
}
if order_sudo.require_payment or values['need_payment']:
+1
View File
@@ -1334,6 +1334,7 @@
<t t-set="pms" t-value="tokens"/>
<t t-set="form_action" t-value="'/shop/payment/token'"/>
<t t-set="prepare_tx_url" t-value="'/shop/payment/transaction/'"/>
<t t-set="partner_id" t-value="partner"/>
</t>
</div>