[IMP] Fixing the code to fit the reviews

This commit is contained in:
tbe-odoo
2017-08-29 16:52:04 +02:00
parent 7d812ebe76
commit e81fa1d3fd
16 changed files with 35 additions and 54 deletions
+2 -14
View File
@@ -404,34 +404,22 @@ class PaymentIcon(models.Model):
image = fields.Binary(
"Image", attachment=True,
help="This field holds the image used for this payment icon, limited to 1024x1024px")
image_medium = fields.Binary(
"Medium-sized image", attachment=True,
help="Medium-sized image of this payment icon. It is automatically "
"resized as a 128x128px image, with aspect ratio preserved. "
"Use this field in form views or some kanban views.")
image_small = fields.Binary(
"Small-sized image", attachment=True,
help="Small-sized image of this payment icon. It is automatically "
"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:
vals['image_payment_form'] = image_resize_image(vals['image'], size=(45,30))
vals['image'] = image_resize_image(vals['image'], size=(64,64))
return super(PaymentIcon, self).create(vals)
@api.multi
def write(self, vals):
image_resize_images(vals)
if 'image' in vals:
vals['image_payment_form'] = image_resize_image(vals['image'], size=(45,30))
vals['image'] = image_resize_image(vals['image'], size=(64,64))
return super(PaymentIcon, self).write(vals)
class PaymentTransaction(models.Model):
+18 -23
View File
@@ -18,7 +18,6 @@ odoo.define('payment.payment_form', function (require){
},
payEvent: function(ev) {
// ev.stopPropagation();
ev.preventDefault();
var form = this.el;
var checked_radio = this.$('input[type="radio"]:checked');
@@ -113,26 +112,23 @@ odoo.define('payment.payment_form', function (require){
// if there's a prepare tx url set
if($tx_url.length == 1)
{
// if the user wants to save his credit card info
form_save_token = $('input[name="o_payment_form_save_token"]').checked === true;
// then we call the route to prepare the transaction
ajax.jsonRpc($tx_url[0].value, 'call', {
'acquirer_id': parseInt(acquirer_id),
'save_token': form_save_token
}).then(function(result){
if(result) {
// TBE: I really don't like how it is designed, but I can't do better with how e-commerce works/
var ignored_inputs = ['data_set', 'o_payment_form_save_token'];
var html_form = '<form method="post" action="'
+ ds.dataset.actionUrl + '" class="hidden">'
+ result + '</form>';
// we append the form to the body
var form = $(html_form).appendTo("body");
// we remove the "unused" inputs
for(var i = 0; i < ignored_inputs.length; i++) {
form.find('input[name="' + ignored_inputs[i] + '"]').remove();
}
// we submit the form
form.submit();
// if the server sent us the html form, we create a form element
var newForm = document.createElement('form');
newForm.setAttribute("method", "post"); // set it to post
newForm.setAttribute("action", ds.dataset.actionUrl); // set the action url
newForm.hidden = true; // hide it
newForm.innerHTML = result; // put the html sent by the server inside the form
document.getElementsByTagName('body')[0].appendChild(newForm); // append the form to the body
$(newForm).find('input[data-remove-me]').remove(); // remove all the input that should be removed
newForm.submit(); // and finally submit the form
}
else {
self.error(_t('Server Error'),
@@ -146,7 +142,6 @@ odoo.define('payment.payment_form', function (require){
else
{
// we append the form to the body and send it.
// $(html_form).appendTo("body").submit();
this.error(_t("Cannot set-up the payment"), _t("<p>We're unable to process your payment.</p>"));
}
}
@@ -366,11 +361,11 @@ odoo.define('payment.payment_form', function (require){
$(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'));
});
require('web.dom_ready'); // only start this when dom is ready
if (!$('.o_payment_form').length) {
return $.Deferred().reject("DOM doesn't contain '.o_payment_form'");
}
var form = new PaymentForm();
form.attachTo($('.o_payment_form'));
});
+2 -2
View File
@@ -74,7 +74,7 @@
</div>
</div>
</t>
<t tif="mode == 'payment'" t-foreach="form_acquirers" t-as="acq">
<t t-if="mode == 'payment'" t-foreach="form_acquirers" t-as="acq">
<div class="panel-body">
<label>
<input type="radio" t-att-data-acquirer-id="acq.id"
@@ -102,7 +102,7 @@
</ul>
</div>
<div t-attf-id="o_payment_form_acq_{{acq.id}}" t-attf-class="hidden {{'panel-footer' if acq.save_token == 'ask' else ''}}">
<label t-if="acq.save_token == 'ask'"><input type="checkbox" name="o_payment_form_save_token"/> Save my payment data</label>
<label t-if="acq.save_token == 'ask'"><input type="checkbox" name="o_payment_form_save_token" data-remove-me=""/> Save my payment data</label>
<t t-raw="acq.form"/>
</div>
</t>
+2 -1
View File
@@ -416,6 +416,7 @@
<menuitem
action="action_payment_icon"
id="payment_icon_menu"
parent="root_payment_menu"/>
parent="root_payment_menu"
groups="base.group_no_one"/>
</data>
</odoo>
@@ -2,7 +2,7 @@
<odoo>
<data noupdate="1">
<template id="adyen_form">
<input type="hidden" name="data_set" t-att-data-action-url="tx_url"/>
<input type="hidden" name="data_set" t-att-data-action-url="tx_url" data-remove-me=""/>
<input type="hidden" name="merchantReference" t-att-value="merchantReference"/>
<input type="hidden" name="paymentAmount" t-att-value="paymentAmount"/>
<input type="hidden" name="currencyCode" t-att-value="currencyCode"/>
@@ -3,7 +3,7 @@
<data noupdate="1">
<template id="authorize_form">
<div>
<input type="hidden" name="data_set" t-att-data-action-url="tx_url"/>
<input type="hidden" name="data_set" t-att-data-action-url="tx_url" data-remove-me=""/>
<input type='hidden' name='x_login' t-att-value='x_login'/>
<input type='hidden' name='x_fp_hash' t-att-value='x_fp_hash'/>
<input type='hidden' name='x_amount' t-att-value='x_amount'/>
@@ -2,7 +2,7 @@
<odoo>
<data noupdate="1">
<template id="buckaroo_form">
<input type="hidden" name="data_set" t-att-data-action-url="tx_url"/>
<input type="hidden" name="data_set" t-att-data-action-url="tx_url" data-remove-me=""/>
<input type="hidden" name="Brq_websitekey" t-att-value="Brq_websitekey"/>
<input type="hidden" name="Brq_amount" t-att-value="Brq_amount"/>
<input type="hidden" name="Brq_currency" t-att-value="Brq_currency"/>
@@ -2,7 +2,7 @@
<odoo>
<data>
<template id="ogone_form">
<input type="hidden" name="data_set" t-att-data-action-url="tx_url"/>
<input type="hidden" name="data_set" t-att-data-action-url="tx_url" data-remove-me=""/>
<!-- seller -->
<input type='hidden' name='PSPID' t-att-value='PSPID'/>
<input type='hidden' name='ORDERID' t-att-value='ORDERID'/>
@@ -3,7 +3,7 @@
<data noupdate="1">
<template id="paypal_form">
<div>
<input type="hidden" name="data_set" t-att-data-action-url="tx_url"/>
<input type="hidden" name="data_set" t-att-data-action-url="tx_url" data-remove-me=""/>
<input type="hidden" name="cmd" t-att-value="cmd"/>
<input type="hidden" name="business" t-att-value="business"/>
<input type="hidden" name="item_name" t-att-value="item_name"/>
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<template id="payumoney_form">
<input type="hidden" name="data_set" t-att-data-action-url="tx_url"/>
<input type="hidden" name="data_set" t-att-data-action-url="tx_url" data-remove-me=""/>
<input type="hidden" name="key" t-att-value='key' />
<input type="hidden" name="txnid" t-att-value='txnid' />
<input type="hidden" name="amount" t-att-value='amount' />
@@ -2,7 +2,7 @@
<odoo>
<data noupdate="0">
<template id="sips_form">
<input type="hidden" name="data_set" t-att-data-action-url="tx_url"/>
<input type="hidden" name="data_set" t-att-data-action-url="tx_url" data-remove-me=""/>
<input type="hidden" name="Data" t-att-value="Data"/>
<input type="hidden" name="InterfaceVersion" t-att-value="InterfaceVersion"/>
<input type="hidden" name="Seal" t-att-value="Seal"/>
@@ -103,7 +103,6 @@ odoo.define('payment_stripe.stripe', function(require) {
}
}
// TBE TODO: Pass 'so_id: so_id' and 'access_token: access_token' on the URL
ajax.jsonRpc(url, 'call', {
acquirer_id: acquirer_id
}, {'async': false}).then(function (data) {
@@ -2,7 +2,7 @@
<odoo>
<data>
<template id="stripe_form">
<input type="hidden" name="data_set" t-att-data-action-url="tx_url"/>
<input type="hidden" name="data_set" t-att-data-action-url="tx_url" data-remove-me=""/>
<script src="https://checkout.stripe.com/checkout.js"></script>
<input type='hidden' name='stripe_image' t-att-value="acquirer.stripe_image_url"/>
<input type='hidden' name='merchant' t-att-value='acquirer.company_id.name'/>
@@ -22,7 +22,6 @@
<input type='hidden' name='email' t-att-value='email'/>
<input id="acquirer_stripe" type='hidden' name="acquirer" t-att-value="acquirer.id"/>
<input type='hidden' name="stripe_key" t-att-value="acquirer.stripe_publishable_key"/>
<!-- TBE TODO: Seems like the JS does something with the submit button, I need to check this out -->
<script type="text/javascript" src="/payment_stripe/static/src/js/stripe.js"></script>
</template>
@@ -2,7 +2,7 @@
<odoo>
<data noupdate="1">
<template id="transfer_form">
<input type="hidden" name="data_set" t-att-data-action-url="tx_url"/>
<input type="hidden" name="data_set" t-att-data-action-url="tx_url" data-remove-me=""/>
<t t-if="return_url">
<input type='hidden' name='return_url' t-att-value='return_url'/>
</t>
+1 -2
View File
@@ -11,5 +11,4 @@ class Website(models.Model):
def payment_icons(self):
""" This function returns the list of payment icons which are supported by payment acquirers that are published
"""
icons = self.env['payment.icon'].sudo().search([('acquirer_ids', '!=', False)])
return [icon for icon in icons if any(acq.website_published for acq in icon.acquirer_ids)]
return self.env['payment.icon'].sudo().search([('acquirer_ids.website_published', '=', True)])
@@ -6,7 +6,7 @@
<ul class="payment_method_list list-inline">
<t t-foreach="request.website.payment_icons()" t-as="icon">
<li>
<span t-field="icon.image_small" t-options='{"widget": "image", "alt-field": "name"}' />
<span t-field="icon.image" t-options='{"widget": "image", "alt-field": "name"}' />
</li>
</t>
</ul>