Files
odoo_source/addons/payment/models/account_payment_method.py
T
Nicolas (vin) 9e432ed243 [FIX] account, payment: Various fixes for account payments/method lines
There is an issue when computing the suitable payment token ids making it impossible to
open a payment for a user without access to payment acquirers.

Also, the default computation of payment token was wrong and would never set it
correctly.

The compute for the method lines in payment would not filter unavailable acquirers
line and thus select them by default if they were first in line.

Also fix an issue with the ordering of payment method lines

X-original-commit: 73410a0fd76a70e1730883d35b79fc603741b59c
2021-07-19 15:17:32 +00:00

64 lines
2.2 KiB
Python

# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import api, fields, models, _
from odoo.osv import expression
class AccountPaymentMethodLine(models.Model):
_inherit = "account.payment.method.line"
payment_acquirer_id = fields.Many2one(
comodel_name='payment.acquirer',
compute='_compute_payment_acquirer_id',
store=True
)
payment_acquirer_state = fields.Selection(
related='payment_acquirer_id.state'
)
@api.depends('payment_method_id')
def _compute_payment_acquirer_id(self):
acquirers = self.env['payment.acquirer'].sudo().search([
('provider', 'in', self.mapped('code')),
('company_id', 'in', self.journal_id.company_id.ids),
])
# Make sure to pick the active acquirer, if any.
acquirers_map = dict()
for acquirer in acquirers:
current_value = acquirers_map.get((acquirer.provider, acquirer.company_id), False)
if current_value and current_value.state != 'disabled':
continue
acquirers_map[(acquirer.provider, acquirer.company_id)] = acquirer
for line in self:
code = line.payment_method_id.code
company = line.journal_id.company_id
line.payment_acquirer_id = acquirers_map.get((code, company), False)
def _get_payment_method_domain(self):
# OVERRIDE
domain = super()._get_payment_method_domain()
information = self._get_payment_method_information().get(self.code)
unique = information.get('mode') == 'unique'
if unique:
company_ids = self.env['payment.acquirer'].sudo().search([('provider', '=', self.code)]).mapped('company_id')
if company_ids:
domain = expression.AND([domain, [('company_id', 'in', company_ids.ids)]])
return domain
def action_open_acquirer_form(self):
self.ensure_one()
return {
'type': 'ir.actions.act_window',
'name': _('Acquirer'),
'view_mode': 'form',
'res_model': 'payment.acquirer',
'target': 'current',
'res_id': self.payment_acquirer_id.id
}