Files
odoo_source/addons/payment/models/account_payment_method.py
T
Nicolas (vin) 66e0e4086b [FIX] account_*: payment method journal filter
Fix two issues linked to payment methods and their journal link.

SEPA Credit Transfer was marked as only available on EUR journals, but
from what we have been told, and we have seen, it should also be made
available for other currencies (CHF/SEK).
So we are changing the rule used to determine if SEPA Credit Transfer
is available on a journal to allow to use it on journals using CHF or
SEK as a currency.

There is another issue, where the filtering is done differently at the
journal creation and when the user add the payment method manually in
the lists.
The filter rules were not respected at the journal creation, which
would lead to incorrect default inbound and outbound payment method list.
For example, a new journal would have the company currency (let's say,
USD) but still have SEPA Credit Transfer (EUR,CHF,SEK) added on it by
default while it should not be available there.

opw-2777522

X-original-commit: 0ad8faf3bfc7b28e5668c3445fcc06c24ad98354
[FIX] account_*: payment method journal filter

Fix two issues linked to payment methods and their journal link.

SEPA Credit Transfer was marked as only available on EUR journals, but
from what we have been told, and we have seen, it should also be made
available for other currencies (CHF/SEK).
So we are changing the rule used to determine if SEPA Credit Transfer
is available on a journal to allow to use it on journals using CHF or
SEK as a currency.

There is another issue, where the filtering is done differently at the
journal creation and when the user add the payment method manually in
the lists.
The filter rules were not respected at the journal creation, which
would lead to incorrect default inbound and outbound payment method list.
For example, a new journal would have the company currency (let's say,
USD) but still have SEPA Credit Transfer (EUR,CHF,SEK) added on it by
default while it should not be available there.

opw-2777522

closes odoo/odoo#88677

X-original-commit: e2cd91ad8339f73b2547bc839e675443528f3adf
Related: odoo/enterprise#26172
Signed-off-by: Florian Gilbert <flg@odoo.com>
2022-04-14 15:11:27 +02:00

65 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)
@api.model
def _get_payment_method_domain(self, code):
# OVERRIDE
domain = super()._get_payment_method_domain(code)
information = self._get_payment_method_information().get(code)
unique = information.get('mode') == 'unique'
if unique:
company_ids = self.env['payment.acquirer'].sudo().search([('provider', '=', 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
}