Files
odoo_source/addons/account_payment/controllers/portal.py
T
Antoine Vandevenne (anv) c902e02317 [FIX] payment(_*), account_payment: fix post-refactoring issues
account_payment:
  - Processing fees computation was done based on the wrong country.
payment:
  - The acquirer's cancel message was missing from the
    /payment/confirmation page.
  - `redirect_form_view_id` field was declared with attribute 'name'
    instead of 'string'.
  - Uninstalling a payment acquirer would fail with a traceback.
  - The first acquirer was not automatically selected if it was the only
    selectable payment option of a 'manage' payment form.
  - Specifying a preferred acquirer to the /payment/pay page would show
    not acquirer at all if the preferred option was incompatible with
    the constraints, rather than falling back on showing all acquirers.
payment_adyen:
  - When the value of the API URL fields is malformed (e.g., missing the
    "https://"), clicking on the confirm button raised a traceback.
payment_ogone:
  - There was a typo in the return route.
payment_paypal:
  - PayPal acquirers were not filtered out if the currency was not not
    supported.
  - Returning to the webshop without paying would raise a traceback.

task-2494916

closes odoo/odoo#69996

X-original-commit: 4f7e463fb8b13506caa8aff0beeef5eb0720bf00
Related: odoo/enterprise#17997
Signed-off-by: Antoine Vandevenne (anv) <AntoineVDV@users.noreply.github.com>
2021-04-28 11:39:26 +00:00

52 lines
2.6 KiB
Python

# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo.http import request
from odoo.addons.account.controllers import portal
from odoo.addons.portal.controllers.portal import _build_url_w_params
class PortalAccount(portal.PortalAccount):
def _invoice_get_page_view_values(self, invoice, access_token, **kwargs):
values = super()._invoice_get_page_view_values(invoice, access_token, **kwargs)
logged_in = not request.env.user._is_public()
# We set partner_id to the partner id of the current user if logged in, otherwise we set it
# to the invoice partner id. We do this to ensure that payment tokens are assigned to the
# correct partner and to avoid linking tokens to the public user.
partner_id = request.env.user.partner_id.id if logged_in else invoice.partner_id.id
acquirers_sudo = request.env['payment.acquirer'].sudo()._get_compatible_acquirers(
invoice.company_id.id or request.env.company.id,
partner_id,
currency_id=invoice.currency_id.id,
) # In sudo mode to read the fields of acquirers and partner (if not logged in)
tokens = request.env['payment.token'].search(
[('acquirer_id', 'in', acquirers_sudo.ids), ('partner_id', '=', partner_id)]
) # Tokens are cleared at the end if the user is not logged in
fees_by_acquirer = {
acq_sudo: acq_sudo._compute_fees(
invoice.amount_total, invoice.currency_id, invoice.partner_id.country_id
) for acq_sudo in acquirers_sudo.filtered('fees_active')
}
values.update({
'acquirers': acquirers_sudo,
'tokens': tokens,
'fees_by_acquirer': fees_by_acquirer,
'show_tokenize_input': logged_in, # Prevent public partner from saving payment methods
'amount': invoice.amount_residual,
'currency': invoice.currency_id,
'partner_id': partner_id,
'access_token': access_token,
'transaction_route': f'/invoice/transaction/{invoice.id}/',
'landing_route': _build_url_w_params(invoice.access_url, {'access_token': access_token})
})
if not logged_in:
# Don't display payment tokens of the invoice partner if the user is not logged in, but
# inform that logging in will make them available.
values.update({
'existing_token': bool(tokens),
'tokens': request.env['payment.token'],
})
return values