[WIP] website_sale use payment_acquirer

bzr revid: chm@openerp.com-20131016150837-1zo80gd1pmlvy2im
This commit is contained in:
Christophe Matthieu
2013-10-16 17:08:37 +02:00
parent 1ac51f42b9
commit 6e4c0f9068
8 changed files with 72 additions and 46 deletions
+1
View File
@@ -26,6 +26,7 @@
'version': '0.1',
'description': """Payment acquirer module, use to display payment method and validate the payments.""",
'author': 'OpenERP SA',
'depends': ['website', 'decimal_precision'],
'data': [
'views/acquirer_view.xml',
'payment_acquirer_data.xml',
+15 -7
View File
@@ -24,21 +24,21 @@ from openerp.osv import osv, fields
from openerp.tools import float_repr
class type(osv.Model):
class type(osv.osv):
_name = 'payment.acquirer.type'
_columns = {
'name': fields.char('Name', required=True),
}
class acquirer(osv.Model):
class acquirer(osv.osv):
_name = 'payment.acquirer'
_description = 'Online Payment Acquirer'
_columns = {
'name': fields.char('Name', required=True),
'type_id': fields.many2one('payment.acquirer.type', required=True),
'form_template_id': fields.many2one('ir.ui.view', translate=True, required=True),
'form_template_id': fields.many2one('ir.ui.view', required=True),
'visible': fields.boolean('Visible', help="Make this payment acquirer available (Customer invoices, etc.)"),
}
@@ -51,6 +51,9 @@ class acquirer(osv.Model):
user = self.pool.get("res.users")
precision = self.pool.get("decimal.precision").precision_get(cr, uid, 'Account')
if not context:
context = {}
qweb_context = {}
qweb_context.update(
object=object,
@@ -62,10 +65,15 @@ class acquirer(osv.Model):
context=context
)
res = []
for pay in self.browse(cr, uid, ids, context=context):
res[pay.id] = pay.form_template_id.render(qweb_context.copy(), context=context)
return res
pays = self.browse(cr, uid, ids, context=context)
if isinstance(ids, list):
res = []
for pay in pays:
res[pay.id] = pay.form_template_id.render(qweb_context.copy(), engine='ir.qweb', context=context)
return res
else:
return pays.form_template_id.render(qweb_context, engine='ir.qweb', context=context)
def validate_payement(self, cr, uid, ids, object, reference, currency, amount, context=None):
res = []
@@ -1,37 +1,48 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data noupdate="1">
<data noupdate="0">
<record id="paypal" model="payment.acquirer.type">
<field name="name">paypal</field>
</record>
<!-- Paypal -->
<template id="paypal_acquirer_view">
<form t-if="object.company_id.paypal_account" action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_blank">
<input type="hidden" name="cmd" value="_xclick"/>
<input type="hidden" name="business" t-att-value="object.company_id.paypal_account"/>
<input type="hidden" name="item_name" t-attf-value="#{object.company_id.name} #{reference}"/>
<input type="hidden" name="amount" t-att-value="amount"/>
<input type="hidden" name="currency_code" t-att-value="currency.name"/>
<input type="image" name="submit" src="https://www.paypal.com/en_US/i/btn/btn_paynowCC_LG.gif"/>
</form>
</template>
<record id="paypal_acquirer" model="payment.acquirer">
<field name="name">Paypal</field>
<field name="form_template_id" ref="paypal_acquirer_view"/>
<field name="type_id" ref="paypal"/>
</record>
<!-- Virement -->
<record id="virement" model="payment.acquirer.type">
<field name="name">virement</field>
</record>
<record id="paypal_acquirer" model="payment.acquirer">
<field name="name">Paypal</field>
<field name="form_template"><![CDATA[
<form t-if="object.company_id.paypal_account" action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_blank">
<input type="hidden" name="cmd" value="_xclick"/>
<input type="hidden" name="business" t-att-value="object.company_id.paypal_account}"/>
<input type="hidden" name="item_name" t-attf-value="#{object.company_id.name} #{kind.title()} #{reference}"/>
<input type="hidden" name="amount" t-att-value="amount"/>
<input type="hidden" name="currency_code" t-att-value="currency.name"/>
<input type="image" name="submit" src="https://www.paypal.com/en_US/i/btn/btn_paynowCC_LG.gif"/>
</form>
]]></field>
<field name="type_id" ref="payment_acquirer.paypal"/>
</record>
<template id="virement_acquirer_view">
<div>
<table>
<tr><td>Numero de compte: </td><td></td></tr>
<tr><td>Communication: </td><td><t t-esc="reference"/></td></tr>
</table>
</div>
</template>
<record id="paypal_acquirer" model="payment.acquirer">
<record id="virement_acquirer" model="payment.acquirer">
<field name="name">Virement</field>
<field name="form_template"><![CDATA[
<div>
Numero de compte:
Communication: <t t-esc="reference"/>
</div>
]]></field>
<field name="type_id" ref="payment_acquirer.virement"/>
<field name="form_template_id" ref="virement_acquirer_view"/>
<field name="type_id" ref="virement"/>
</record>
</data>
</openerp>
@@ -44,7 +44,7 @@
</field>
</record>
<record id="acquirer_search" model="ir.ui.view">
<field name="model">portal.payment.acquirer</field>
<field name="model">payment.acquirer</field>
<field name="arch" type="xml">
<search>
<field name="name"/>
+1 -1
View File
@@ -9,7 +9,7 @@ OpenERP E-Commerce
""",
'author': 'OpenERP SA',
'depends': ['website', 'sale', 'product'],
'depends': ['website', 'sale', 'product', 'payment_acquirer'],
'data': [
'website_sale_data.xml',
'views/website_sale.xml',
+2 -2
View File
@@ -624,12 +624,12 @@ class Ecommerce(http.Controller):
'order': order
}
payment_obj = request.registry.get('portal.payment.acquirer')
payment_obj = request.registry.get('payment.acquirer')
payment_ids = payment_obj.search(request.cr, SUPERUSER_ID, [('visible', '=', True)], context=request.context)
values['payments'] = payment_obj.browse(request.cr, SUPERUSER_ID, payment_ids, request.context)
for payment in values['payments']:
content = payment_obj.render(request.cr, SUPERUSER_ID, payment.id, order, order.name, order.pricelist_id.currency_id, order.amount_total)
payment._content = content
payment._content = content.strip()
return request.website.render("website_sale.payment", values)
@@ -58,11 +58,11 @@ $(document).ready(function () {
$('form.js_add_cart_json label').on('mouseup', function (ev) {
ev.preventDefault();
var $label = $(ev.currentTarget);
var $price = $label.parent("form").find(".oe_price");
var $price = $label.parent("form").find(".oe_price .oe_currency_value");
if (!$price.data("price")) {
$price.data("price", parseFloat($price.html()));
$price.data("price", parseFloat($price.text()));
}
$price.html($price.data("price")+parseFloat($label.find(".badge span").html() || 0));
$price.html($price.data("price")+parseFloat($label.find(".badge span").text() || 0));
});
$(document).on('click', '.js_publish_management .js_go_to_top,.js_publish_management .js_go_to_bottom', function (event) {
+15 -9
View File
@@ -286,14 +286,20 @@
<div class="product_price mt16">
<h4>
<b><span class="oe_price" t-esc="product.product_variant_ids[0].price" /> €</b>
<t t-if="product.product_variant_ids[0].lst_price != product.product_variant_ids[0].price">
<span class="text-danger" style="text-decoration: line-through;">
<t t-esc="product.product_variant_ids[0].lst_price" /> €
</span>&amp;nbsp;
<span class="text-danger" style="text-decoration: line-through;"
t-field="product.product_variant_ids[0].lst_price"
t-field-options='{
"widget": "monetary",
"display_currency": "website.pricelist_id.currency_id"
}'/><br/>
</t>
<h4><b><span class="oe_price" t-esc="product.product_variant_ids[0].price" /> €</b></h4>
<b class="oe_price"
t-field="product.product_variant_ids[0].price"
t-field-options='{
"widget": "monetary",
"display_currency": "website.pricelist_id.currency_id"
}'/>
</h4>
</div>
<button class="btn btn-primary btn-lg mt8">Add to Cart</button>
@@ -866,13 +872,13 @@
<div class="js_payment mb64">
<p>Select your payment method:</p>
<div>
<t t-foreach="payments or []" t-as="payment">
<label>
<t t-foreach="payments" t-as="payment">
<label t-if="payment._content">
<input t-att-value="payment.id" type="radio" name="payment_type"/> <t t-esc="payment.name"/>
</label>
</t>
</div>
<t t-foreach="payments or []" t-as="payment">
<t t-foreach="payments" t-as="payment">
<div t-att-data-id="payment.id" t-raw="payment._content" class="hidden"/>
</t>
<a t-href="/shop/payment_validate/" class="btn btn-primary mt16">Validate &amp; Pay <span class="icon-long-arrow-right"/></a>