Fix two issues: The search of suitable payment token was searching on the journal_id field of the payment acquirer that is no longer stored. Change it to now search on the acquirer_id directly, since we have this information. The _inverse_journal_id method on payment acquirers would create new payment line with the manual payment method when no provider are given to an acquirer, or no payment method is existing for a given provider. This would cause issues with the creation of multiple line with the same name on a same journal, which would trigger the constrains blocking that. closes odoo/odoo#74990 X-original-commit: a3a2fcb0b299fafbf359ec9015da5c85cdb57b3a Related: odoo/enterprise#20193 Signed-off-by: Laurent Smet <smetl@users.noreply.github.com>
31 lines
1.1 KiB
Python
31 lines
1.1 KiB
Python
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
|
|
|
from odoo import _, api, fields, models
|
|
from odoo.exceptions import UserError
|
|
|
|
|
|
class PaymentAcquirer(models.Model):
|
|
_inherit = 'payment.acquirer'
|
|
|
|
provider = fields.Selection(selection_add=[('test', 'Test')], ondelete={'test': 'set default'})
|
|
|
|
@api.depends('provider')
|
|
def _compute_view_configuration_fields(self):
|
|
""" Override of payment to hide the credentials page.
|
|
|
|
:return: None
|
|
"""
|
|
super()._compute_view_configuration_fields()
|
|
self.filtered(lambda acq: acq.provider == 'test').show_credentials_page = False
|
|
|
|
@api.constrains('state', 'provider')
|
|
def _check_acquirer_state(self):
|
|
if self.filtered(lambda a: a.provider == 'test' and a.state not in ('test', 'disabled')):
|
|
raise UserError(_("Test acquirers should never be enabled."))
|
|
|
|
def _get_default_payment_method_id(self):
|
|
self.ensure_one()
|
|
if self.provider != 'test':
|
|
return super()._get_default_payment_method_id()
|
|
return self.env.ref('payment_test.payment_method_test').id
|