diff --git a/addons/payment/models/payment_acquirer.py b/addons/payment/models/payment_acquirer.py index 1a7afc3031d..39e8624b359 100644 --- a/addons/payment/models/payment_acquirer.py +++ b/addons/payment/models/payment_acquirer.py @@ -3,7 +3,8 @@ import logging 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__) @@ -185,7 +186,7 @@ class PaymentAcquirer(osv.Model): - acquirer: the payment.acquirer browse record - user: the current user browse record - - currency: currency browse record + - currency_id: id of the transaction currency - amount: amount of the transaction - reference: reference of the transaction - 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 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 = """
+
+
%s
+ %s +
+ %%s +
""" % (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): """ Transaction Model. Each specific acquirer can extend the model by adding diff --git a/addons/portal/__init__.py b/addons/portal/__init__.py index 1f60accc83d..3e3f8dfdd0e 100644 --- a/addons/portal/__init__.py +++ b/addons/portal/__init__.py @@ -24,6 +24,5 @@ import mail_thread import mail_mail import mail_message import wizard -import acquirer # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/addons/portal/__openerp__.py b/addons/portal/__openerp__.py index c747409207a..2ee81218f82 100644 --- a/addons/portal/__openerp__.py +++ b/addons/portal/__openerp__.py @@ -47,7 +47,6 @@ very handy when used in combination with the module 'share'. 'portal_view.xml', 'wizard/portal_wizard_view.xml', 'wizard/share_wizard_view.xml', - 'acquirer_view.xml', 'security/ir.model.access.csv', ], 'demo': ['portal_demo.xml'], diff --git a/addons/portal/acquirer.py b/addons/portal/acquirer.py deleted file mode 100644 index 9c18b597a1b..00000000000 --- a/addons/portal/acquirer.py +++ /dev/null @@ -1,108 +0,0 @@ -# -*- coding: utf-8 -*- -############################################################################## -# -# OpenERP, Open Source Business Applications -# Copyright (c) 2012-TODAY OpenERP S.A. -# -# 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 . -# -############################################################################## - -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 Bank&Cash settings') % 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 = """
-
-
%s
- %s -
- %%s -
""" % (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) diff --git a/addons/portal/acquirer_view.xml b/addons/portal/acquirer_view.xml deleted file mode 100644 index 53e0591009e..00000000000 --- a/addons/portal/acquirer_view.xml +++ /dev/null @@ -1,65 +0,0 @@ - - - - - portal.payment.acquirer - -
- -
-
- -
-

- This is an HTML form template to submit a payment through this acquirer. - The template will be rendered with Mako, so it may use Mako expressions. - The Mako evaluation context provides: -

    -
  • reference: the reference number of the document to pay
  • -
  • kind: the kind of document on which the payment form is rendered (translated to user language, e.g. "Invoice")
  • -
  • currency: the currency record in which the document is issued (e.g. currency.name could be EUR)
  • -
  • amount: the total amount to pay, as a float
  • -
  • object: the document on which the payment form is rendered (usually an invoice or sales order record)
  • -
  • quote(): a method to quote special string character to make them suitable for inclusion in a URL
  • -
  • cr: the current database cursor
  • -
  • uid: the current user id
  • -
  • ctx: the current context dictionary
  • -
- If the template renders to an empty result in a certain context it will be ignored, as if it was inactive. -

-
- -
-
-
-
-
- - portal.payment.acquirer - - - - - - - - - portal.payment.acquirer - - - - - - - - - - Payment Acquirers - portal.payment.acquirer - - - -
-
diff --git a/addons/portal/portal_data.xml b/addons/portal/portal_data.xml index 3fec4d7e1ee..a9388ff1045 100644 --- a/addons/portal/portal_data.xml +++ b/addons/portal/portal_data.xml @@ -76,22 +76,6 @@ - - Paypal - - - - - - - - -% endif - ]]> - - diff --git a/addons/portal/security/ir.model.access.csv b/addons/portal/security/ir.model.access.csv index 7676f0a9d2b..1ec8d4d0be2 100644 --- a/addons/portal/security/ir.model.access.csv +++ b/addons/portal/security/ir.model.access.csv @@ -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_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_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 \ No newline at end of file diff --git a/addons/portal_sale/__openerp__.py b/addons/portal_sale/__openerp__.py index b8ce9165283..ec3f4651119 100644 --- a/addons/portal_sale/__openerp__.py +++ b/addons/portal_sale/__openerp__.py @@ -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. """, 'author': 'OpenERP SA', - 'depends': ['sale','portal'], + 'depends': ['sale', 'portal', 'payment'], 'data': [ 'security/portal_security.xml', 'portal_sale_view.xml', diff --git a/addons/portal_sale/portal_sale.py b/addons/portal_sale/portal_sale.py index 11314704745..23bb36bd353 100644 --- a/addons/portal_sale/portal_sale.py +++ b/addons/portal_sale/portal_sale.py @@ -34,11 +34,12 @@ class sale_order(osv.Model): def _portal_payment_block(self, cr, uid, ids, fieldname, arg, context=None): 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): if this.state not in ('draft', 'cancel') and not this.invoiced: - result[this.id] = payment_acquirer.render_payment_block(cr, uid, this, this.name, - this.pricelist_id.currency_id, this.amount_total, context=context) + result[this.id] = payment_acquirer.render_payment_block( + cr, uid, this.name, this.amount_total, this.pricelist_id.currency_id.id, + partner_id=this.partner_id.id, context=context) return result 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') 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: - result[this.id] = payment_acquirer.render_payment_block(cr, uid, this, this.number, - this.currency_id, this.residual, context=context) + result[this.id] = payment_acquirer.render_payment_block( + cr, uid, this.number, this.residual, this.currency_id.id, + partner_id=this.partner_id.id, context=context) return result def action_invoice_sent(self, cr, uid, ids, context=None): diff --git a/addons/portal_sale/res_config_view.xml b/addons/portal_sale/res_config_view.xml index ce33a1a1a72..50664a43d36 100644 --- a/addons/portal_sale/res_config_view.xml +++ b/addons/portal_sale/res_config_view.xml @@ -11,8 +11,6 @@