[REF] portal, portal_sale, payment: refactored old acquirer in portal
now based on the new implementation of payment. [REM] portal: removed acquirer model, views and implementation [REF] portal_sale: now using payment rendering methods [IMP] payment: added render_payment_block, taken from old acquirer, that renders all portal_published acquirers. bzr revid: tde@openerp.com-20140122190022-lef4b3o1tpcua3vx
This commit is contained in:
parent
7445a207f0
commit
2e7b5991b7
|
@ -3,7 +3,8 @@
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from openerp.osv import osv, fields
|
from openerp.osv import osv, fields
|
||||||
from openerp.tools import float_round
|
from openerp.tools import float_round, float_repr
|
||||||
|
from openerp.tools.translate import _
|
||||||
|
|
||||||
_logger = logging.getLogger(__name__)
|
_logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
@ -185,7 +186,7 @@ class PaymentAcquirer(osv.Model):
|
||||||
|
|
||||||
- acquirer: the payment.acquirer browse record
|
- acquirer: the payment.acquirer browse record
|
||||||
- user: the current user browse record
|
- user: the current user browse record
|
||||||
- currency: currency browse record
|
- currency_id: id of the transaction currency
|
||||||
- amount: amount of the transaction
|
- amount: amount of the transaction
|
||||||
- reference: reference of the transaction
|
- reference: reference of the transaction
|
||||||
- partner: the current partner browse record, if any (not necessarily set)
|
- partner: the current partner browse record, if any (not necessarily set)
|
||||||
|
@ -253,6 +254,37 @@ class PaymentAcquirer(osv.Model):
|
||||||
# because render accepts view ids but not qweb -> need to use the xml_id
|
# because render accepts view ids but not qweb -> need to use the xml_id
|
||||||
return self.pool['ir.ui.view'].render(cr, uid, acquirer.view_template_id.xml_id, qweb_context, engine='ir.qweb', context=context)
|
return self.pool['ir.ui.view'].render(cr, uid, acquirer.view_template_id.xml_id, qweb_context, engine='ir.qweb', context=context)
|
||||||
|
|
||||||
|
def _wrap_payment_block(self, cr, uid, html_block, amount, currency_id, context=None):
|
||||||
|
payment_header = _('Pay safely online')
|
||||||
|
amount_str = float_repr(amount, self.pool.get('decimal.precision').precision_get(cr, uid, 'Account'))
|
||||||
|
currency = self.pool['res.currency'].browse(cr, uid, currency_id, context=context)
|
||||||
|
currency_str = currency.symbol or currency.name
|
||||||
|
amount = u"%s %s" % ((currency_str, amount_str) if currency.position == 'before' else (amount_str, currency_str))
|
||||||
|
result = """<div class="payment_acquirers">
|
||||||
|
<div class="payment_header">
|
||||||
|
<div class="payment_amount">%s</div>
|
||||||
|
%s
|
||||||
|
</div>
|
||||||
|
%%s
|
||||||
|
</div>""" % (amount, payment_header)
|
||||||
|
return result % html_block
|
||||||
|
|
||||||
|
def render_payment_block(self, cr, uid, reference, amount, currency_id, tx_id=None, partner_id=False, partner_values=None, tx_values=None, context=None):
|
||||||
|
html_forms = []
|
||||||
|
# TDE FIXME: change this domain, see with CHM about 'dynamic/static' acquirer
|
||||||
|
acquirer_ids = self.search(cr, uid, [('portal_published', '=', True), ('name', '!=', 'transfer')], context=context)
|
||||||
|
for acquirer_id in acquirer_ids:
|
||||||
|
button = self.render(
|
||||||
|
cr, uid, acquirer_id,
|
||||||
|
reference, amount, currency_id,
|
||||||
|
tx_id, partner_id, partner_values, tx_values,
|
||||||
|
context)
|
||||||
|
html_forms.append(button)
|
||||||
|
if not html_forms:
|
||||||
|
return ''
|
||||||
|
html_block = '\n'.join(filter(None, html_forms))
|
||||||
|
return self._wrap_payment_block(cr, uid, html_block, amount, currency_id, context=context)
|
||||||
|
|
||||||
|
|
||||||
class PaymentTransaction(osv.Model):
|
class PaymentTransaction(osv.Model):
|
||||||
""" Transaction Model. Each specific acquirer can extend the model by adding
|
""" Transaction Model. Each specific acquirer can extend the model by adding
|
||||||
|
|
|
@ -24,6 +24,5 @@ import mail_thread
|
||||||
import mail_mail
|
import mail_mail
|
||||||
import mail_message
|
import mail_message
|
||||||
import wizard
|
import wizard
|
||||||
import acquirer
|
|
||||||
|
|
||||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||||
|
|
|
@ -47,7 +47,6 @@ very handy when used in combination with the module 'share'.
|
||||||
'portal_view.xml',
|
'portal_view.xml',
|
||||||
'wizard/portal_wizard_view.xml',
|
'wizard/portal_wizard_view.xml',
|
||||||
'wizard/share_wizard_view.xml',
|
'wizard/share_wizard_view.xml',
|
||||||
'acquirer_view.xml',
|
|
||||||
'security/ir.model.access.csv',
|
'security/ir.model.access.csv',
|
||||||
],
|
],
|
||||||
'demo': ['portal_demo.xml'],
|
'demo': ['portal_demo.xml'],
|
||||||
|
|
|
@ -1,108 +0,0 @@
|
||||||
# -*- coding: utf-8 -*-
|
|
||||||
##############################################################################
|
|
||||||
#
|
|
||||||
# OpenERP, Open Source Business Applications
|
|
||||||
# Copyright (c) 2012-TODAY OpenERP S.A. <http://openerp.com>
|
|
||||||
#
|
|
||||||
# This program is free software: you can redistribute it and/or modify
|
|
||||||
# it under the terms of the GNU Affero General Public License as
|
|
||||||
# published by the Free Software Foundation, either version 3 of the
|
|
||||||
# License, or (at your option) any later version.
|
|
||||||
#
|
|
||||||
# This program is distributed in the hope that it will be useful,
|
|
||||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
# GNU Affero General Public License for more details.
|
|
||||||
#
|
|
||||||
# You should have received a copy of the GNU Affero General Public License
|
|
||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
#
|
|
||||||
##############################################################################
|
|
||||||
|
|
||||||
import logging
|
|
||||||
from urllib import quote as quote
|
|
||||||
|
|
||||||
from openerp.osv import osv, fields
|
|
||||||
from openerp.tools.translate import _
|
|
||||||
from openerp.tools import float_repr
|
|
||||||
|
|
||||||
_logger = logging.getLogger(__name__)
|
|
||||||
try:
|
|
||||||
from mako.template import Template as MakoTemplate
|
|
||||||
except ImportError:
|
|
||||||
_logger.warning("payment_acquirer: mako templates not available, payment acquirer will not work!")
|
|
||||||
|
|
||||||
|
|
||||||
class acquirer(osv.Model):
|
|
||||||
_name = 'portal.payment.acquirer'
|
|
||||||
_description = 'Online Payment Acquirer'
|
|
||||||
|
|
||||||
_columns = {
|
|
||||||
'name': fields.char('Name', required=True),
|
|
||||||
'form_template': fields.text('Payment form template (HTML)', translate=True, required=True),
|
|
||||||
'visible': fields.boolean('Visible', help="Make this payment acquirer available in portal forms (Customer invoices, etc.)"),
|
|
||||||
}
|
|
||||||
|
|
||||||
_defaults = {
|
|
||||||
'visible': True,
|
|
||||||
}
|
|
||||||
|
|
||||||
def render(self, cr, uid, id, object, reference, currency, amount, context=None, **kwargs):
|
|
||||||
""" Renders the form template of the given acquirer as a mako template """
|
|
||||||
if not isinstance(id, (int,long)):
|
|
||||||
id = id[0]
|
|
||||||
this = self.browse(cr, uid, id)
|
|
||||||
if context is None:
|
|
||||||
context = {}
|
|
||||||
try:
|
|
||||||
i18n_kind = _(object._description) # may fail to translate, but at least we try
|
|
||||||
result = MakoTemplate(this.form_template).render_unicode(object=object,
|
|
||||||
reference=reference,
|
|
||||||
currency=currency,
|
|
||||||
amount=amount,
|
|
||||||
kind=i18n_kind,
|
|
||||||
quote=quote,
|
|
||||||
# context kw would clash with mako internals
|
|
||||||
ctx=context,
|
|
||||||
format_exceptions=True)
|
|
||||||
return result.strip()
|
|
||||||
except Exception:
|
|
||||||
_logger.exception("failed to render mako template value for payment.acquirer %s: %r", this.name, this.form_template)
|
|
||||||
return
|
|
||||||
|
|
||||||
def _wrap_payment_block(self, cr, uid, html_block, amount, currency, context=None):
|
|
||||||
if not html_block:
|
|
||||||
link = '#action=account.action_account_config'
|
|
||||||
payment_header = _('You can finish the configuration in the <a href="%s">Bank&Cash settings</a>') % link
|
|
||||||
amount = _('No online payment acquirers configured')
|
|
||||||
group_ids = self.pool.get('res.users').browse(cr, uid, uid, context=context).groups_id
|
|
||||||
if any(group.is_portal for group in group_ids):
|
|
||||||
return ''
|
|
||||||
else:
|
|
||||||
payment_header = _('Pay safely online')
|
|
||||||
amount_str = float_repr(amount, self.pool.get('decimal.precision').precision_get(cr, uid, 'Account'))
|
|
||||||
currency_str = currency.symbol or currency.name
|
|
||||||
amount = u"%s %s" % ((currency_str, amount_str) if currency.position == 'before' else (amount_str, currency_str))
|
|
||||||
result = """<div class="payment_acquirers">
|
|
||||||
<div class="payment_header">
|
|
||||||
<div class="payment_amount">%s</div>
|
|
||||||
%s
|
|
||||||
</div>
|
|
||||||
%%s
|
|
||||||
</div>""" % (amount, payment_header)
|
|
||||||
return result % html_block
|
|
||||||
|
|
||||||
def render_payment_block(self, cr, uid, object, reference, currency, amount, context=None, **kwargs):
|
|
||||||
""" Renders all visible payment acquirer forms for the given rendering context, and
|
|
||||||
return them wrapped in an appropriate HTML block, ready for direct inclusion
|
|
||||||
in an OpenERP v7 form view """
|
|
||||||
acquirer_ids = self.search(cr, uid, [('visible', '=', True)])
|
|
||||||
if not acquirer_ids:
|
|
||||||
return
|
|
||||||
html_forms = []
|
|
||||||
for this in self.browse(cr, uid, acquirer_ids):
|
|
||||||
content = this.render(object, reference, currency, amount, context=context, **kwargs)
|
|
||||||
if content:
|
|
||||||
html_forms.append(content)
|
|
||||||
html_block = '\n'.join(filter(None,html_forms))
|
|
||||||
return self._wrap_payment_block(cr, uid, html_block, amount, currency, context=context)
|
|
|
@ -1,65 +0,0 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<openerp>
|
|
||||||
<data>
|
|
||||||
<record id="acquirer_form" model="ir.ui.view">
|
|
||||||
<field name="model">portal.payment.acquirer</field>
|
|
||||||
<field name="arch" type="xml">
|
|
||||||
<form string="Payment Acquirer" version="7.0">
|
|
||||||
<group col="1">
|
|
||||||
<div class="oe_title">
|
|
||||||
<label for="name" class="oe_edit_only"/><h1><field name="name"/></h1>
|
|
||||||
<div class="oe_edit_only"><field name="visible"/><label for="visible"/></div>
|
|
||||||
</div>
|
|
||||||
<group string="Form Template">
|
|
||||||
<div>
|
|
||||||
<p>
|
|
||||||
This is an HTML form template to submit a payment through this acquirer.
|
|
||||||
The template will be rendered with <a href="http://www.makotemplates.org/" target="_blank">Mako</a>, so it may use Mako expressions.
|
|
||||||
The Mako evaluation context provides:
|
|
||||||
<ul>
|
|
||||||
<li>reference: the reference number of the document to pay</li>
|
|
||||||
<li>kind: the kind of document on which the payment form is rendered (translated to user language, e.g. "Invoice")</li>
|
|
||||||
<li>currency: the currency record in which the document is issued (e.g. currency.name could be EUR)</li>
|
|
||||||
<li>amount: the total amount to pay, as a float</li>
|
|
||||||
<li>object: the document on which the payment form is rendered (usually an invoice or sales order record)</li>
|
|
||||||
<li>quote(): a method to quote special string character to make them suitable for inclusion in a URL</li>
|
|
||||||
<li>cr: the current database cursor</li>
|
|
||||||
<li>uid: the current user id</li>
|
|
||||||
<li>ctx: the current context dictionary</li>
|
|
||||||
</ul>
|
|
||||||
If the template renders to an empty result in a certain context it will be ignored, as if it was inactive.
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
<field name="form_template" nolabel="1" colspan="2"/>
|
|
||||||
</group>
|
|
||||||
</group>
|
|
||||||
</form>
|
|
||||||
</field>
|
|
||||||
</record>
|
|
||||||
<record id="acquirer_list" model="ir.ui.view">
|
|
||||||
<field name="model">portal.payment.acquirer</field>
|
|
||||||
<field name="arch" type="xml">
|
|
||||||
<tree string="Payment Acquirers">
|
|
||||||
<field name="name"/>
|
|
||||||
<field name="visible"/>
|
|
||||||
</tree>
|
|
||||||
</field>
|
|
||||||
</record>
|
|
||||||
<record id="acquirer_search" model="ir.ui.view">
|
|
||||||
<field name="model">portal.payment.acquirer</field>
|
|
||||||
<field name="arch" type="xml">
|
|
||||||
<search>
|
|
||||||
<field name="name"/>
|
|
||||||
</search>
|
|
||||||
</field>
|
|
||||||
</record>
|
|
||||||
|
|
||||||
<!-- Acquirers list action is visible in Invoicing Settings -->
|
|
||||||
<record model="ir.actions.act_window" id="action_acquirer_list">
|
|
||||||
<field name="name">Payment Acquirers</field>
|
|
||||||
<field name="res_model">portal.payment.acquirer</field>
|
|
||||||
</record>
|
|
||||||
|
|
||||||
|
|
||||||
</data>
|
|
||||||
</openerp>
|
|
|
@ -76,22 +76,6 @@
|
||||||
</field>
|
</field>
|
||||||
</record>
|
</record>
|
||||||
|
|
||||||
<record id="paypal_acquirer" model="portal.payment.acquirer">
|
|
||||||
<field name="name">Paypal</field>
|
|
||||||
<field name="form_template"><![CDATA[
|
|
||||||
% if object.company_id.paypal_account:
|
|
||||||
<form action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_blank">
|
|
||||||
<input type="hidden" name="cmd" value="_xclick"/>
|
|
||||||
<input type="hidden" name="business" value="${object.company_id.paypal_account}"/>
|
|
||||||
<input type="hidden" name="item_name" value="${object.company_id.name} ${kind.title()} ${reference}"/>
|
|
||||||
<input type="hidden" name="amount" value="${amount}"/>
|
|
||||||
<input type="hidden" name="currency_code" value="${currency.name}"/>
|
|
||||||
<input type="image" name="submit" src="https://www.paypal.com/en_US/i/btn/btn_paynowCC_LG.gif"/>
|
|
||||||
</form>
|
|
||||||
% endif
|
|
||||||
]]></field>
|
|
||||||
</record>
|
|
||||||
|
|
||||||
</data>
|
</data>
|
||||||
|
|
||||||
<data>
|
<data>
|
||||||
|
|
|
@ -3,6 +3,4 @@ access_mail_message_portal,mail.message.portal,mail.model_mail_message,base.grou
|
||||||
access_mail_mail_portal,mail.mail.portal,mail.model_mail_mail,base.group_portal,1,1,1,0
|
access_mail_mail_portal,mail.mail.portal,mail.model_mail_mail,base.group_portal,1,1,1,0
|
||||||
access_mail_notification_portal,mail.notification.portal,mail.model_mail_notification,base.group_portal,1,1,1,0
|
access_mail_notification_portal,mail.notification.portal,mail.model_mail_notification,base.group_portal,1,1,1,0
|
||||||
access_mail_followers_portal,mail.followers.portal,mail.model_mail_followers,base.group_portal,1,1,0,0
|
access_mail_followers_portal,mail.followers.portal,mail.model_mail_followers,base.group_portal,1,1,0,0
|
||||||
access_acquirer,portal.payment.acquirer,portal.model_portal_payment_acquirer,,1,0,0,0
|
|
||||||
access_acquirer_all,portal.payment.acquirer,portal.model_portal_payment_acquirer,base.group_system,1,1,1,1
|
|
||||||
access_ir_attachment_group_portal,ir.attachment group_portal,base.model_ir_attachment,base.group_portal,1,0,1,0
|
access_ir_attachment_group_portal,ir.attachment group_portal,base.model_ir_attachment,base.group_portal,1,0,1,0
|
|
|
@ -44,7 +44,7 @@ pay online on their Sale Orders and Invoices that are not paid yet. Paypal is in
|
||||||
by default, you simply need to configure a Paypal account in the Accounting/Invoicing settings.
|
by default, you simply need to configure a Paypal account in the Accounting/Invoicing settings.
|
||||||
""",
|
""",
|
||||||
'author': 'OpenERP SA',
|
'author': 'OpenERP SA',
|
||||||
'depends': ['sale','portal'],
|
'depends': ['sale', 'portal', 'payment'],
|
||||||
'data': [
|
'data': [
|
||||||
'security/portal_security.xml',
|
'security/portal_security.xml',
|
||||||
'portal_sale_view.xml',
|
'portal_sale_view.xml',
|
||||||
|
|
|
@ -34,11 +34,12 @@ class sale_order(osv.Model):
|
||||||
|
|
||||||
def _portal_payment_block(self, cr, uid, ids, fieldname, arg, context=None):
|
def _portal_payment_block(self, cr, uid, ids, fieldname, arg, context=None):
|
||||||
result = dict.fromkeys(ids, False)
|
result = dict.fromkeys(ids, False)
|
||||||
payment_acquirer = self.pool.get('portal.payment.acquirer')
|
payment_acquirer = self.pool['payment.acquirer']
|
||||||
for this in self.browse(cr, uid, ids, context=context):
|
for this in self.browse(cr, uid, ids, context=context):
|
||||||
if this.state not in ('draft', 'cancel') and not this.invoiced:
|
if this.state not in ('draft', 'cancel') and not this.invoiced:
|
||||||
result[this.id] = payment_acquirer.render_payment_block(cr, uid, this, this.name,
|
result[this.id] = payment_acquirer.render_payment_block(
|
||||||
this.pricelist_id.currency_id, this.amount_total, context=context)
|
cr, uid, this.name, this.amount_total, this.pricelist_id.currency_id.id,
|
||||||
|
partner_id=this.partner_id.id, context=context)
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def action_quotation_send(self, cr, uid, ids, context=None):
|
def action_quotation_send(self, cr, uid, ids, context=None):
|
||||||
|
@ -87,8 +88,9 @@ class account_invoice(osv.Model):
|
||||||
payment_acquirer = self.pool.get('portal.payment.acquirer')
|
payment_acquirer = self.pool.get('portal.payment.acquirer')
|
||||||
for this in self.browse(cr, uid, ids, context=context):
|
for this in self.browse(cr, uid, ids, context=context):
|
||||||
if this.type == 'out_invoice' and this.state not in ('draft', 'done') and not this.reconciled:
|
if this.type == 'out_invoice' and this.state not in ('draft', 'done') and not this.reconciled:
|
||||||
result[this.id] = payment_acquirer.render_payment_block(cr, uid, this, this.number,
|
result[this.id] = payment_acquirer.render_payment_block(
|
||||||
this.currency_id, this.residual, context=context)
|
cr, uid, this.number, this.residual, this.currency_id.id,
|
||||||
|
partner_id=this.partner_id.id, context=context)
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def action_invoice_sent(self, cr, uid, ids, context=None):
|
def action_invoice_sent(self, cr, uid, ids, context=None):
|
||||||
|
|
|
@ -11,8 +11,6 @@
|
||||||
<div>
|
<div>
|
||||||
<field name="group_payment_options" class="oe_inline"/>
|
<field name="group_payment_options" class="oe_inline"/>
|
||||||
<label for="group_payment_options"/>
|
<label for="group_payment_options"/>
|
||||||
<button name='%(portal.action_acquirer_list)d' type="action"
|
|
||||||
string="Configure payment acquiring methods" class="oe_link"/>
|
|
||||||
</div>
|
</div>
|
||||||
</xpath>
|
</xpath>
|
||||||
</field>
|
</field>
|
||||||
|
|
Loading…
Reference in New Issue