summaryrefslogtreecommitdiff
path: root/addons/account_payment/controllers/portal.py
diff options
context:
space:
mode:
authorstephanchrst <stephanchrst@gmail.com>2022-05-10 21:51:50 +0700
committerstephanchrst <stephanchrst@gmail.com>2022-05-10 21:51:50 +0700
commit3751379f1e9a4c215fb6eb898b4ccc67659b9ace (patch)
treea44932296ef4a9b71d5f010906253d8c53727726 /addons/account_payment/controllers/portal.py
parent0a15094050bfde69a06d6eff798e9a8ddf2b8c21 (diff)
initial commit 2
Diffstat (limited to 'addons/account_payment/controllers/portal.py')
-rw-r--r--addons/account_payment/controllers/portal.py26
1 files changed, 26 insertions, 0 deletions
diff --git a/addons/account_payment/controllers/portal.py b/addons/account_payment/controllers/portal.py
new file mode 100644
index 00000000..0f2476c0
--- /dev/null
+++ b/addons/account_payment/controllers/portal.py
@@ -0,0 +1,26 @@
+# -*- coding: utf-8 -*-
+# Part of Odoo. See LICENSE file for full copyright and licensing details.
+
+from odoo.addons.account.controllers.portal import PortalAccount
+from odoo.http import request
+
+
+class PortalAccount(PortalAccount):
+
+ def _invoice_get_page_view_values(self, invoice, access_token, **kwargs):
+ values = super(PortalAccount, self)._invoice_get_page_view_values(invoice, access_token, **kwargs)
+ payment_inputs = request.env['payment.acquirer']._get_available_payment_input(partner=invoice.partner_id, company=invoice.company_id)
+ # if not connected (using public user), the method _get_available_payment_input will return public user tokens
+ is_public_user = request.env.user._is_public()
+ if is_public_user:
+ # we should not display payment tokens owned by the public user
+ payment_inputs.pop('pms', None)
+ token_count = request.env['payment.token'].sudo().search_count([('acquirer_id.company_id', '=', invoice.company_id.id),
+ ('partner_id', '=', invoice.partner_id.id),
+ ])
+ values['existing_token'] = token_count > 0
+ values.update(payment_inputs)
+ # if the current user is connected we set partner_id to his partner otherwise we set it as the invoice partner
+ # we do this to force the creation of payment tokens to the correct partner and avoid token linked to the public user
+ values['partner_id'] = invoice.partner_id if is_public_user else request.env.user.partner_id,
+ return values